Changeset 161:44e78cf7fed0 in verona
Legend:
- Unmodified
- Added
- Removed
-
phapi/phapi.c
r150 r161 294 294 #define ph_custom_lock() osip_mutex_lock(ph_custom_mutex) 295 295 #define ph_custom_unlock() osip_mutex_unlock(ph_custom_mutex) 296 static void ph_apply_header_monitor(osip_message_t* msg, struct ph_hdr_list *hlist); 297 298 299 ph_mutex_t *ph_hdrmon_mutex; 300 int ph_hdrmon_idx; 301 osip_list_t ph_hdrmon_list; 302 303 #define ph_hdrmon_lock() osip_mutex_lock(ph_hdrmon_mutex) 304 #define ph_hdrmon_unlock() osip_mutex_unlock(ph_hdrmon_mutex) 305 296 306 297 307 … … 4123 4133 osip_list_init(&ph_custom_headers); 4124 4134 4135 ph_hdrmon_mutex = osip_mutex_init(); 4136 osip_list_init(&ph_hdrmon_list); 4137 4138 4139 4125 4140 if (asyncmode) 4126 4141 phapithread = osip_thread_create(20000, ph_api_thread, (void*)0); … … 4889 4904 info.remoteSdp = sdp = ph_req_get_body(je->response); 4890 4905 4906 ph_apply_header_monitor(je->response, &info.hlist); 4891 4907 4892 4908 phcb->callProgress(ca->cid, &info); 4893 done:4909 done: 4894 4910 if (remoteUri) 4895 4911 osip_free(remoteUri); … … 4900 4916 if (sdp) 4901 4917 osip_free(sdp); 4918 4919 if (info.hlist.elems) 4920 osip_free(info.hlist.elems); 4921 4902 4922 } 4903 4923 } … … 5044 5064 * the local var 5045 5065 */ 5066 ph_apply_header_monitor(je->response, &info.hlist); 5046 5067 phcb->callProgress(ca->cid, &info); 5047 5068 } … … 5060 5081 if (from) 5061 5082 osip_free(from); 5083 5084 if (info.hlist.elems) 5085 osip_free(info.hlist.elems); 5062 5086 5063 5087 } … … 5094 5118 info.streams = ca->nego_mflags; 5095 5119 5120 ph_apply_header_monitor(je->response, &info.hlist); 5096 5121 phcb->callProgress(ca->cid, &info); 5097 5122 } … … 5104 5129 if (to) 5105 5130 free(to); 5131 5132 if (info.hlist.elems) 5133 osip_free(info.hlist.elems); 5134 5106 5135 5107 5136 } … … 5134 5163 if (from) 5135 5164 osip_free(from); 5165 5166 5136 5167 } 5137 5168 … … 5253 5284 info.streams = ca->nego_mflags; 5254 5285 5286 ph_apply_header_monitor(je->response, &info.hlist); 5255 5287 5256 5288 phcb->callProgress(je->cid, &info); … … 5265 5297 if (from) 5266 5298 osip_free(from); 5299 5300 if (info.hlist.elems) 5301 osip_free(info.hlist.elems); 5267 5302 } 5268 5303 … … 5311 5346 } 5312 5347 5348 ph_apply_header_monitor(je->response, &info.hlist); 5313 5349 5314 5350 phcb->callProgress(je->cid, &info); … … 5322 5358 if (from) 5323 5359 osip_free(from); 5360 5361 if (info.hlist.elems) 5362 osip_free(info.hlist.elems); 5324 5363 } 5325 5364 … … 5352 5391 info.errorCode = s; 5353 5392 5393 ph_apply_header_monitor(je->response, &info.hlist); 5394 5354 5395 phcb->callProgress(je->cid, &info); 5355 5396 … … 5363 5404 if (from) 5364 5405 osip_free(from); 5406 5407 if (info.hlist.elems) 5408 osip_free(info.hlist.elems); 5365 5409 } 5366 5410 … … 5398 5442 } 5399 5443 5444 ph_apply_header_monitor(je->request, &info.hlist); 5445 5400 5446 phcb->callProgress(je->cid, &info); 5401 5447 … … 5409 5455 if (from) 5410 5456 osip_free(from); 5457 5458 if (info.hlist.elems) 5459 osip_free(info.hlist.elems); 5411 5460 } 5412 5461 … … 5437 5486 // info.localUri = from = ph_req_get_to(je->response); 5438 5487 5488 ph_apply_header_monitor(je->request, &info.hlist); 5489 5439 5490 phcb->callProgress(je->cid, &info); 5440 5491 … … 5448 5499 if (from) 5449 5500 osip_free(from); 5501 5502 if (info.hlist.elems) 5503 osip_free(info.hlist.elems); 5450 5504 } 5451 5505 … … 5475 5529 info.event = phCALLCLOSED; 5476 5530 info.errorCode = 0; 5531 5532 ph_apply_header_monitor(je->request, &info.hlist); 5477 5533 phcb->callProgress(je->cid, &info); 5478 5534 } … … 5482 5538 ph_refer_notify(rca->rdid, ph_req_get_status(je->response), "Closed", 1); 5483 5539 } 5540 5541 if (info.hlist.elems) 5542 osip_free(info.hlist.elems); 5484 5543 } 5485 5544 … … 5579 5638 DBG_SIP_NEGO("Retrying reg=%d for vlid=%d i=%d t=%d\n", je->rid, vlid, i, newtimeout); 5580 5639 } 5640 5641 5581 5642 phcb->regProgress(vlid, mask | (status ? status : 500) ); 5582 5643 … … 5640 5701 info.event = phMsgNew; 5641 5702 info.content = body = ph_req_get_body(je->request); 5703 ph_apply_header_monitor(je->request, &info.hlist); 5704 5642 5705 if (ctt) 5643 5706 { … … 5658 5721 info.to = to = ph_req_get_to(je->response); 5659 5722 info.from = from = ph_req_get_from(je->response); 5723 ph_apply_header_monitor(je->response, &info.hlist); 5724 5660 5725 if (phcb->msgProgress != NULL) 5661 5726 phcb->msgProgress(je->tid, &info); … … 5668 5733 if (je->response) 5669 5734 { 5735 ph_apply_header_monitor(je->response, &info.hlist); 5736 5670 5737 info.to = to = ph_req_get_to(je->response); 5671 5738 info.from = from = ph_req_get_from(je->response); 5672 5739 } else if (je->request) 5673 5740 { 5741 ph_apply_header_monitor(je->request, &info.hlist); 5674 5742 info.to = to = ph_req_get_to(je->request); 5675 5743 info.from = from = ph_req_get_from(je->request); … … 5691 5759 if (body) 5692 5760 osip_free(body); 5761 5762 if (info.hlist.elems) 5763 osip_free(info.hlist.elems); 5693 5764 } 5694 5765 … … 5760 5831 osip_uri_to_str(je->response->req_uri, &info.to); 5761 5832 5833 ph_apply_header_monitor(je->response, &info.hlist); 5834 5762 5835 if (phcb->subscriptionProgress != NULL) 5763 5836 phcb->subscriptionProgress (je->sid, &info); … … 5773 5846 else 5774 5847 { 5848 5849 ph_apply_header_monitor(je->response, &info.hlist); 5850 5775 5851 if (je->response->status_code == 404) { 5776 5852 info.event = phSubscriptionErrNotFound; … … 5783 5859 } 5784 5860 } 5861 5862 if (info.from) 5863 osip_free(info.from); 5864 5865 if (info.to) 5866 osip_free(info.to); 5867 5868 if (info.hlist.elems) 5869 osip_free(info.hlist.elems) 5785 5870 } 5786 5871 … … 6296 6381 if (!osip_strcasecmp(h, "Expires")) 6297 6382 osip_message_replace_header(req, "Expires", v); 6298 else if (!osip_strcasecmp(h, "Allow"))6299 osip_message_set_allow(req, v);6300 else if (!osip_strcasecmp(h, "Accept"))6301 osip_message_set_accept(req, v);6302 else if (!osip_strcasecmp(h, "Content-Type"))6303 osip_message_set_content_type(req, v);6304 else if (!osip_strcasecmp(h, "Content-Encoding"))6305 osip_message_set_content_encoding(req, v);6306 else if (!osip_strcasecmp(h, "Accept-Language"))6307 osip_message_set_accept_language(req, v);6308 6383 else 6309 osip_message_set_header(req, h, v);6384 osip_message_set_multiple_header(req, h, v); 6310 6385 6311 6386 } … … 6381 6456 6382 6457 6458 int 6459 phMonitorHeader(const char *reqnames, const char *hdrname) 6460 { 6461 struct ph_custom_hdr *hdr; 6462 int idx; 6463 6464 hdr = (struct ph_custom_hdr*) osip_malloc(sizeof(struct ph_custom_hdr)); 6465 6466 if (!hdr) 6467 return -1; 6468 6469 memset(hdr, 0, sizeof(*hdr)); 6470 6471 hdr->matchrequests = osip_strdup(reqnames); 6472 hdr->hdrname = osip_strdup(hdrname); 6473 hdr->enabled = 1; 6474 6475 ph_hdrmon_lock(); 6476 idx = hdr->idx = ++ph_hdrmon_idx; 6477 osip_list_add(&ph_hdrmon_list, hdr, -1); 6478 ph_hdrmon_unlock(); 6479 6480 return idx; 6481 6482 } 6483 6484 int phEnableMonitor(int idx, int enable) 6485 { 6486 struct ph_custom_hdr *hdr; 6487 int i = 0; 6488 6489 6490 6491 ph_hdrmon_lock(); 6492 do 6493 { 6494 hdr = (struct ph_custom_hdr *) osip_list_get(&ph_hdrmon_list, i++); 6495 } while(hdr); 6496 6497 if (hdr) 6498 hdr->enabled = enable; 6499 6500 ph_hdrmon_unlock(); 6501 return hdr == 0; 6502 } 6503 6504 6505 void phResetMonitoring() 6506 { 6507 ph_hdrmon_lock(); 6508 osip_list_special_free(&ph_hdrmon_list, custom_hdr_free); 6509 ph_hdrmon_idx = 0; 6510 ph_hdrmon_unlock(); 6511 } 6512 6513 static 6514 void ph_apply_header_monitor(osip_message_t* msg, struct ph_hdr_list *hlist) 6515 { 6516 const char* reqname; 6517 int i; 6518 const int NHDRS = 64; 6519 struct ph_hdr_val tmpval[NHDRS]; 6520 struct ph_hdr_list tmphlist = { 0, tmpval }; 6521 6522 if (MSG_IS_REQUEST(msg)) 6523 reqname = msg->sip_method; 6524 else 6525 reqname = msg->cseq->method; 6526 6527 6528 for(i = 0; ; i++) { 6529 struct ph_custom_hdr *chdr = (struct ph_custom_hdr *) osip_list_get(&ph_hdrmon_list, i); 6530 if (!chdr) 6531 break; 6532 6533 if (!strcmp(chdr->matchrequests, "*") || (0 != strstr(reqname, chdr->matchrequests))) { 6534 int h = 0; 6535 osip_header_t* hv; 6536 6537 while ((h = osip_message_header_get_byname(msg, chdr->hdrname, h, &hv))) { 6538 struct ph_hdr_val *phhv = &tmphlist.elems[tmphlist.count++]; 6539 phhv->hdr = hv->hname; 6540 phhv->val = hv->hvalue; 6541 } 6542 } 6543 } 6544 6545 if (tmphlist.count) { 6546 if (!hlist->elems) { 6547 hlist->elems = osip_malloc(sizeof(struct ph_hdr_val)*tmphlist.count); 6548 if (!hlist->elems) { 6549 return; 6550 } 6551 } 6552 memcpy(&hlist->elems[hlist->count], tmphlist.elems, tmphlist.count*sizeof(struct ph_hdr_val)); 6553 hlist->count += tmphlist.count; 6554 } 6555 6556 } 6557 6558 6559 -
phapi/phapi.h
r156 r161 589 589 /** 590 590 * Add customization rule for given header, for given request types 591 * the customization can be later disabled and re- anabled by using phEnableCustomization...591 * the customization can be later disabled and re-enabled by using phEnableCustomization... 592 592 * 593 593 * @param reqnames comma separated list of SIP REQUEST NAMES in capital letters to which this rule apply ("*" means all requests) … … 601 601 * Enable or Disable a given customization 602 602 * 603 * @param custID the customization id (value return deby phAddCustomHeader)603 * @param custID the customization id (value returned by phAddCustomHeader) 604 604 * @param enable if zero the customization is disabled else enable 605 605 * @return 0 in case of success, -1 if custID specifies non-existent … … 608 608 609 609 610 610 /** 611 * Add monitoring rule for given header, for given request/response types 612 * the rule can be later disabled and re-enabled by using phEnableCustomization... 613 * 614 * @param reqnames comma separated list of SIP REQUEST NAMES in capital letters to which this rule apply ("*" means all requests) 615 * @param hdrname the header name to add 616 * @param hdrval header value to add 617 * @return -1 in case of failure (no memory) or positive index to use in phEnableMonitor... 618 */ 619 620 PHAPI_EXPORT int phMonitorHeader(const char *reqnames, const char *hdrname); 621 622 /* 623 * Enable or Disable a given montor rule 624 * 625 * @param ruleID the rule id (value returned by phMonitorHeader) 626 * @param enable if zero the rule is disabled else enable 627 * @return 0 in case of success, -1 if custID specifies non-existent 628 */ 629 630 PHAPI_EXPORT int phEnableMonitor(int ruleID, int enable); 631 632 PHAPI_EXPORT void phResetMonitoring(); 611 633 612 634 /********************CONFERENCING*********************/ … … 785 807 786 808 /********************STRUCTS*********************/ 809 810 struct ph_hdr_val { 811 const char *hdr; 812 const char *val; 813 }; 814 typedef struct ph_hdr_val ph_hdr_val_t; 815 816 struct ph_hdr_list { 817 int count; 818 struct ph_hdr_val *elems; 819 }; 820 821 typedef struct ph_hdr_list ph_hdr_list_t; 787 822 788 823 /** … … 815 850 int dtmfDigit; /*!< valid for DTMF */ 816 851 const char *remoteSdp; 852 struct ph_hdr_list hlist; 817 853 }; 818 854 typedef struct phCallStateInfo phCallStateInfo_t; … … 838 874 const char *rawctt; 839 875 int cid; /*!< when non-zero this is message inside a dialog corresponding to call 'cid' */ 876 struct ph_hdr_list hlist; 840 877 }; 841 878 typedef struct phMsgStateInfo phMsgStateInfo_t; … … 856 893 char *from; 857 894 char *to; 895 struct ph_hdr_list hlist; 858 896 }; 859 897 typedef struct phSubscriptionStateInfo phSubscriptionStateInfo_t;
Note: See TracChangeset
for help on using the changeset viewer.
