- Timestamp:
- Jun 23, 2007 7:26:54 AM (17 years ago)
- Location:
- pjproject/trunk/pjsip
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip/include/pjsip/sip_transport.h
r1387 r1388 1059 1059 1060 1060 /** 1061 * This is a low-level function to send raw data using the specified transport 1062 * to the specified destination. 1063 * 1064 * @param tr The SIP transport to be used. 1061 * This is a low-level function to send raw data to a destination. 1062 * 1063 * See also #pjsip_endpt_send_raw() and #pjsip_endpt_send_raw_to_uri(). 1064 * 1065 * @param mgr Transport manager. 1066 * @param tp_type Transport type. 1067 * @param sel Optional pointer to transport selector instance if 1068 * application wants to use a specific transport instance 1069 * rather then letting transport manager finds the suitable 1070 * transport. 1071 * @param tdata Optional transmit data buffer to be used. If this value 1072 * is NULL, this function will create one internally. If 1073 * tdata is specified, this function will decrement the 1074 * reference counter upon completion. 1065 1075 * @param raw_data The data to be sent. 1066 1076 * @param data_len The length of the data. … … 1080 1090 * callback will not be called. 1081 1091 */ 1082 PJ_DECL(pj_status_t) pjsip_transport_send_raw(pjsip_transport *tr, 1083 const void *raw_data, 1084 pj_size_t data_len, 1085 const pj_sockaddr_t *addr, 1086 int addr_len, 1087 void *token, 1088 pjsip_tp_send_callback cb); 1089 1092 PJ_DECL(pj_status_t) pjsip_tpmgr_send_raw(pjsip_tpmgr *mgr, 1093 pjsip_transport_type_e tp_type, 1094 const pjsip_tpselector *sel, 1095 pjsip_tx_data *tdata, 1096 const void *raw_data, 1097 pj_size_t data_len, 1098 const pj_sockaddr_t *addr, 1099 int addr_len, 1100 void *token, 1101 pjsip_tp_send_callback cb); 1090 1102 1091 1103 /** -
pjproject/trunk/pjsip/include/pjsip/sip_util.h
r1269 r1388 21 21 22 22 #include <pjsip/sip_msg.h> 23 #include <pjsip/sip_transport.h> 23 24 #include <pjsip/sip_resolve.h> 24 25 … … 220 221 pjsip_host_info *dest_info ); 221 222 222 223 223 /** 224 224 * This structure holds the state of outgoing stateless request. … … 259 259 } pjsip_send_state; 260 260 261 typedef void (*pjsip_endpt_callback)(pjsip_send_state*, pj_ssize_t sent, 262 pj_bool_t *cont); 261 262 typedef void (*pjsip_send_callback)(pjsip_send_state*, pj_ssize_t sent, 263 pj_bool_t *cont); 264 263 265 /** 264 266 * Send outgoing request statelessly The function will take care of which … … 282 284 pjsip_tx_data *tdata, 283 285 void *token, 284 pjsip_endpt_callback cb); 286 pjsip_send_callback cb); 287 288 /** 289 * This is a low-level function to send raw data to a destination. 290 * 291 * See also #pjsip_endpt_send_raw_to_uri(). 292 * 293 * @param endpt The SIP endpoint instance. 294 * @param tp_type Transport type. 295 * @param sel Optional pointer to transport selector instance if 296 * application wants to use a specific transport instance 297 * rather then letting transport manager finds the suitable 298 * transport.. 299 * @param raw_data The data to be sent. 300 * @param data_len The length of the data. 301 * @param addr Destination address. 302 * @param addr_len Length of destination address. 303 * @param token Arbitrary token to be returned back to callback. 304 * @param cb Optional callback to be called to notify caller about 305 * the completion status of the pending send operation. 306 * 307 * @return If the message has been sent successfully, this function 308 * will return PJ_SUCCESS and the callback will not be 309 * called. If message cannot be sent immediately, this 310 * function will return PJ_EPENDING, and application will 311 * be notified later about the completion via the callback. 312 * Any statuses other than PJ_SUCCESS or PJ_EPENDING 313 * indicates immediate failure, and in this case the 314 * callback will not be called. 315 */ 316 PJ_DECL(pj_status_t) pjsip_endpt_send_raw(pjsip_endpoint *endpt, 317 pjsip_transport_type_e tp_type, 318 const pjsip_tpselector *sel, 319 const void *raw_data, 320 pj_size_t data_len, 321 const pj_sockaddr_t *addr, 322 int addr_len, 323 void *token, 324 pjsip_tp_send_callback cb); 325 326 /** 327 * Send raw data to the specified destination URI. The actual destination 328 * address will be calculated from the URI, using normal SIP URI to host 329 * resolution. 330 * 331 * See also #pjsip_endpt_send_raw(). 332 * 333 * @param endpt The SIP endpoint instance. 334 * @param dst_uri Destination address URI. 335 * @param sel Optional pointer to transport selector instance if 336 * application wants to use a specific transport instance 337 * rather then letting transport manager finds the suitable 338 * transport.. 339 * @param raw_data The data to be sent. 340 * @param data_len The length of the data. 341 * @param token Arbitrary token to be returned back to callback. 342 * @param cb Optional callback to be called to notify caller about 343 * the completion status of the pending send operation. 344 * 345 * @return If the message has been sent successfully, this function 346 * will return PJ_SUCCESS and the callback will not be 347 * called. If message cannot be sent immediately, this 348 * function will return PJ_EPENDING, and application will 349 * be notified later about the completion via the callback. 350 * Any statuses other than PJ_SUCCESS or PJ_EPENDING 351 * indicates immediate failure, and in this case the 352 * callback will not be called. 353 */ 354 PJ_DECL(pj_status_t) pjsip_endpt_send_raw_to_uri(pjsip_endpoint *endpt, 355 const pj_str_t *dst_uri, 356 const pjsip_tpselector *sel, 357 const void *raw_data, 358 pj_size_t data_len, 359 void *token, 360 pjsip_tp_send_callback cb); 285 361 286 362 /** … … 358 434 pjsip_tx_data *tdata, 359 435 void *token, 360 pjsip_ endpt_callback cb);436 pjsip_send_callback cb); 361 437 362 438 /** … … 381 457 pjsip_tx_data *tdata, 382 458 void *token, 383 pjsip_ endpt_callback cb);459 pjsip_send_callback cb); 384 460 385 461 /** -
pjproject/trunk/pjsip/src/pjsip/sip_transport.c
r1387 r1388 604 604 605 605 606 /* send_raw() callback */ 607 static void send_raw_callback(pjsip_transport *transport, 608 void *token, 609 pj_ssize_t size) 610 { 611 pjsip_tx_data *tdata = (pjsip_tx_data*) token; 612 613 /* Mark pending off so that app can resend/reuse txdata from inside 614 * the callback. 615 */ 616 tdata->is_pending = 0; 617 618 /* Call callback, if any. */ 619 if (tdata->cb) { 620 (*tdata->cb)(tdata->token, tdata, size); 621 } 622 623 /* Decrement tdata reference count. */ 624 pjsip_tx_data_dec_ref(tdata); 625 626 /* Decrement transport reference count */ 627 pjsip_transport_dec_ref(transport); 628 } 629 630 606 631 /* Send raw data */ 607 PJ_DEF(pj_status_t) pjsip_transport_send_raw(pjsip_transport *tr, 608 const void *raw_data, 609 pj_size_t data_len, 610 const pj_sockaddr_t *addr, 611 int addr_len, 612 void *token, 613 pjsip_tp_send_callback cb) 614 { 615 pjsip_tx_data *tdata; 632 PJ_DEF(pj_status_t) pjsip_tpmgr_send_raw(pjsip_tpmgr *mgr, 633 pjsip_transport_type_e tp_type, 634 const pjsip_tpselector *sel, 635 pjsip_tx_data *tdata, 636 const void *raw_data, 637 pj_size_t data_len, 638 const pj_sockaddr_t *addr, 639 int addr_len, 640 void *token, 641 pjsip_tp_send_callback cb) 642 { 643 pjsip_transport *tr; 616 644 pj_status_t status; 617 645 618 status = pjsip_endpt_create_tdata(tr->endpt, &tdata); 646 /* Acquire the transport */ 647 status = pjsip_tpmgr_acquire_transport(mgr, tp_type, addr, addr_len, 648 sel, &tr); 619 649 if (status != PJ_SUCCESS) 620 650 return status; 621 651 622 /* Add reference counter. */ 623 pjsip_tx_data_add_ref(tdata); 652 /* Create transmit data buffer if one is not specified */ 653 if (tdata == NULL) { 654 status = pjsip_endpt_create_tdata(tr->endpt, &tdata); 655 if (status != PJ_SUCCESS) { 656 pjsip_transport_dec_ref(tr); 657 return status; 658 } 659 660 /* Add reference counter. */ 661 pjsip_tx_data_add_ref(tdata); 662 } 663 664 /* Allocate buffer */ 665 if (tdata->buf.start == NULL || 666 (tdata->buf.end - tdata->buf.start) < (int)data_len) 667 { 668 /* Note: data_len may be zero, so allocate +1 */ 669 tdata->buf.start = (char*) pj_pool_alloc(tdata->pool, data_len+1); 670 tdata->buf.end = tdata->buf.start + data_len + 1; 671 } 624 672 625 /* Allocate buffer */ 626 tdata->buf.start = (char*) pj_pool_alloc(tdata->pool, data_len); 627 tdata->buf.end = tdata->buf.start + data_len; 628 629 /* Copy data */ 630 pj_memcpy(tdata->buf.start, raw_data, data_len); 673 /* Copy data, if any! (application may send zero len packet) */ 674 if (data_len) { 675 pj_memcpy(tdata->buf.start, raw_data, data_len); 676 } 631 677 tdata->buf.cur = tdata->buf.start + data_len; 632 678 … … 638 684 tdata->is_pending = 1; 639 685 640 /* Send to trans oprt */686 /* Send to transport */ 641 687 status = tr->send_msg(tr, tdata, addr, addr_len, 642 tdata, & transport_send_callback);688 tdata, &send_raw_callback); 643 689 644 690 if (status != PJ_EPENDING) { 645 691 /* callback will not be called, so destroy tdata now. */ 646 692 pjsip_tx_data_dec_ref(tdata); 693 pjsip_transport_dec_ref(tr); 647 694 } 648 695 -
pjproject/trunk/pjsip/src/pjsip/sip_util.c
r1375 r1388 997 997 pjsip_tx_data *tdata, 998 998 void *token, 999 pjsip_ endpt_callback cb)999 pjsip_send_callback cb) 1000 1000 { 1001 1001 pjsip_host_info dest_info; … … 1024 1024 return PJ_SUCCESS; 1025 1025 } 1026 1027 1028 /* 1029 * Send raw data to a destination. 1030 */ 1031 PJ_DEF(pj_status_t) pjsip_endpt_send_raw( pjsip_endpoint *endpt, 1032 pjsip_transport_type_e tp_type, 1033 const pjsip_tpselector *sel, 1034 const void *raw_data, 1035 pj_size_t data_len, 1036 const pj_sockaddr_t *addr, 1037 int addr_len, 1038 void *token, 1039 pjsip_tp_send_callback cb) 1040 { 1041 return pjsip_tpmgr_send_raw(pjsip_endpt_get_tpmgr(endpt), tp_type, sel, 1042 NULL, raw_data, data_len, addr, addr_len, 1043 token, cb); 1044 } 1045 1046 1047 /* Callback data for sending raw data */ 1048 struct send_raw_data 1049 { 1050 pjsip_endpoint *endpt; 1051 pjsip_tx_data *tdata; 1052 pjsip_tpselector *sel; 1053 void *app_token; 1054 pjsip_tp_send_callback app_cb; 1055 }; 1056 1057 1058 /* Resolver callback for sending raw data. */ 1059 static void send_raw_resolver_callback( pj_status_t status, 1060 void *token, 1061 const pjsip_server_addresses *addr) 1062 { 1063 struct send_raw_data *sraw_data = (struct send_raw_data*) token; 1064 1065 if (status != PJ_SUCCESS) { 1066 if (sraw_data->app_cb) { 1067 (*sraw_data->app_cb)(sraw_data->app_token, sraw_data->tdata, 1068 -status); 1069 } 1070 } else { 1071 pj_size_t data_len; 1072 1073 pj_assert(addr->count != 0); 1074 1075 data_len = sraw_data->tdata->buf.cur - sraw_data->tdata->buf.start; 1076 status = pjsip_tpmgr_send_raw(pjsip_endpt_get_tpmgr(sraw_data->endpt), 1077 addr->entry[0].type, 1078 sraw_data->sel, sraw_data->tdata, 1079 sraw_data->tdata->buf.start, data_len, 1080 &addr->entry[0].addr, 1081 addr->entry[0].addr_len, 1082 sraw_data->app_token, 1083 sraw_data->app_cb); 1084 if (status == PJ_SUCCESS) { 1085 (*sraw_data->app_cb)(sraw_data->app_token, sraw_data->tdata, 1086 data_len); 1087 } else if (status != PJ_EPENDING) { 1088 (*sraw_data->app_cb)(sraw_data->app_token, sraw_data->tdata, 1089 -status); 1090 } 1091 } 1092 1093 if (sraw_data->sel) { 1094 pjsip_tpselector_dec_ref(sraw_data->sel); 1095 } 1096 pjsip_tx_data_dec_ref(sraw_data->tdata); 1097 } 1098 1099 1100 /* 1101 * Send raw data to the specified destination URI. 1102 */ 1103 PJ_DEF(pj_status_t) pjsip_endpt_send_raw_to_uri(pjsip_endpoint *endpt, 1104 const pj_str_t *p_dst_uri, 1105 const pjsip_tpselector *sel, 1106 const void *raw_data, 1107 pj_size_t data_len, 1108 void *token, 1109 pjsip_tp_send_callback cb) 1110 { 1111 pjsip_tx_data *tdata; 1112 struct send_raw_data *sraw_data; 1113 pj_str_t dst_uri; 1114 pjsip_uri *uri; 1115 pjsip_host_info dest_info; 1116 pj_status_t status; 1117 1118 /* Allocate buffer */ 1119 status = pjsip_endpt_create_tdata(endpt, &tdata); 1120 if (status != PJ_SUCCESS) 1121 return status; 1122 1123 pjsip_tx_data_add_ref(tdata); 1124 1125 /* Duplicate URI since parser requires URI to be NULL terminated */ 1126 pj_strdup_with_null(tdata->pool, &dst_uri, p_dst_uri); 1127 1128 /* Parse URI */ 1129 uri = pjsip_parse_uri(tdata->pool, dst_uri.ptr, dst_uri.slen, 0); 1130 if (uri == NULL) { 1131 pjsip_tx_data_dec_ref(tdata); 1132 return PJSIP_EINVALIDURI; 1133 } 1134 1135 /* Build destination info. */ 1136 status = get_dest_info(uri, tdata->pool, &dest_info); 1137 if (status != PJ_SUCCESS) { 1138 pjsip_tx_data_dec_ref(tdata); 1139 return status; 1140 } 1141 1142 /* Copy data (note: data_len may be zero!) */ 1143 tdata->buf.start = (char*) pj_pool_alloc(tdata->pool, data_len+1); 1144 tdata->buf.end = tdata->buf.start + data_len + 1; 1145 if (data_len) 1146 pj_memcpy(tdata->buf.start, raw_data, data_len); 1147 tdata->buf.cur = tdata->buf.start + data_len; 1148 1149 /* Init send_raw_data */ 1150 sraw_data = PJ_POOL_ZALLOC_T(tdata->pool, struct send_raw_data); 1151 sraw_data->endpt = endpt; 1152 sraw_data->tdata = tdata; 1153 sraw_data->app_token = token; 1154 sraw_data->app_cb = cb; 1155 1156 if (sel) { 1157 sraw_data->sel = PJ_POOL_ALLOC_T(tdata->pool, pjsip_tpselector); 1158 pj_memcpy(sraw_data->sel, sel, sizeof(pjsip_tpselector)); 1159 pjsip_tpselector_add_ref(sraw_data->sel); 1160 } 1161 1162 /* Resolve destination host. 1163 * The processing then resumed when the resolving callback is called. 1164 */ 1165 pjsip_endpt_resolve( endpt, tdata->pool, &dest_info, sraw_data, 1166 &send_raw_resolver_callback); 1167 return PJ_SUCCESS; 1168 } 1169 1026 1170 1027 1171 /* … … 1216 1360 pjsip_tx_data *tdata, 1217 1361 void *token, 1218 pjsip_ endpt_callback cb)1362 pjsip_send_callback cb) 1219 1363 { 1220 1364 /* Determine which transports and addresses to send the response, … … 1265 1409 pjsip_tx_data *tdata, 1266 1410 void *token, 1267 pjsip_ endpt_callback cb)1411 pjsip_send_callback cb) 1268 1412 { 1269 1413 pjsip_response_addr res_addr;
Note: See TracChangeset
for help on using the changeset viewer.