Changeset 2940 for pjproject/trunk
- Timestamp:
- Oct 12, 2009 7:44:14 AM (15 years ago)
- Location:
- pjproject/trunk/pjsip
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip/include/pjsip-simple/publish.h
r2661 r2940 65 65 typedef struct pjsip_publishc pjsip_publishc; 66 66 67 68 /** 69 * Client publication options. Application should initialize this structure 70 * with its default values by calling #pjsip_publishc_opt_default() 71 */ 72 typedef struct pjsip_publishc_opt 73 { 74 /** 75 * Specify whether the client publication session should queue the 76 * PUBLISH request should there be another PUBLISH transaction still 77 * pending. If this is set to false, the client will return error 78 * on the PUBLISH request if there is another PUBLISH transaction still 79 * in progress. 80 * 81 * Default: PJSIP_PUBLISHC_QUEUE_REQUEST 82 */ 83 pj_bool_t queue_request; 84 85 } pjsip_publishc_opt; 67 86 68 87 … … 90 109 91 110 /** 111 * Initialize client publication session option with default values. 112 * 113 * @param opt The option. 114 */ 115 PJ_DECL(void) pjsip_publishc_opt_default(pjsip_publishc_opt *opt); 116 117 118 /** 92 119 * Initialize client publication module. 93 120 * … … 99 126 100 127 101 102 128 /** 103 129 * Create client publication structure. 104 130 * 105 131 * @param endpt Endpoint, used to allocate pool from. 106 * @param opt ions Option flags.132 * @param opt Options, or NULL to specify default options. 107 133 * @param token Opaque data to be associated with the client publication. 108 134 * @param cb Pointer to callback function to receive publication status. … … 112 138 */ 113 139 PJ_DECL(pj_status_t) pjsip_publishc_create( pjsip_endpoint *endpt, 114 unsigned options,140 const pjsip_publishc_opt *opt, 115 141 void *token, 116 142 pjsip_publishc_cb *cb, … … 270 296 * completes. 271 297 * 298 * If the session has another PUBLISH request outstanding, the behavior 299 * depends on whether request queueing is enabled in the session (this was 300 * set by setting \a queue_request field of #pjsip_publishc_opt to true 301 * when calling #pjsip_publishc_create(). Default is true). If request 302 * queueing is enabled, the request will be queued and the function will 303 * return PJ_EPENDING. One the outstanding request is complete, the queued 304 * request will be sent automatically. If request queueing is disabled, the 305 * function will reject the request and return PJ_EBUSY. 306 * 272 307 * @param pubc The client publication structure. 273 308 * @param tdata Transmit data. 274 309 * 275 * @return PJ_SUCCESS on success. 310 * @return - PJ_SUCCESS on success, or 311 * - PJ_EPENDING if request is queued, or 312 * - PJ_EBUSY if request is rejected because another PUBLISH 313 * request is in progress, or 314 * - other status code to indicate the error. 276 315 */ 277 316 PJ_DECL(pj_status_t) pjsip_publishc_send(pjsip_publishc *pubc, -
pjproject/trunk/pjsip/include/pjsip/sip_config.h
r2859 r2940 897 897 898 898 899 /** 900 * Specify whether the client publication session should queue the 901 * PUBLISH request should there be another PUBLISH transaction still 902 * pending. If this is set to false, the client will return error 903 * on the PUBLISH request if there is another PUBLISH transaction still 904 * in progress. 905 * 906 * Default: 1 (yes) 907 */ 908 #ifndef PJSIP_PUBLISHC_QUEUE_REQUEST 909 # define PJSIP_PUBLISHC_QUEUE_REQUEST 1 910 #endif 911 912 899 913 PJ_END_DECL 900 914 -
pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h
r2864 r2940 1798 1798 1799 1799 /** 1800 * Event publication options. 1801 */ 1802 pjsip_publishc_opt publish_opt; 1803 1804 /** 1800 1805 * Authentication preference. 1801 1806 */ -
pjproject/trunk/pjsip/src/pjsip-simple/publishc.c
r2939 r2940 58 58 59 59 /** 60 * Pending request list. 61 */ 62 typedef struct pending_publish 63 { 64 PJ_DECL_LIST_MEMBER(pjsip_tx_data); 65 } pending_publish; 66 67 68 /** 60 69 * SIP client publication structure. 61 70 */ … … 66 75 pj_bool_t _delete_flag; 67 76 int pending_tsx; 68 77 pj_mutex_t *mutex; 78 79 pjsip_publishc_opt opt; 69 80 void *token; 70 81 pjsip_publishc_cb *cb; … … 92 103 pj_time_val next_refresh; 93 104 pj_timer_entry timer; 105 106 /* Pending PUBLISH request */ 107 pending_publish pending_reqs; 94 108 }; 95 109 110 111 PJ_DEF(void) pjsip_publishc_opt_default(pjsip_publishc_opt *opt) 112 { 113 pj_bzero(opt, sizeof(*opt)); 114 opt->queue_request = PJSIP_PUBLISHC_QUEUE_REQUEST; 115 } 96 116 97 117 … … 128 148 129 149 PJ_DEF(pj_status_t) pjsip_publishc_create( pjsip_endpoint *endpt, 130 unsigned options,150 const pjsip_publishc_opt *opt, 131 151 void *token, 132 152 pjsip_publishc_cb *cb, … … 135 155 pj_pool_t *pool; 136 156 pjsip_publishc *pubc; 157 pjsip_publishc_opt default_opt; 137 158 pj_status_t status; 138 159 139 160 /* Verify arguments. */ 140 161 PJ_ASSERT_RETURN(endpt && cb && p_pubc, PJ_EINVAL); 141 PJ_ASSERT_RETURN(options == 0, PJ_EINVAL);142 143 PJ_UNUSED_ARG(options);144 162 145 163 pool = pjsip_endpt_create_pool(endpt, "pubc%p", 1024, 1024); … … 154 172 pubc->expires = PJSIP_PUBC_EXPIRATION_NOT_SPECIFIED; 155 173 174 if (!opt) { 175 pjsip_publishc_opt_default(&default_opt); 176 opt = &default_opt; 177 } 178 pj_memcpy(&pubc->opt, opt, sizeof(*opt)); 179 pj_list_init(&pubc->pending_reqs); 180 181 status = pj_mutex_create_recursive(pubc->pool, "pubc%p", &pubc->mutex); 182 if (status != PJ_SUCCESS) { 183 pj_pool_release(pool); 184 return status; 185 } 186 156 187 status = pjsip_auth_clt_init(&pubc->auth_sess, endpt, pubc->pool, 0); 157 if (status != PJ_SUCCESS) 188 if (status != PJ_SUCCESS) { 189 pj_mutex_destroy(pubc->mutex); 190 pj_pool_release(pool); 158 191 return status; 192 } 159 193 160 194 pj_list_init(&pubc->route_set); … … 181 215 } 182 216 217 if (pubc->mutex) 218 pj_mutex_destroy(pubc->mutex); 183 219 pjsip_endpt_release_pool(pubc->endpt, pubc->pool); 184 220 } … … 576 612 if (pubc->auto_refresh && expiration!=0 && expiration!=0xFFFF) { 577 613 pj_time_val delay = { 0, 0}; 614 615 /* Cancel existing timer, if any */ 616 if (pubc->timer.id != 0) { 617 pjsip_endpt_cancel_timer(pubc->endpt, &pubc->timer); 618 pubc->timer.id = 0; 619 } 578 620 579 621 delay.sec = expiration - DELAY_BEFORE_REFRESH; … … 614 656 615 657 --pubc->pending_tsx; 658 659 /* If we have pending request(s), send them now */ 660 pj_mutex_lock(pubc->mutex); 661 while (!pj_list_empty(&pubc->pending_reqs)) { 662 pjsip_tx_data *tdata = pubc->pending_reqs.next; 663 pj_list_erase(tdata); 664 status = pjsip_publishc_send(pubc, tdata); 665 if (status == PJ_EPENDING) { 666 pj_assert(!"Not expected"); 667 pj_list_erase(tdata); 668 pjsip_tx_data_dec_ref(tdata); 669 } else if (status == PJ_SUCCESS) { 670 break; 671 } 672 } 673 pj_mutex_unlock(pubc->mutex); 616 674 } 617 675 … … 630 688 pj_uint32_t cseq; 631 689 690 PJ_ASSERT_RETURN(pubc && tdata, PJ_EINVAL); 691 632 692 /* Make sure we don't have pending transaction. */ 693 pj_mutex_lock(pubc->mutex); 633 694 if (pubc->pending_tsx) { 634 PJ_LOG(4,(THIS_FILE, "Unable to send request, pubc has another " 635 "transaction pending")); 636 pjsip_tx_data_dec_ref( tdata ); 637 return PJSIP_EBUSY; 638 } 695 if (pubc->opt.queue_request) { 696 pj_list_push_back(&pubc->pending_reqs, tdata); 697 pj_mutex_unlock(pubc->mutex); 698 PJ_LOG(4,(THIS_FILE, "Request is queued, pubc has another " 699 "transaction pending")); 700 return PJ_EPENDING; 701 } else { 702 pjsip_tx_data_dec_ref(tdata); 703 pj_mutex_unlock(pubc->mutex); 704 PJ_LOG(4,(THIS_FILE, "Unable to send request, pubc has another " 705 "transaction pending")); 706 return PJ_EBUSY; 707 } 708 } 709 pj_mutex_unlock(pubc->mutex); 639 710 640 711 /* Invalidate message buffer. */ -
pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c
r2895 r2940 162 162 163 163 cfg->reg_timeout = PJSUA_REG_INTERVAL; 164 pjsip_publishc_opt_default(&cfg->publish_opt); 164 165 cfg->transport_id = PJSUA_INVALID_ID; 165 166 cfg->allow_contact_rewrite = PJ_TRUE; -
pjproject/trunk/pjsip/src/pjsua-lib/pjsua_pres.c
r2824 r2940 1074 1074 /* Send the PUBLISH request */ 1075 1075 status = pjsip_publishc_send(acc->publish_sess, tdata); 1076 if (status != PJ_SUCCESS) { 1076 if (status == PJ_EPENDING) { 1077 PJ_LOG(3,(THIS_FILE, "Previous request is in progress, " 1078 "PUBLISH request is queued")); 1079 } else if (status != PJ_SUCCESS) { 1077 1080 pjsua_perror(THIS_FILE, "Error sending PUBLISH request", status); 1078 1081 goto on_error; … … 1103 1106 1104 1107 /* Create client publication */ 1105 status = pjsip_publishc_create(pjsua_var.endpt, 0, acc, &publish_cb, 1108 status = pjsip_publishc_create(pjsua_var.endpt, &acc_cfg->publish_opt, 1109 acc, &publish_cb, 1106 1110 &acc->publish_sess); 1107 1111 if (status != PJ_SUCCESS) {
Note: See TracChangeset
for help on using the changeset viewer.