Changeset 161:44e78cf7fed0 in verona


Ignore:
Timestamp:
Apr 3, 2011 4:19:01 PM (2 years ago)
Author:
Vadim Lebedev <vadim@…>
Branch:
default
Message:

implement header monitoring

Location:
phapi
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • phapi/phapi.c

    r150 r161  
    294294#define ph_custom_lock() osip_mutex_lock(ph_custom_mutex) 
    295295#define ph_custom_unlock() osip_mutex_unlock(ph_custom_mutex) 
     296static void ph_apply_header_monitor(osip_message_t* msg,  struct ph_hdr_list *hlist); 
     297 
     298 
     299ph_mutex_t *ph_hdrmon_mutex; 
     300int ph_hdrmon_idx; 
     301osip_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 
    296306 
    297307 
     
    41234133        osip_list_init(&ph_custom_headers); 
    41244134 
     4135        ph_hdrmon_mutex = osip_mutex_init(); 
     4136        osip_list_init(&ph_hdrmon_list); 
     4137 
     4138 
     4139 
    41254140        if (asyncmode) 
    41264141                phapithread = osip_thread_create(20000, ph_api_thread, (void*)0); 
     
    48894904                info.remoteSdp = sdp = ph_req_get_body(je->response); 
    48904905 
     4906                ph_apply_header_monitor(je->response, &info.hlist); 
    48914907 
    48924908                phcb->callProgress(ca->cid, &info); 
    4893                 done: 
     4909done: 
    48944910                if (remoteUri) 
    48954911                        osip_free(remoteUri); 
     
    49004916                if (sdp) 
    49014917                        osip_free(sdp); 
     4918 
     4919                if (info.hlist.elems) 
     4920                        osip_free(info.hlist.elems); 
     4921 
    49024922        } 
    49034923} 
     
    50445064                 * the local var 
    50455065                 */ 
     5066                ph_apply_header_monitor(je->response, &info.hlist); 
    50465067                phcb->callProgress(ca->cid, &info); 
    50475068        } 
     
    50605081        if (from) 
    50615082                osip_free(from); 
     5083 
     5084        if (info.hlist.elems) 
     5085                osip_free(info.hlist.elems); 
    50625086 
    50635087} 
     
    50945118                info.streams = ca->nego_mflags; 
    50955119 
     5120                ph_apply_header_monitor(je->response, &info.hlist); 
    50965121                phcb->callProgress(ca->cid, &info); 
    50975122        } 
     
    51045129        if (to) 
    51055130                free(to); 
     5131 
     5132        if (info.hlist.elems) 
     5133                osip_free(info.hlist.elems); 
     5134 
    51065135 
    51075136} 
     
    51345163        if (from) 
    51355164                osip_free(from); 
     5165 
     5166 
    51365167} 
    51375168 
     
    52535284        info.streams = ca->nego_mflags; 
    52545285 
     5286        ph_apply_header_monitor(je->response, &info.hlist); 
    52555287 
    52565288        phcb->callProgress(je->cid, &info); 
     
    52655297        if (from) 
    52665298                osip_free(from); 
     5299 
     5300        if (info.hlist.elems) 
     5301                osip_free(info.hlist.elems); 
    52675302} 
    52685303 
     
    53115346        } 
    53125347 
     5348        ph_apply_header_monitor(je->response, &info.hlist); 
    53135349 
    53145350        phcb->callProgress(je->cid, &info); 
     
    53225358        if (from) 
    53235359                osip_free(from); 
     5360 
     5361        if (info.hlist.elems) 
     5362                osip_free(info.hlist.elems); 
    53245363} 
    53255364 
     
    53525391        info.errorCode = s; 
    53535392 
     5393        ph_apply_header_monitor(je->response, &info.hlist); 
     5394 
    53545395        phcb->callProgress(je->cid, &info); 
    53555396 
     
    53635404        if (from) 
    53645405                osip_free(from); 
     5406 
     5407        if (info.hlist.elems) 
     5408                osip_free(info.hlist.elems); 
    53655409} 
    53665410 
     
    53985442        } 
    53995443 
     5444        ph_apply_header_monitor(je->request, &info.hlist); 
     5445 
    54005446        phcb->callProgress(je->cid, &info); 
    54015447 
     
    54095455        if (from) 
    54105456                osip_free(from); 
     5457 
     5458        if (info.hlist.elems) 
     5459                osip_free(info.hlist.elems); 
    54115460} 
    54125461 
     
    54375486        //      info.localUri = from = ph_req_get_to(je->response); 
    54385487 
     5488        ph_apply_header_monitor(je->request, &info.hlist); 
     5489 
    54395490        phcb->callProgress(je->cid, &info); 
    54405491 
     
    54485499        if (from) 
    54495500                osip_free(from); 
     5501 
     5502        if (info.hlist.elems) 
     5503                osip_free(info.hlist.elems); 
    54505504} 
    54515505 
     
    54755529                info.event = phCALLCLOSED; 
    54765530                info.errorCode = 0; 
     5531 
     5532                ph_apply_header_monitor(je->request, &info.hlist); 
    54775533                phcb->callProgress(je->cid, &info); 
    54785534        } 
     
    54825538                ph_refer_notify(rca->rdid, ph_req_get_status(je->response), "Closed", 1); 
    54835539        } 
     5540 
     5541        if (info.hlist.elems) 
     5542                osip_free(info.hlist.elems); 
    54845543} 
    54855544 
     
    55795638                        DBG_SIP_NEGO("Retrying reg=%d for vlid=%d i=%d t=%d\n", je->rid, vlid, i, newtimeout); 
    55805639                } 
     5640 
     5641 
    55815642                phcb->regProgress(vlid, mask | (status ? status : 500) ); 
    55825643 
     
    56405701                info.event = phMsgNew; 
    56415702                info.content = body = ph_req_get_body(je->request); 
     5703                ph_apply_header_monitor(je->request, &info.hlist); 
     5704 
    56425705                if (ctt) 
    56435706                { 
     
    56585721                info.to = to = ph_req_get_to(je->response); 
    56595722                info.from = from = ph_req_get_from(je->response); 
     5723                ph_apply_header_monitor(je->response, &info.hlist); 
     5724 
    56605725                if (phcb->msgProgress != NULL) 
    56615726                        phcb->msgProgress(je->tid, &info); 
     
    56685733                if (je->response) 
    56695734                { 
     5735                        ph_apply_header_monitor(je->response, &info.hlist); 
     5736 
    56705737                        info.to = to = ph_req_get_to(je->response); 
    56715738                        info.from = from = ph_req_get_from(je->response); 
    56725739                } else if (je->request) 
    56735740                { 
     5741                        ph_apply_header_monitor(je->request, &info.hlist); 
    56745742                        info.to = to = ph_req_get_to(je->request); 
    56755743                        info.from = from = ph_req_get_from(je->request); 
     
    56915759        if (body) 
    56925760                osip_free(body); 
     5761 
     5762        if (info.hlist.elems) 
     5763                osip_free(info.hlist.elems); 
    56935764} 
    56945765 
     
    57605831                osip_uri_to_str(je->response->req_uri, &info.to); 
    57615832 
     5833                ph_apply_header_monitor(je->response, &info.hlist); 
     5834 
    57625835                if (phcb->subscriptionProgress != NULL) 
    57635836                        phcb->subscriptionProgress (je->sid, &info); 
     
    57735846                else 
    57745847                { 
     5848 
     5849                        ph_apply_header_monitor(je->response, &info.hlist); 
     5850 
    57755851                        if (je->response->status_code == 404) { 
    57765852                                info.event = phSubscriptionErrNotFound; 
     
    57835859                } 
    57845860        } 
     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) 
    57855870} 
    57865871 
     
    62966381    if (!osip_strcasecmp(h, "Expires")) 
    62976382      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); 
    63086383    else 
    6309         osip_message_set_header(req, h, v); 
     6384        osip_message_set_multiple_header(req, h, v); 
    63106385 
    63116386} 
     
    63816456 
    63826457 
     6458int 
     6459phMonitorHeader(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 
     6484int 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 
     6505void 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 
     6513static 
     6514void 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  
    589589/** 
    590590  * 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... 
    592592  * 
    593593  * @param reqnames  comma separated list of SIP REQUEST NAMES in capital letters  to which this rule apply ("*" means all requests) 
     
    601601 * Enable or Disable a given customization 
    602602 * 
    603  * @param custID   the customization id (value returnde by phAddCustomHeader) 
     603 * @param custID   the customization id (value returned by phAddCustomHeader) 
    604604 * @param enable   if zero the customization is disabled else enable 
    605605 * @return 0 in case of success, -1 if custID specifies non-existent 
     
    608608 
    609609 
    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 
     620PHAPI_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 
     630PHAPI_EXPORT int phEnableMonitor(int ruleID, int enable); 
     631 
     632PHAPI_EXPORT void phResetMonitoring(); 
    611633 
    612634/********************CONFERENCING*********************/ 
     
    785807 
    786808/********************STRUCTS*********************/ 
     809 
     810struct ph_hdr_val { 
     811        const char *hdr; 
     812        const char *val; 
     813}; 
     814typedef struct ph_hdr_val ph_hdr_val_t; 
     815 
     816struct ph_hdr_list { 
     817        int count; 
     818        struct ph_hdr_val *elems; 
     819}; 
     820 
     821typedef struct ph_hdr_list ph_hdr_list_t; 
    787822 
    788823/** 
     
    815850  int   dtmfDigit;           /*!< valid for DTMF */ 
    816851  const char *remoteSdp; 
     852  struct ph_hdr_list hlist; 
    817853}; 
    818854typedef struct phCallStateInfo phCallStateInfo_t; 
     
    838874  const char *rawctt; 
    839875  int   cid;     /*!<  when non-zero this is message inside a dialog corresponding to call 'cid' */ 
     876  struct ph_hdr_list hlist; 
    840877}; 
    841878typedef struct phMsgStateInfo  phMsgStateInfo_t; 
     
    856893        char *from; 
    857894        char *to; 
     895        struct ph_hdr_list hlist; 
    858896}; 
    859897typedef struct phSubscriptionStateInfo  phSubscriptionStateInfo_t; 
Note: See TracChangeset for help on using the changeset viewer.