Ignore:
Timestamp:
Dec 30, 2005 11:50:15 PM (18 years ago)
Author:
bennylp
Message:

Basic module, transport, and sending messages

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/src/pjsip/sip_msg.c

    r82 r106  
    2222#include <pj/string.h> 
    2323#include <pj/pool.h> 
     24#include <pj/assert.h> 
    2425 
    2526/* 
     
    3031#endif 
    3132 
    32 static const pj_str_t method_names[] =  
    33 { 
    34     { "INVITE",     6 }, 
    35     { "CANCEL",     6 }, 
    36     { "ACK",        3 }, 
    37     { "BYE",        3 }, 
    38     { "REGISTER",   8 }, 
    39     { "OPTIONS",    7 }, 
     33const pjsip_method  
     34    pjsip_invite_method     = { PJSIP_INVITE_METHOD,    { "INVITE",6 }  }, 
     35    pjsip_cancel_method     = { PJSIP_CANCEL_METHOD,    { "CANCEL",6 }  }, 
     36    pjsip_ack_method        = { PJSIP_ACK_METHOD,       { "ACK",3}      }, 
     37    pjsip_bye_method        = { PJSIP_BYE_METHOD,       { "BYE",3}      }, 
     38    pjsip_register_method   = { PJSIP_REGISTER_METHOD,  { "REGISTER",8} }, 
     39    pjsip_options_method    = { PJSIP_OPTIONS_METHOD,   { "OPTIONS",7}  }; 
     40 
     41static const pj_str_t *method_names[] =  
     42{ 
     43    &pjsip_invite_method.name, 
     44    &pjsip_cancel_method.name, 
     45    &pjsip_ack_method.name, 
     46    &pjsip_bye_method.name, 
     47    &pjsip_register_method.name, 
     48    &pjsip_options_method.name 
    4049}; 
    4150 
     
    179188PJ_DEF(void) pjsip_method_set( pjsip_method *m, pjsip_method_e me ) 
    180189{ 
     190    pj_assert(me < PJSIP_OTHER_METHOD); 
    181191    m->id = me; 
    182     m->name = method_names[me]; 
     192    m->name = *method_names[me]; 
    183193} 
    184194 
     
    188198    int i; 
    189199    for (i=0; i<PJ_ARRAY_SIZE(method_names); ++i) { 
    190         if (pj_stricmp(str, &method_names[i])==0) { 
     200        if (pj_stricmp(str, method_names[i])==0) { 
    191201            m->id = (pjsip_method_e)i; 
    192             m->name = method_names[i]; 
     202            m->name = *method_names[i]; 
    193203            return; 
    194204        } 
     
    236246} 
    237247 
    238 PJ_DEF(void*)  pjsip_msg_find_hdr( pjsip_msg *msg,  
    239                                    pjsip_hdr_e hdr_type, void *start) 
    240 { 
    241     pjsip_hdr *hdr=start, *end=&msg->hdr; 
     248PJ_DEF(void*)  pjsip_msg_find_hdr( const pjsip_msg *msg,  
     249                                   pjsip_hdr_e hdr_type, const void *start) 
     250{ 
     251    const pjsip_hdr *hdr=start, *end=&msg->hdr; 
    242252 
    243253    if (hdr == NULL) { 
     
    246256    for (; hdr!=end; hdr = hdr->next) { 
    247257        if (hdr->type == hdr_type) 
    248             return hdr; 
     258            return (void*)hdr; 
    249259    } 
    250260    return NULL; 
    251261} 
    252262 
    253 PJ_DEF(void*)  pjsip_msg_find_hdr_by_name( pjsip_msg *msg,  
    254                                            const pj_str_t *name, void *start) 
    255 { 
    256     pjsip_hdr *hdr=start, *end=&msg->hdr; 
     263PJ_DEF(void*)  pjsip_msg_find_hdr_by_name( const pjsip_msg *msg,  
     264                                           const pj_str_t *name,  
     265                                           const void *start) 
     266{ 
     267    const pjsip_hdr *hdr=start, *end=&msg->hdr; 
    257268 
    258269    if (hdr == NULL) { 
     
    262273        if (hdr->type < PJSIP_H_OTHER) { 
    263274            if (pj_stricmp(&pjsip_hdr_names[hdr->type], name) == 0) 
    264                 return hdr; 
     275                return (void*)hdr; 
    265276        } else { 
    266277            if (pj_stricmp(&hdr->name, name) == 0) 
    267                 return hdr; 
     278                return (void*)hdr; 
    268279        } 
    269280    } 
     
    281292} 
    282293 
    283 PJ_DEF(pj_ssize_t) pjsip_msg_print( pjsip_msg *msg, char *buf, pj_size_t size) 
     294PJ_DEF(pj_ssize_t) pjsip_msg_print( const pjsip_msg *msg,  
     295                                    char *buf, pj_size_t size) 
    284296{ 
    285297    char *p=buf, *end=buf+size; 
     
    13501362    pjsip_via_hdr *hdr = pj_pool_calloc(pool, 1, sizeof(*hdr)); 
    13511363    init_hdr(hdr, PJSIP_H_VIA, &via_hdr_vptr); 
    1352     hdr->sent_by.port = 5060; 
     1364    //hdr->sent_by.port = 5060; 
    13531365    hdr->ttl_param = -1; 
    13541366    hdr->rport_param = -1; 
     
    13841396    pj_memcpy(buf, hdr->sent_by.host.ptr, hdr->sent_by.host.slen); 
    13851397    buf += hdr->sent_by.host.slen; 
    1386     *buf++ = ':'; 
    1387     printed = pj_utoa(hdr->sent_by.port, buf); 
    1388     buf += printed; 
     1398    if (hdr->sent_by.port != 0) { 
     1399        *buf++ = ':'; 
     1400        printed = pj_utoa(hdr->sent_by.port, buf); 
     1401        buf += printed; 
     1402    } 
    13891403 
    13901404    if (hdr->ttl_param >= 0) { 
Note: See TracChangeset for help on using the changeset viewer.