本文整理汇总了C++中parse_contact函数的典型用法代码示例。如果您正苦于以下问题:C++ parse_contact函数的具体用法?C++ parse_contact怎么用?C++ parse_contact使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse_contact函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parse_message_for_register
/*! \brief
* Parse the whole message and bodies of all header fields
* that will be needed by registrar
*/
int parse_message_for_register(struct sip_msg* _m) {
struct hdr_field* ptr;
if (parse_headers(_m, HDR_EOH_F, 0) == -1) {
rerrno = R_PARSE;
LM_ERR("failed to parse headers\n");
return -1;
}
if (!_m->to) {
rerrno = R_TO_MISS;
LM_ERR("To not found\n");
return -2;
}
if (!_m->callid) {
rerrno = R_CID_MISS;
LM_ERR("Call-ID not found\n");
return -3;
}
if (!_m->cseq) {
rerrno = R_CS_MISS;
LM_ERR("CSeq not found\n");
return -4;
}
if (_m->expires && !_m->expires->parsed
&& (parse_expires(_m->expires) < 0)) {
rerrno = R_PARSE_EXP;
LM_ERR("failed to parse expires body\n");
return -5;
}
if (_m->contact) {
ptr = _m->contact;
while (ptr) {
if (ptr->type == HDR_CONTACT_T) {
if (!ptr->parsed && (parse_contact(ptr) < 0)) {
rerrno = R_PARSE_CONT;
LM_ERR("failed to parse Contact body\n");
return -6;
}
}
ptr = ptr->next;
}
}
return 0;
}
示例2: parse_message
/*
* Parse the whole message and bodies of all header fields
* that will be needed by registrar
*/
int parse_message(struct sip_msg* _m)
{
struct hdr_field* ptr;
if (parse_headers(_m, HDR_EOH_F, 0) == -1) {
rerrno = R_PARSE;
LOG(L_ERR, "parse_message(): Error while parsing headers\n");
return -1;
}
if (!_m->to) {
rerrno = R_TO_MISS;
LOG(L_ERR, "parse_message(): To not found\n");
return -2;
}
if (!_m->callid) {
rerrno = R_CID_MISS;
LOG(L_ERR, "parse_message(): Call-ID not found\n");
return -3;
}
if (!_m->cseq) {
rerrno = R_CS_MISS;
LOG(L_ERR, "parse_message(): CSeq not found\n");
return -4;
}
if (_m->expires && !_m->expires->parsed && (parse_expires(_m->expires) < 0)) {
rerrno = R_PARSE_EXP;
LOG(L_ERR, "parse_message(): Error while parsing expires body\n");
return -5;
}
if (_m->contact) {
ptr = _m->contact;
while(ptr) {
if (ptr->type == HDR_CONTACT_T) {
if (!ptr->parsed && (parse_contact(ptr) < 0)) {
rerrno = R_PARSE_CONT;
LOG(L_ERR, "parse_message(): Error while parsing Contact body\n");
return -6;
}
}
ptr = ptr->next;
}
}
return 0;
}
示例3: sca_get_msg_contact_uri
int
sca_get_msg_contact_uri( sip_msg_t *msg, str *contact_uri )
{
contact_body_t *contact_body;
assert( msg != NULL );
assert( contact_uri != NULL );
if ( SCA_HEADER_EMPTY( msg->contact )) {
LM_DBG( "Empty Contact header" );
contact_uri->s = NULL;
contact_uri->len = 0;
return( 0 );
}
if ( parse_contact( msg->contact ) < 0 ) {
LM_ERR( "Failed to parse Contact header: %.*s",
STR_FMT( &msg->contact->body ));
return( -1 );
}
if (( contact_body = (contact_body_t *)msg->contact->parsed ) == NULL ) {
LM_ERR( "Invalid Contact header: %.*s", STR_FMT( &msg->contact->body ));
return( -1 );
}
if ( contact_body->star ) {
LM_ERR( "Invalid Contact header: SCA Contact must not be \"*\"" );
return( -1 );
}
if ( contact_body->contacts == NULL ) {
LM_ERR( "Invalid Contact header: parser found no contacts" );
return( -1 );
}
if ( contact_body->contacts->next ) {
LM_ERR( "Invalid Contact header: Contact may only contain one URI" );
return( -1 );
}
contact_uri->s = contact_body->contacts->uri.s;
contact_uri->len = contact_body->contacts->uri.len;
return( 1 );
}
示例4: get_contact_uri
/**
* Extract URI from the Contact header field
* @param _m - the SIP message
* @param uri - URI to fill
* @param _c - contact to fill
* @returns 0 on success, -1 on error
*/
static inline int get_contact_uri(struct sip_msg* _m, struct sip_uri *uri, contact_t** _c)
{
if ((parse_headers(_m, HDR_CONTACT_F, 0) == -1) || !_m->contact)
return -1;
if (!_m->contact->parsed && parse_contact(_m->contact) < 0) {
LOG(L_ERR, "get_contact_uri: Error while parsing Contact body\n");
return -1;
}
*_c = ((contact_body_t*)_m->contact->parsed)->contacts;
if (*_c == NULL) {
LOG(L_DBG, "get_contact_uri: Error while parsing Contact body or star contact\n");
return -1;
}
if (parse_uri((*_c)->uri.s, (*_c)->uri.len, uri) < 0 || uri->host.len <= 0) {
LOG(L_ERR, "get_contact_uri: Error while parsing Contact URI\n");
return -1;
}
return 0;
}
示例5: get_routing_info
static inline void get_routing_info(struct sip_msg *msg, int is_req,
unsigned int *skip_rrs, str *contact, str *rr_set)
{
/* extract the contact address */
if (!msg->contact&&(parse_headers(msg,HDR_CONTACT_F,0)<0||!msg->contact)){
//LM_ERR("bad sip message or missing Contact hdr\n");
contact->s = NULL;
contact->len = 0;
} else {
if ( parse_contact(msg->contact)<0 ||
((contact_body_t *)msg->contact->parsed)->contacts==NULL ||
((contact_body_t *)msg->contact->parsed)->contacts->next!=NULL ) {
LM_ERR("bad Contact HDR\n");
contact->s = NULL;
contact->len = 0;
} else {
*contact = ((contact_body_t *)msg->contact->parsed)->contacts->uri;
}
}
/* extract the RR parts - parse all headers as we can have multiple
RR headers in the same message */
if( parse_headers(msg,HDR_EOH_F,0)<0 ){
LM_ERR("failed to parse record route header\n");
rr_set->s = 0;
rr_set->len = 0;
} else {
if(msg->record_route){
if( print_rr_body(msg->record_route, rr_set, !is_req,
skip_rrs) != 0 ){
LM_ERR("failed to print route records \n");
rr_set->s = 0;
rr_set->len = 0;
}
} else {
rr_set->s = 0;
rr_set->len = 0;
}
}
}
示例6: get_contact_uri
/*
* Extract URI from the Contact header field
*/
int
get_contact_uri(struct sip_msg* _m, struct sip_uri *uri, contact_t** _c)
{
if ((parse_headers(_m, HDR_CONTACT_F, 0) == -1) || !_m->contact)
return -1;
if (!_m->contact->parsed && parse_contact(_m->contact) < 0) {
LM_ERR("failed to parse Contact body\n");
return -1;
}
*_c = ((contact_body_t*)_m->contact->parsed)->contacts;
if (*_c == NULL)
/* no contacts found */
return -1;
if (parse_uri((*_c)->uri.s, (*_c)->uri.len, uri) < 0 || uri->host.len <= 0) {
LM_ERR("failed to parse Contact URI [%.*s]\n",
(*_c)->uri.len, ((*_c)->uri.s)?(*_c)->uri.s:"");
return -1;
}
return 0;
}
示例7: get_contact_uri
/*
* Parse Contact header field body and extract URI
* Does not parse headers !
*/
static inline int get_contact_uri(struct sip_msg* msg, str* uri)
{
contact_t* c;
uri->len = 0;
if (!msg->contact) return 1;
if (parse_contact(msg->contact) < 0) {
LM_ERR("error while parsing Contact body\n");
return -1;
}
c = ((contact_body_t*)msg->contact->parsed)->contacts;
if (!c) {
LM_ERR("empty body or * contact\n");
return -2;
}
*uri = c->uri;
return 0;
}
示例8: encode_contact
//#define DEBUG
int
encode_contact (struct sip_msg *msg, char *encoding_prefix,char *public_ip)
{
contact_body_t *cb;
contact_t *c;
str uri;
str newUri;
int res;
char separator;
/*
* I have a list of contacts in contact->parsed which is of type contact_body_t
* inside i have a contact->parsed->contact which is the head of the list of contacts
* inside it is a
* str uri;
* struct contact *next;
* I just have to visit each uri and encode each uri according to a scheme
*/
if ((msg->contact == NULL)&&((parse_headers(msg,HDR_CONTACT_F,0) == -1) ||
(msg->contact == NULL) ))
{
LM_ERR("no Contact header present\n");
return -1;
}
separator = DEFAULT_SEPARATOR[0];
if (contact_flds_separator != NULL)
if (strlen(contact_flds_separator)>=1)
separator = contact_flds_separator[0];
if (msg->contact->parsed == NULL) parse_contact (msg->contact);
if (msg->contact->parsed != NULL)
{
cb = (contact_body_t *) msg->contact->parsed;
c = cb->contacts;
/* we visit each contact */
if (c != NULL)
{
uri = c->uri;
res = encode_uri (uri, encoding_prefix, public_ip,separator, &newUri);
if (res != 0)
{
LM_ERR("failed encoding contact.Code %d\n", res);
#ifdef STRICT_CHECK
return res;
#endif
}
else
if (patch (msg, uri.s, uri.len, newUri.s, newUri.len) < 0)
{
LM_ERR("lumping failed in mangling port \n");
return -2;
}
/* encoding next contacts too?*/
#ifdef ENCODE_ALL_CONTACTS
while (c->next != NULL)
{
c = c->next;
uri = c->uri;
res = encode_uri (uri, encoding_prefix,public_ip,separator,&newUri);
if (res != 0)
{
LM_ERR("failed encode_uri.Code %d\n",res);
#ifdef STRICT_CHECK
return res;
#endif
}
else
if (patch (msg, uri.s, uri.len, newUri.s, newUri.len)< 0)
{
LM_ERR("lumping failed in mangling port \n");
return -3;
}
} /* while */
#endif /* ENCODE_ALL_CONTACTS */
} /* if c != NULL */
} /* end if */
else /* after parsing still NULL */
{
LM_ERR("unable to parse Contact header\n");
return -4;
}
return 1;
}
示例9: decode_contact_header
int
decode_contact_header (struct sip_msg *msg,char *unused1,char *unused2)
{
contact_body_t *cb;
contact_t *c;
str uri;
str newUri;
char separator;
int res;
#ifdef DEBUG
str* ruri;
fprintf (stdout,"---START--------DECODE CONTACT HEADER-----------------\n");
#endif
if ((msg->contact == NULL)&&((parse_headers(msg,HDR_CONTACT_F,0) == -1) ||
(msg->contact== NULL) ))
{
LM_ERR("no Contact header present\n");
return -1;
}
separator = DEFAULT_SEPARATOR[0];
if (contact_flds_separator != NULL)
if (strlen(contact_flds_separator)>=1)
separator = contact_flds_separator[0];
#ifdef DEBUG
fprintf (stdout,"Using separator %c\n",separator);
ruri = GET_RURI(msg);
fprintf (stdout,"[len = %d]New uri is->%.*s\n",
ruri->len,ruri->len,ruri->s);
ruri = &msg->first_line.u.request.uri;
fprintf (stdout, "INITIAL.s=[%.*s]\n", ruri->len, ruri->s);
#endif
if (msg->contact->parsed == NULL) parse_contact (msg->contact);
if (msg->contact->parsed != NULL)
{
cb = (contact_body_t *) msg->contact->parsed;
c = cb->contacts;
// we visit each contact
if (c != NULL)
{
uri = c->uri;
res = decode_uri (uri, separator, &newUri);
#ifdef DEBUG
fprintf (stdout, "newuri.s=[%.*s]\n", newUri.len, newUri.s);
#endif
if (res != 0)
{
LM_ERR("failed decoding contact.Code %d\n", res);
#ifdef STRICT_CHECK
return res;
#endif
}
else
if (patch (msg, uri.s, uri.len, newUri.s, newUri.len) < 0)
{
LM_ERR("lumping failed in mangling port \n");
return -2;
}
#ifdef DECODE_ALL_CONTACTS
while (c->next != NULL)
{
c = c->next;
uri = c->uri;
res = decode_uri (uri, separator, &newUri);
if (res != 0)
{
LM_ERR("failed decoding contact.Code %d\n",res);
#ifdef STRICT_CHECK
return res;
#endif
}
else
if (patch (msg, uri.s, uri.len, newUri.s, newUri.len) < 0)
{
LM_ERR("lumping failed in mangling port \n");
return -3;
}
} // end while
#endif
} // if c!= NULL
} // end if
else // after parsing still NULL
{
LM_ERR("unable to parse Contact header\n");
return -4;
}
#ifdef DEBUG
fprintf (stdout,"---END--------DECODE CONTACT HEADER-----------------\n");fflush(stdout);
#endif
return 1;
}
示例10: subs_cback_func
//.........这里部分代码省略.........
if(hentity->desired_expires== 0)
subs.expires= -1;
else
if(hentity->desired_expires< (int)time(NULL))
subs.expires= 0;
else
subs.expires= hentity->desired_expires- (int)time(NULL)+ 3;
subs.flag= INSERT_TYPE;
subs.source_flag= flag;
subs.event= hentity->event;
subs.id= hentity->id;
subs.outbound_proxy= hentity->outbound_proxy;
subs.extra_headers= &hentity->extra_headers;
subs.cb_param= hentity->cb_param;
if(send_subscribe(&subs)< 0)
{
LM_ERR("when trying to send SUBSCRIBE\n");
goto done;
}
}
goto done;
}
/*if a 2XX reply handle the two cases- an existing dialog and a new one*/
/* extract the contact */
if(msg->contact== NULL || msg->contact->body.s== NULL)
{
LM_ERR("no contact header found");
goto error;
}
if( parse_contact(msg->contact) <0 )
{
LM_ERR(" cannot parse contact header\n");
goto error;
}
if(msg->contact->parsed == NULL)
{
LM_ERR("cannot parse contact header\n");
goto error;
}
contact = ((contact_body_t* )msg->contact->parsed)->contacts->uri;
if(!initial_request)
{
/* do not delete the dialog - allow Notifies to be recognized as
* inside a known dialog */
if (lexpire == 0)
lexpire = 5;
LM_DBG("*** Update expires\n");
update_htable(hentity->hash_index, hentity->local_index, lexpire, NULL, &contact);
goto done;
}
/* if a new dialog -> insert */
if(lexpire== 0)
{
LM_DBG("expires= 0: no not insert\n");
goto done;
}
if( msg->cseq==NULL || msg->cseq->body.s==NULL)
示例11: dlg_replace_contact
int dlg_replace_contact(struct sip_msg* msg, struct dlg_cell* dlg)
{
struct lump* lump, *crt, *prev_crt =0, *a, *foo;
int offset;
int len,n;
char *prefix=NULL,*suffix=NULL,*p,*p_init,*ct_username=NULL;
int prefix_len,suffix_len,ct_username_len=0;
struct sip_uri ctu;
str contact;
if(!msg->contact)
{
if(parse_headers(msg, HDR_CONTACT_F, 0)< 0)
{
LM_ERR("Failed to parse headers\n");
return -1;
}
if(!msg->contact)
return 0;
}
prefix_len = 5; /* <sip: */
if (dlg->flags & DLG_FLAG_TOPH_KEEP_USER) {
if ( parse_contact(msg->contact)<0 ||
((contact_body_t *)msg->contact->parsed)->contacts==NULL ||
((contact_body_t *)msg->contact->parsed)->contacts->next!=NULL ) {
LM_ERR("bad Contact HDR\n");
} else {
contact = ((contact_body_t *)msg->contact->parsed)->contacts->uri;
if(parse_uri(contact.s, contact.len, &ctu) < 0) {
LM_ERR("Bad Contact URI\n");
} else {
ct_username = ctu.user.s;
ct_username_len = ctu.user.len;
LM_DBG("Trying to propagate username [%.*s]\n",ct_username_len,
ct_username);
if (ct_username_len > 0)
prefix_len += 1 + /* @ */ + ct_username_len;
}
}
}
prefix = pkg_malloc(prefix_len);
if (!prefix) {
LM_ERR("no more pkg\n");
goto error;
}
suffix_len = RR_DLG_PARAM_SIZE+1; /* > */
suffix = pkg_malloc(suffix_len);
if (!suffix) {
LM_ERR("no more pkg\n");
goto error;
}
memcpy(prefix,"<sip:",prefix_len);
if (dlg->flags & DLG_FLAG_TOPH_KEEP_USER && ct_username_len > 0) {
memcpy(prefix+5,ct_username,ct_username_len);
prefix[prefix_len-1] = '@';
}
p_init = p = suffix;
*p++ = ';';
memcpy(p,rr_param.s,rr_param.len);
p+=rr_param.len;
*p++ = '=';
n = RR_DLG_PARAM_SIZE - (p-p_init);
if (int2reverse_hex( &p, &n, dlg->h_entry)==-1)
return -1;
*(p++) = DLG_SEPARATOR;
n = RR_DLG_PARAM_SIZE - (p-p_init);
if (int2reverse_hex( &p, &n, dlg->h_id)==-1)
return -1;
*p++ = '>';
suffix_len = p - p_init;
offset = msg->contact->body.s - msg->buf;
len = msg->contact->body.len;
for (crt = msg->add_rm;crt;) {
if (crt->type == HDR_CONTACT_T && crt->op == LUMP_DEL &&
crt->u.offset >= offset && crt->u.offset <= offset + len) {
lump = crt;
crt = crt->next;
a=lump->before;
while(a) {
LM_DBG("before [%p], op=%d\n", a, a->op);
if(a->op == LUMP_ADD)
LM_DBG("value= %.*s\n", a->len, a->u.value);
foo=a; a=a->before;
if (!(foo->flags&(LUMPFLAG_DUPED|LUMPFLAG_SHMEM)))
free_lump(foo);
if (!(foo->flags&LUMPFLAG_SHMEM))
pkg_free(foo);
}
//.........这里部分代码省略.........
示例12: reg_tm_cback
void reg_tm_cback(struct cell *t, int type, struct tmcb_params *ps)
{
struct sip_msg *msg;
reg_tm_cb_t *cb_param;
int statuscode = 0;
unsigned int exp = 0;
reg_record_t *rec;
struct hdr_field *c_ptr, *head_contact;
struct uac_credential crd;
contact_t *contact;
struct authenticate_body *auth = NULL;
static struct authenticate_nc_cnonce auth_nc_cnonce;
HASHHEX response;
str *new_hdr;
time_t now;
if(ps==NULL || ps->rpl==NULL) {
LM_ERR("wrong ps parameter\n");
return;
}
if(ps->param==NULL || *ps->param==NULL) {
LM_ERR("null callback parameter\n");
return;
}
cb_param = (reg_tm_cb_t *)*ps->param;
if(cb_param->uac == NULL) {
LM_ERR("null record\n");
return;
}
statuscode = ps->code;
now = time(0);
LM_DBG("tm [%p] notification cb for %s [%d] reply at [%d]\n",
t, (ps->rpl==FAKED_REPLY)?"FAKED_REPLY":"", statuscode, (unsigned int)now);
if(statuscode<200) return;
lock_get(®_htable[cb_param->hash_index].lock);
rec = reg_htable[cb_param->hash_index].first;
while(rec) {
if (rec==cb_param->uac) {
break;
}
rec = rec->next;
}
if(!rec) {
LM_ERR("record [%p] not found on hash index [%d]\n",
cb_param->uac, cb_param->hash_index);
lock_release(®_htable[cb_param->hash_index].lock);
return;
}
reg_print_record(rec);
switch(statuscode) {
case 200:
msg = ps->rpl;
if(msg==FAKED_REPLY) {
LM_ERR("FAKED_REPLY\n");
goto done;
}
if (parse_headers(msg, HDR_EOH_F, 0) == -1) {
LM_ERR("failed to parse headers\n");
goto done;
}
if (msg->contact) {
c_ptr = msg->contact;
while(c_ptr) {
if (c_ptr->type == HDR_CONTACT_T) {
if (!c_ptr->parsed && (parse_contact(c_ptr)<0)) {
LM_ERR("failed to parse Contact body\n");
goto done;
}
}
c_ptr = c_ptr->next;
}
} else {
LM_ERR("No contact header in received 200ok\n");
goto done;
}
head_contact = msg->contact;
contact = ((contact_body_t*)msg->contact->parsed)->contacts;
while (contact) {
/* Check for binding */
if (contact->uri.len==rec->contact_uri.len &&
strncmp(contact->uri.s,rec->contact_uri.s,contact->uri.len)==0){
if (contact->expires && contact->expires->body.len) {
if (str2int(&contact->expires->body, &exp)<0) {
LM_ERR("Unable to extract expires from [%.*s]"
" for binding [%.*s]\n",
contact->expires->body.len,
contact->expires->body.s,
contact->uri.len, contact->uri.s);
} else {
rec->expires = exp;
}
}
break;
}
/* get the next contact */
if (contact->next == NULL) {
//.........这里部分代码省略.........
示例13: l_siplua_getContact
static int l_siplua_getContact(lua_State *L)
{
struct sipapi_object *o;
struct hdr_field *_p;
contact_t *_c;
int n = 1;
int found_hf_no_star = 0;
int found_hf_star = 0;
int expires;
o = luaL_checkudata(L, 1, "siplua.api");
if (!o->msg->contact)
{
lua_pushnil(L);
return 1;
}
lua_newtable(L);
_p = o->msg->contact;
for (_p = o->msg->contact; _p; _p = _p->next)
{
/* siplua_log(L_DBG, "l_siplua_getContact _p/%p", _p); */
if (_p->type == HDR_CONTACT_T)
{
if (parse_contact(_p) < 0)
{
return luaL_error(L, "failed to parse Contact body");
}
if (((contact_body_t *)_p->parsed)->star)
{
lua_pushinteger(L, n++);
lua_newtable(L);
lua_pushstring(L, "star");
lua_pushboolean(L, 1);
lua_rawset(L, -3);
lua_pushstring(L, "name");
lua_pushstring(L, "*");
lua_rawset(L, -3);
lua_pushstring(L, "uri");
lua_pushstring(L, "*");
lua_rawset(L, -3);
lua_rawset(L, -3);
found_hf_star = 1;
}
for (_c = ((contact_body_t *)_p->parsed)->contacts; _c; _c = _c->next)
{
/* siplua_log(L_DBG, "l_siplua_getContact _c/%p", _c); */
if (!_c)
break;
lua_pushinteger(L, n++);
lua_newtable(L);
lua_pushstring(L, "name");
lua_pushlstring(L, _c->name.s, _c->name.len);
lua_rawset(L, -3);
lua_pushstring(L, "uri");
lua_pushlstring(L, _c->uri.s, _c->uri.len);
lua_rawset(L, -3);
/* siplua_log(L_DBG, "contact q/%p expires/%p", _c->q, _c->expires); */
if (_c->q)
{
lua_pushstring(L, "q");
lua_pushlstring(L, _c->q->body.s, _c->q->body.len);
lua_pushnumber(L, lua_tonumber(L, -1));
lua_remove(L, -2);
lua_rawset(L, -3);
}
if (_c->expires)
{
lua_pushstring(L, "expires");
lua_pushlstring(L, _c->expires->body.s, _c->expires->body.len);
lua_pushnumber(L, lua_tonumber(L, -1));
lua_remove(L, -2);
lua_rawset(L, -3);
}
lua_rawset(L, -3);
found_hf_no_star = 1;
}
}
}
if (found_hf_star)
{
if (found_hf_no_star)
{
lua_remove(L, -1);
lua_pushnil(L);
siplua_log(L_DBG, "l_siplua_getContact Found Contact HF with both star and no star.");
}
else
{
/* siplua_log(L_DBG, "BEFORE"); */
expires = sipapi_getExpires(o->msg);
/* siplua_log(L_DBG, "AFTER"); */
if (expires != 0 && expires != -1)
{
lua_remove(L, -1);
lua_pushnil(L);
siplua_log(L_DBG, "l_siplua_getContact Found Contact HF star with unvalid expires.");
}
}
}
/* siplua_log(L_DBG, "l_siplua_getContact returned."); */
//.........这里部分代码省略.........
示例14: shmcontact2dset
/* returns : -1 - error
* 0 - ok, but no contact added
* n - ok and n contacts added
*/
static int shmcontact2dset(struct sip_msg *req, struct sip_msg *sh_rpl,
long max, struct acc_param *reason, unsigned int bflags)
{
static struct sip_msg dup_rpl;
static contact_t *scontacts[MAX_CONTACTS_PER_REPLY];
static qvalue_t sqvalues[MAX_CONTACTS_PER_REPLY];
struct hdr_field *hdr;
struct hdr_field *contact_hdr;
contact_t *contacts;
int n,i;
int added;
int dup;
int ret;
/* dup can be:
* 0 - sh reply but nothing duplicated
* 1 - sh reply but only contact body parsed
* 2 - sh reply and contact header and body parsed
* 3 - private reply
*/
dup = 0; /* sh_rpl not duplicated */
ret = 0; /* success and no contact added */
contact_hdr = 0;
if (sh_rpl==0 || sh_rpl==FAKED_REPLY)
return 0;
if (sh_rpl->contact==0) {
/* contact header is not parsed */
if ( sh_rpl->msg_flags&FL_SHM_CLONE ) {
/* duplicate the reply into private memory to be able
* to parse it and afterwards to free the parsed mems */
memcpy( &dup_rpl, sh_rpl, sizeof(struct sip_msg) );
dup = 2;
/* ok -> force the parsing of contact header */
if ( parse_headers( &dup_rpl, HDR_EOH_F, 0)<0 ) {
LM_ERR("dup_rpl parse failed\n");
ret = -1;
goto restore;
}
if (dup_rpl.contact==0) {
LM_DBG("contact hdr not found in dup_rpl\n");
goto restore;
}
contact_hdr = dup_rpl.contact;
} else {
dup = 3;
/* force the parsing of contact header */
if ( parse_headers( sh_rpl, HDR_EOH_F, 0)<0 ) {
LM_ERR("sh_rpl parse failed\n");
ret = -1;
goto restore;
}
if (sh_rpl->contact==0) {
LM_DBG("contact hdr not found in sh_rpl\n");
goto restore;
}
contact_hdr = sh_rpl->contact;
}
} else {
contact_hdr = sh_rpl->contact;
}
/* parse the body of contact headers */
hdr = contact_hdr;
while(hdr) {
if (hdr->type == HDR_CONTACT_T) {
if (hdr->parsed==0) {
if(parse_contact(hdr) < 0) {
LM_ERR("failed to parse Contact body\n");
ret = -1;
goto restore;
}
if (dup==0)
dup = 1;
}
}
hdr = hdr->next;
}
/* we have the contact header and its body parsed -> sort the contacts
* based on the q value */
contacts = ((contact_body_t*)contact_hdr->parsed)->contacts;
if (contacts==0) {
LM_DBG("contact hdr has no contacts\n");
goto restore;
}
n = sort_contacts(contact_hdr, scontacts, sqvalues);
if (n==0) {
LM_DBG("no contacts left after filtering\n");
goto restore;
}
i=0;
/* more branches than requested in the parameter
//.........这里部分代码省略.........
示例15: encode_header
/*
* This function encodes an arbitrary header into a chunk of bytes,
* ready to be sent to the Application Server.
*
* The header codes start with this encoded-bytes:
* 2: SIP-MSG-START based pointer to the header (including header name)
* 2: length of the header
* 1: length of the header name
*/
int encode_header(struct sip_msg *sipmsg,struct hdr_field *hdr,unsigned char *payload,int paylen)
{
int len=0;
unsigned int integer,*methods=0;
char *hdrstart,*tmp;
unsigned short int ptr;
struct to_body *tobody=0;
struct via_body *viabody=0;
struct cseq_body *cseqbody=0;
char *msg,*myerror;
int mlen;
msg=sipmsg->buf;
mlen=sipmsg->len;
hdrstart = hdr->name.s;
if(hdrstart-msg<0){
LM_ERR("header(%.*s) does not belong to sip_msg(hdrstart<msg)\n",
hdr->name.len,hdr->name.s);
return -1;
}
ptr=htons((short int)(hdrstart-msg));
if((hdrstart-msg)>mlen){
LM_ERR("out of the sip_msg bounds (%d>%d)\n",ntohs(ptr),mlen);
return -1;
}
if(hdr->len>(1<<16)){
LM_ERR("length of header too long\n");
return -1;
}
memcpy(payload,&ptr,2);
ptr=htons((short int)(hdr->len));
memcpy(payload+HEADER_LEN_IDX,&ptr,2);
payload[HEADER_NAME_LEN_IDX]=(unsigned char)hdr->name.len;
switch(hdr->type){
case HDR_FROM_T:
case HDR_TO_T:
case HDR_REFER_TO_T:
case HDR_RPID_T:
if(!hdr->parsed){
if((tobody=pkg_malloc(sizeof(struct to_body)))==0){
myerror="Out of memory !!\n";
goto error;
}
parse_to(hdr->body.s,hdr->body.s+hdr->body.len+1,tobody);
if (tobody->error == PARSE_ERROR) {
myerror="bad (REFER,TO,FROM,RPID) header\n";
pkg_free(tobody);
return 5;
goto error;
}
hdr->parsed=(struct to_body*)tobody;
}else
tobody=(struct to_body*)hdr->parsed;
if((len=encode_to_body(hdr->name.s,hdr->len,tobody,payload+5))<0){
myerror="parsing from or to header\n";
goto error;
}else{
return 5+len;
}
break;
case HDR_CONTACT_T:
if(!hdr->parsed)
if(parse_contact(hdr)<0){
myerror="parsing contact\n";
goto error;
}
if((len=encode_contact_body(hdr->name.s,hdr->len,(contact_body_t*)hdr->parsed,payload+5))<0){
myerror="encoding contact header\n";
goto error;
}else{
return 5+len;
}
break;
case HDR_ROUTE_T:
case HDR_RECORDROUTE_T:
if(!hdr->parsed)
if(parse_rr(hdr)<0){
myerror="encoding route or recordroute\n";
goto error;
}
if((len=encode_route_body(hdr->name.s,hdr->len,(rr_t*)hdr->parsed,payload+5))<0){
myerror="encoding route or recordroute header\n";
goto error;
}else{
return 5+len;
}
break;
case HDR_CONTENTLENGTH_T:
if(!hdr->parsed){
tmp=parse_content_length(hdr->body.s,hdr->body.s+hdr->body.len+1,(int*)&integer);
if (tmp==0){
//.........这里部分代码省略.........