本文整理汇总了C++中parse_from_header函数的典型用法代码示例。如果您正苦于以下问题:C++ parse_from_header函数的具体用法?C++ parse_from_header怎么用?C++ parse_from_header使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse_from_header函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: match_res
/*
* Matches from uri against patterns returned from database. Returns number
* of matches or -1 if none of the patterns match.
*/
static int match_res(struct sip_msg* msg, int proto, db1_res_t* _r)
{
int i, tag_avp_type;
str uri;
char uri_string[MAX_URI_SIZE+1];
db_row_t* row;
db_val_t* val;
regex_t preg;
int_str tag_avp, avp_val;
int count = 0;
if (IS_SIP(msg)) {
if (parse_from_header(msg) < 0) return -1;
uri = get_from(msg)->uri;
if (uri.len > MAX_URI_SIZE) {
LM_ERR("message has From URI too large\n");
return -1;
}
memcpy(uri_string, uri.s, uri.len);
uri_string[uri.len] = (char)0;
}
get_tag_avp(&tag_avp, &tag_avp_type);
row = RES_ROWS(_r);
for(i = 0; i < RES_ROW_N(_r); i++) {
val = ROW_VALUES(row + i);
if ((ROW_N(row + i) == 3) &&
(VAL_TYPE(val) == DB1_STRING) && !VAL_NULL(val) &&
match_proto(VAL_STRING(val), proto) &&
(VAL_NULL(val + 1) ||
((VAL_TYPE(val + 1) == DB1_STRING) && !VAL_NULL(val + 1))) &&
(VAL_NULL(val + 2) ||
((VAL_TYPE(val + 2) == DB1_STRING) && !VAL_NULL(val + 2))))
{
if (!VAL_NULL(val + 1) && IS_SIP(msg)) {
if (regcomp(&preg, (char *)VAL_STRING(val + 1), REG_NOSUB)) {
LM_ERR("invalid regular expression\n");
continue;
}
if (regexec(&preg, uri_string, 0, (regmatch_t *)0, 0)) {
regfree(&preg);
continue;
}
regfree(&preg);
}
/* Found a match */
if (tag_avp.n && !VAL_NULL(val + 2)) {
avp_val.s.s = (char *)VAL_STRING(val + 2);
avp_val.s.len = strlen(avp_val.s.s);
if (add_avp(tag_avp_type|AVP_VAL_STR, tag_avp, avp_val) != 0) {
LM_ERR("failed to set of tag_avp failed\n");
return -1;
}
}
if (!peer_tag_mode)
return 1;
count++;
}
}
if (!count)
return -1;
else
return count;
}
示例2: record_route_preset
/*! \brief
* Insert manually created Record-Route header, no checks, no restrictions,
* always adds lr parameter, only fromtag is added automatically when requested
*/
int record_route_preset(struct sip_msg* _m, str* _data)
{
str user;
struct to_body* from;
struct lump* l, *lp, *ap;
struct lump* l2;
char *hdr, *suffix, *p, *term;
int hdr_len, suffix_len;
from = 0;
user.len = 0;
user.s = 0;
if (add_username) {
if (get_username(_m, &user) < 0) {
LM_ERR("failed to extract username\n");
return -1;
}
}
if (append_fromtag) {
if (parse_from_header(_m) < 0) {
LM_ERR("From parsing failed\n");
return -2;
}
from = (struct to_body*)_m->from->parsed;
}
hdr_len = RR_PREFIX_LEN;
if (user.len)
hdr_len += user.len + 1; /* @ */
hdr_len += _data->len;
suffix_len = 0;
if (append_fromtag && from->tag_value.len) {
suffix_len += RR_FROMTAG_LEN + from->tag_value.len;
}
suffix_len += RR_LR_LEN;
hdr = pkg_malloc(hdr_len);
term = pkg_malloc(RR_TERM_LEN);
suffix = pkg_malloc(suffix_len);
if (!hdr || !term || !suffix) {
LM_ERR("no pkg memory left\n");
return -4;
}
/* header */
p = hdr;
memcpy(p, RR_PREFIX, RR_PREFIX_LEN);
p += RR_PREFIX_LEN;
if (user.len) {
memcpy(p, user.s, user.len);
p += user.len;
*p = '@';
p++;
}
memcpy(p, _data->s, _data->len);
p += _data->len;
/*suffix*/
p = suffix;
if (append_fromtag && from->tag_value.len) {
memcpy(p, RR_FROMTAG, RR_FROMTAG_LEN);
p += RR_FROMTAG_LEN;
memcpy(p, from->tag_value.s, from->tag_value.len);
p += from->tag_value.len;
}
memcpy(p, RR_LR, RR_LR_LEN);
p += RR_LR_LEN;
memcpy(term, RR_TERM, RR_TERM_LEN);
l = anchor_lump(_m, _m->headers->name.s - _m->buf, HDR_RECORDROUTE_T);
l2 = anchor_lump(_m, _m->headers->name.s - _m->buf, HDR_RECORDROUTE_T);
if (!l || !l2) {
LM_ERR("failed to create lump anchor\n");
goto error;
}
if (!(l=insert_new_lump_after(l, hdr, hdr_len, 0))) {
LM_ERR("failed to insert new lump\n");
goto error;
}
hdr = NULL;
l2 = insert_new_lump_before(l2, suffix, suffix_len, HDR_RECORDROUTE_T);
if (l2==NULL) {
LM_ERR("failed to insert suffix lump\n");
goto error;
}
suffix = NULL;
//.........这里部分代码省略.........
示例3: siprec_start_rec
/*
* function that simply prints the parameters passed
*/
static int siprec_start_rec(struct sip_msg *msg, str *srs, str *group,
str *_cA, str *_cB, str *rtp, str *m_ip)
{
int ret;
str *aor, *display, *xml_val;
struct src_sess *ss;
struct dlg_cell *dlg;
/* create the dialog, if does not exist yet */
dlg = srec_dlg.get_dlg();
if (!dlg) {
if (srec_dlg.create_dlg(msg, 0) < 0) {
LM_ERR("cannot create dialog!\n");
return -2;
}
dlg = srec_dlg.get_dlg();
}
/* XXX: if there is a forced send socket in the message, use it
* this is the only way to provide a different socket for SRS, but
* we might need to take a different approach */
/* check if the current dialog has a siprec session ongoing */
if (!(ss = src_new_session(srs, rtp, m_ip, group, msg->force_send_socket))) {
LM_ERR("cannot create siprec session!\n");
return -2;
}
/* we ref the dialog to make sure it does not dissapear until we receive
* the reply from the SRS */
srec_dlg.ref_dlg(dlg, 1);
ss->dlg = dlg;
ret = -2;
/* caller info */
if (_cA) {
xml_val = _cA;
display = aor = NULL;
} else {
if (parse_from_header(msg) < 0) {
LM_ERR("cannot parse from header!\n");
goto session_cleanup;
}
aor = &get_from(msg)->uri;
display = (get_from(msg)->display.s ? &get_from(msg)->display : NULL);
xml_val = NULL;
}
if (src_add_participant(ss, aor, display, xml_val, NULL) < 0) {
LM_ERR("cannot add caller participant!\n");
goto session_cleanup;
}
if (srs_fill_sdp_stream(msg, ss, &ss->participants[0], 0) < 0) {
LM_ERR("cannot add SDP for caller!\n");
goto session_cleanup;
}
/* caller info */
if (_cB) {
xml_val = _cB;
} else {
if ((!msg->to && parse_headers(msg, HDR_TO_F, 0) < 0) || !msg->to) {
LM_ERR("inexisting or invalid to header!\n");
goto session_cleanup;
}
aor = &get_to(msg)->uri;
display = (get_to(msg)->display.s ? &get_to(msg)->display : NULL);
xml_val = NULL;
}
if (src_add_participant(ss, aor, display, xml_val, NULL) < 0) {
LM_ERR("cannot add callee pariticipant!\n");
goto session_cleanup;
}
SIPREC_REF_UNSAFE(ss);
if (srec_tm.register_tmcb(msg, 0, TMCB_RESPONSE_OUT, tm_start_recording,
ss, src_unref_session) <= 0) {
LM_ERR("cannot register tm callbacks\n");
SIPREC_UNREF_UNSAFE(ss);
goto session_cleanup;
}
return 1;
session_cleanup:
src_free_session(ss);
return ret;
}
示例4: dlg_bridge_tm_callback
void dlg_bridge_tm_callback(struct cell *t, int type, struct tmcb_params *ps)
{
struct sip_msg *msg = NULL;
dlg_transfer_ctx_t *dtc = NULL;
struct dlg_cell *dlg = NULL;
str s;
str cseq;
str empty = {"", 0};
if(ps->param==NULL || *ps->param==0)
{
LM_DBG("message id not received\n");
return;
}
dtc = *((dlg_transfer_ctx_t**)ps->param);
if(dtc==NULL)
return;
LM_DBG("completed with status %d\n", ps->code);
if(ps->code>=300)
goto error;
/* 2xx - build dialog/send refer */
msg = ps->rpl;
if((msg->cseq==NULL || parse_headers(msg,HDR_CSEQ_F,0)<0)
|| msg->cseq==NULL || msg->cseq->parsed==NULL)
{
LM_ERR("bad sip message or missing CSeq hdr :-/\n");
goto error;
}
cseq = (get_cseq(msg))->number;
if((msg->to==NULL && parse_headers(msg, HDR_TO_F,0)<0) || msg->to==NULL)
{
LM_ERR("bad request or missing TO hdr\n");
goto error;
}
if(parse_from_header(msg))
{
LM_ERR("bad request or missing FROM hdr\n");
goto error;
}
if((msg->callid==NULL && parse_headers(msg,HDR_CALLID_F,0)<0)
|| msg->callid==NULL){
LM_ERR("bad request or missing CALLID hdr\n");
goto error;
}
s = msg->callid->body;
trim(&s);
/* some sanity checks */
if (s.len==0 || get_from(msg)->tag_value.len==0) {
LM_ERR("invalid request -> callid (%d) or from TAG (%d) empty\n",
s.len, get_from(msg)->tag_value.len);
goto error;
}
dlg = build_new_dlg(&s /*callid*/, &(get_from(msg)->uri) /*from uri*/,
&(get_to(msg)->uri) /*to uri*/,
&(get_from(msg)->tag_value)/*from_tag*/,
&(get_to(msg)->uri) /*use to as r-uri*/ );
if (dlg==0) {
LM_ERR("failed to create new dialog\n");
goto error;
}
dtc->dlg = dlg;
if (dlg_set_leg_info(dlg, &(get_from(msg)->tag_value),
&empty, &dlg_bridge_controller, &cseq, DLG_CALLER_LEG)!=0) {
LM_ERR("dlg_set_leg_info failed\n");
goto error;
}
if (populate_leg_info(dlg, msg, t, DLG_CALLEE_LEG,
&(get_to(msg)->tag_value)) !=0)
{
LM_ERR("could not add further info to the dialog\n");
shm_free(dlg);
goto error;
}
if(dlg_refer_callee(dtc)!=0)
goto error;
return;
error:
dlg_transfer_ctx_free(dtc);
return;
}
示例5: rls_handle_notify
int rls_handle_notify(struct sip_msg* msg, char* c1, char* c2)
{
struct to_body *pto, TO = {0}, *pfrom = NULL;
str body= {0, 0};
ua_pres_t dialog;
str* res_id= NULL;
db_key_t query_cols[8];
db_val_t query_vals[8];
int n_query_cols= 0;
str auth_state= {0, 0};
int found= 0;
str reason = {0, 0};
int auth_flag;
struct hdr_field* hdr= NULL;
int expires= -1;
str content_type= {0, 0};
int reply_code = 500;
str reply_str = pu_500_rpl;
LM_DBG("start\n");
/* extract the dialog information and check if an existing dialog*/
if( parse_headers(msg,HDR_EOH_F, 0)==-1 )
{
LM_ERR("parsing headers\n");
reply_code = 400;
reply_str = pu_400_rpl;
goto error;
}
if((!msg->event ) ||(msg->event->body.len<=0))
{
LM_ERR("Missing event header field value\n");
reply_code = 400;
reply_str = pu_400_rpl;
goto error;
}
if( msg->to==NULL || msg->to->body.s==NULL)
{
LM_ERR("cannot parse TO header\n");
reply_code = 400;
reply_str = pu_400_rpl;
goto error;
}
if(msg->to->parsed != NULL)
{
pto = (struct to_body*)msg->to->parsed;
LM_DBG("'To' header ALREADY PARSED: <%.*s>\n",
pto->uri.len, pto->uri.s );
}
else
{
parse_to(msg->to->body.s,msg->to->body.s + msg->to->body.len + 1, &TO);
if(TO.uri.len <= 0)
{
LM_ERR(" 'To' header NOT parsed\n");
reply_code = 400;
reply_str = pu_400_rpl;
goto error;
}
pto = &TO;
}
memset(&dialog, 0, sizeof(ua_pres_t));
dialog.watcher_uri= &pto->uri;
if (pto->tag_value.s==NULL || pto->tag_value.len==0 )
{
LM_ERR("to tag value not parsed\n");
reply_code = 400;
reply_str = pu_400_rpl;
goto error;
}
dialog.from_tag= pto->tag_value;
if( msg->callid==NULL || msg->callid->body.s==NULL)
{
LM_ERR("cannot parse callid header\n");
reply_code = 400;
reply_str = pu_400_rpl;
goto error;
}
dialog.call_id = msg->callid->body;
if (!msg->from || !msg->from->body.s)
{
LM_ERR("cannot find 'from' header!\n");
reply_code = 400;
reply_str = pu_400_rpl;
goto error;
}
if (msg->from->parsed == NULL)
{
LM_DBG("'From' header not parsed\n");
/* parsing from header */
if ( parse_from_header( msg )<0 )
{
LM_ERR("cannot parse From header\n");
reply_code = 400;
reply_str = pu_400_rpl;
goto error;
}
}
pfrom = (struct to_body*)msg->from->parsed;
dialog.pres_uri= &pfrom->uri;
//.........这里部分代码省略.........
示例6: xjab_manage_sipmsg
/**
* manage SIP message
*/
int xjab_manage_sipmsg(struct sip_msg *msg, int type)
{
str body, dst, from_uri;
xj_sipmsg jsmsg;
int pipe, fl;
t_xj_jkey jkey, *p;
int mime;
body.len = 0;
body.s = 0;
// extract message body - after that whole SIP MESSAGE is parsed
if (type==XJ_SEND_MESSAGE)
{
/* get the message's body */
body.s = get_body( msg );
if(body.s==0)
{
LM_ERR("cannot extract body from msg\n");
goto error;
}
/* content-length (if present) must be already parsed */
if(!msg->content_length)
{
LM_ERR("no Content-Length header found!\n");
goto error;
}
body.len = get_content_length(msg);
/* parse the content-type header */
if((mime=parse_content_type_hdr(msg))<1)
{
LM_ERR("cannot parse Content-Type header\n");
goto error;
}
/* check the content-type value */
if(mime!=(TYPE_TEXT<<16)+SUBTYPE_PLAIN
&& mime!=(TYPE_MESSAGE<<16)+SUBTYPE_CPIM)
{
LM_ERR("invalid content-type for"
" a message request! type found=%d\n", mime);
goto error;
}
}
// check for TO and FROM headers - if is not SIP MESSAGE
if(parse_headers(msg,HDR_TO_F|HDR_FROM_F,0)==-1 || !msg->to || !msg->from)
{
LM_ERR("cannot find TO or FROM HEADERS!\n");
goto error;
}
/* parsing from header */
if ( parse_from_header( msg )<0 || msg->from->parsed==NULL)
{
LM_DBG("cannot get FROM header\n");
goto error;
}
from_uri.s = ((struct to_body*)msg->from->parsed)->uri.s;
from_uri.len = ((struct to_body*)msg->from->parsed)->uri.len;
if(xj_extract_aor(&from_uri, 0))
{
LM_DBG("cannot get AoR from FROM header\n");
goto error;
}
jkey.hash = xj_get_hash(&from_uri, NULL);
jkey.id = &from_uri;
// get the communication pipe with the worker
switch(type)
{
case XJ_SEND_MESSAGE:
case XJ_JOIN_JCONF:
case XJ_GO_ONLINE:
if((pipe = xj_wlist_get(jwl, &jkey, &p)) < 0)
{
LM_DBG("cannot find pipe of the worker!\n");
goto error;
}
break;
case XJ_EXIT_JCONF:
case XJ_GO_OFFLINE:
if((pipe = xj_wlist_check(jwl, &jkey, &p)) < 0)
{
LM_DBG("no open Jabber session for"
" <%.*s>!\n", from_uri.len, from_uri.s);
goto error;
}
break;
default:
LM_DBG("ERROR:strange SIP msg type!\n");
goto error;
}
// if is for going ONLINE/OFFLINE we do not need the destination
//.........这里部分代码省略.........
示例7: allow_uri
/*
* determines the permission to an uri
* return values:
* -1: deny
* 1: allow
*/
static int allow_uri(struct sip_msg* msg, char* _idx, char* _sp)
{
struct hdr_field *from;
int idx, len;
static char from_str[EXPRESSION_LENGTH+1];
static char uri_str[EXPRESSION_LENGTH+1];
pv_spec_t *sp;
pv_value_t pv_val;
idx = (int)(long)_idx;
sp = (pv_spec_t *)_sp;
/* turn off control, allow any uri */
if ((!allow[idx].rules) && (!deny[idx].rules)) {
LM_DBG("no rules => allow any uri\n");
return 1;
}
/* looking for FROM HF */
if ((!msg->from) && (parse_headers(msg, HDR_FROM_F, 0) == -1)) {
LM_ERR("failed to parse message\n");
return -1;
}
if (!msg->from) {
LM_ERR("FROM header field not found\n");
return -1;
}
/* we must call parse_from_header explicitly */
if ((!(msg->from)->parsed) && (parse_from_header(msg) < 0)) {
LM_ERR("failed to parse From body\n");
return -1;
}
from = msg->from;
len = ((struct to_body*)from->parsed)->uri.len;
if (len > EXPRESSION_LENGTH) {
LM_ERR("From header field is too long: %d chars\n", len);
return -1;
}
strncpy(from_str, ((struct to_body*)from->parsed)->uri.s, len);
from_str[len] = '\0';
if (sp && (pv_get_spec_value(msg, sp, &pv_val) == 0)) {
if (pv_val.flags & PV_VAL_STR) {
if (pv_val.rs.len > EXPRESSION_LENGTH) {
LM_ERR("pseudo variable value is too "
"long: %d chars\n", pv_val.rs.len);
return -1;
}
strncpy(uri_str, pv_val.rs.s, pv_val.rs.len);
uri_str[pv_val.rs.len] = '\0';
} else {
LM_ERR("pseudo variable value is not string\n");
return -1;
}
} else {
LM_ERR("cannot get pseudo variable value\n");
return -1;
}
LM_DBG("looking for From: %s URI: %s\n", from_str, uri_str);
/* rule exists in allow file */
if (search_rule(allow[idx].rules, from_str, uri_str)) {
LM_DBG("allow rule found => URI is allowed\n");
return 1;
}
/* rule exists in deny file */
if (search_rule(deny[idx].rules, from_str, uri_str)) {
LM_DBG("deny rule found => URI is denied\n");
return -1;
}
LM_DBG("neither allow nor deny rule found => URI is allowed\n");
return 1;
}
示例8: sip_trace
static int sip_trace(struct sip_msg *msg, char *s1, char *s2)
{
db_key_t db_keys[NR_KEYS];
db_val_t db_vals[NR_KEYS];
static char toip_buff[IP_ADDR_MAX_STR_SIZE+6];
static char fromip_buff[IP_ADDR_MAX_STR_SIZE+6];
int_str avp_value;
struct usr_avp *avp;
if(msg==NULL)
{
LM_DBG("no uas request, local transaction\n");
return -1;
}
avp = NULL;
if(traced_user_avp.n!=0)
avp=search_first_avp(traced_user_avp_type, traced_user_avp,
&avp_value, 0);
if((avp==NULL) && (trace_on_flag==NULL || *trace_on_flag==0))
{
LM_DBG("trace off...\n");
return -1;
}
if(parse_from_header(msg)==-1 || msg->from==NULL || get_from(msg)==NULL)
{
LM_ERR("cannot parse FROM header\n");
goto error;
}
if(parse_headers(msg, HDR_CALLID_F, 0)!=0 || msg->callid==NULL
|| msg->callid->body.s==NULL)
{
LM_ERR("cannot parse call-id\n");
goto error;
}
db_keys[0] = msg_column;
db_vals[0].type = DB_BLOB;
db_vals[0].nul = 0;
db_vals[0].val.blob_val.s = msg->buf;
db_vals[0].val.blob_val.len = msg->len;
db_keys[1] = callid_column;
db_vals[1].type = DB_STR;
db_vals[1].nul = 0;
db_vals[1].val.str_val.s = msg->callid->body.s;
db_vals[1].val.str_val.len = msg->callid->body.len;
db_keys[2] = method_column;
db_vals[2].type = DB_STR;
db_vals[2].nul = 0;
if(msg->first_line.type==SIP_REQUEST)
{
db_vals[2].val.str_val.s = msg->first_line.u.request.method.s;
db_vals[2].val.str_val.len = msg->first_line.u.request.method.len;
} else {
db_vals[2].val.str_val.s = "";
db_vals[2].val.str_val.len = 0;
}
db_keys[3] = status_column;
db_vals[3].type = DB_STR;
db_vals[3].nul = 0;
if(msg->first_line.type==SIP_REPLY)
{
db_vals[3].val.str_val.s = msg->first_line.u.reply.status.s;
db_vals[3].val.str_val.len = msg->first_line.u.reply.status.len;
} else {
db_vals[3].val.str_val.s = "";
db_vals[3].val.str_val.len = 0;
}
db_keys[4] = fromip_column;
db_vals[4].type = DB_STRING;
db_vals[4].nul = 0;
siptrace_copy_proto(msg->rcv.proto, fromip_buff);
strcat(fromip_buff, ip_addr2a(&msg->rcv.src_ip));
strcat(fromip_buff,":");
strcat(fromip_buff, int2str(msg->rcv.src_port, NULL));
db_vals[4].val.string_val = fromip_buff;
db_keys[5] = toip_column;
db_vals[5].type = DB_STRING;
db_vals[5].nul = 0;
// db_vals[5].val.string_val = ip_addr2a(&msg->rcv.dst_ip);;
siptrace_copy_proto(msg->rcv.proto, toip_buff);
strcat(toip_buff, ip_addr2a(&msg->rcv.dst_ip));
strcat(toip_buff,":");
strcat(toip_buff, int2str(msg->rcv.dst_port, NULL));
db_vals[5].val.string_val = toip_buff;
db_keys[6] = date_column;
db_vals[6].type = DB_DATETIME;
db_vals[6].nul = 0;
db_vals[6].val.time_val = time(NULL);
db_keys[7] = direction_column;
//.........这里部分代码省略.........
示例9: trace_onreq_in
static void trace_onreq_in(struct cell* t, int type, struct tmcb_params *ps)
{
struct sip_msg* msg;
int_str avp_value;
struct usr_avp *avp;
if(t==NULL || ps==NULL)
{
LM_DBG("no uas request, local transaction\n");
return;
}
msg = ps->req;
if(msg==NULL)
{
LM_DBG("no uas request, local transaction\n");
return;
}
avp = NULL;
if(traced_user_avp.n!=0)
avp=search_first_avp(traced_user_avp_type, traced_user_avp,
&avp_value, 0);
if((avp==NULL) && trace_is_off(msg))
{
LM_DBG("trace off...\n");
return;
}
if(parse_from_header(msg)==-1 || msg->from==NULL || get_from(msg)==NULL)
{
LM_ERR("cannot parse FROM header\n");
return;
}
if(parse_headers(msg, HDR_CALLID_F, 0)!=0)
{
LM_ERR("cannot parse call-id\n");
return;
}
if (msg->REQ_METHOD==METHOD_INVITE)
{
LM_DBG("noisy_timer set for tracing\n");
t->flags |= T_NOISY_CTIMER_FLAG;
}
if(tmb.register_tmcb( 0, t, TMCB_REQUEST_BUILT, trace_onreq_out, 0) <=0)
{
LM_ERR("can't register trace_onreq_out\n");
return;
}
if(tmb.register_tmcb( 0, t, TMCB_RESPONSE_IN, trace_onreply_in, 0) <=0)
{
LM_ERR("can't register trace_onreply_in\n");
return;
}
if(tmb.register_tmcb( 0, t, TMCB_RESPONSE_OUT, trace_onreply_out, 0) <=0)
{
LM_ERR("can't register trace_onreply_out\n");
return;
}
}
示例10: get_subs_cell
/* look for subscriber cell using callid and to_tag of Notify*/
struct sm_subscriber* get_subs_cell(struct sip_msg *msg, str callid_event) {
str callid;
str method;
struct to_body *pto= NULL, *pfrom = NULL;
struct sm_subscriber* s;
unsigned int hash_code;
method.s = msg->first_line.u.request.method.s;
method.len = msg->first_line.u.request.method.len;
if ( parse_headers(msg,HDR_EOH_F, 0) == -1 ){
LM_ERR("error in parsing headers\n");
return NULL;
}
// get callid from Notify
if( msg->callid==NULL || msg->callid->body.s==NULL){
LM_ERR("reply without callid header\n");
return NULL;
}
callid = msg->callid->body;
LM_DBG("CALLID: %.*s \n ", callid.len, callid.s );
if (msg->from->parsed == NULL){
if ( parse_from_header( msg )<0 ){
LM_ERR("reply without From header\n");
return NULL;
}
}
//get From header from Notify
pfrom = get_from(msg);
LM_DBG("PFROM: %.*s \n ", pfrom->uri.len, pfrom->uri.s );
if( pfrom->tag_value.s ==NULL || pfrom->tag_value.len == 0){
LM_ERR("reply without tag value \n");
return NULL;
}
if( msg->to==NULL || msg->to->body.s==NULL){
LM_ERR("error in parse TO header\n");
return NULL;
}
// get To header from Notify
pto = get_to(msg);
if (pto == NULL || pto->error != PARSE_OK) {
LM_ERR("failed to parse TO header\n");
return NULL;
}
if( pto->tag_value.s ==NULL || pto->tag_value.len == 0){
LM_ERR("reply without tag value \n");
}
LM_DBG("PTO: %.*s \n ", pto->uri.len, pto->uri.s );
LM_DBG("PTO_TAG: %.*s \n ", pto->tag_value.len, pto->tag_value.s );
LM_DBG("********************************************CALLID_STR%.*s\n", callid_event.len, callid_event.s);
hash_code= core_hash(&callid_event, 0, subst_size);
LM_DBG("********************************************HASH_CODE%d\n", hash_code);
s= search_shtable(subs_htable, &callid, &pfrom->tag_value, hash_code, &method);
if (s == NULL) {
LM_ERR(" ---FAILURE SUB_CELL NOT FOUND IN SHTABLE\n");
}
return s;
}
示例11: trace_sl_onreply_out
static void trace_sl_onreply_out( unsigned int types, struct sip_msg* req,
struct sl_cb_param *sl_param)
{
db_key_t db_keys[NR_KEYS];
db_val_t db_vals[NR_KEYS];
static char fromip_buff[IP_ADDR_MAX_STR_SIZE+12];
static char toip_buff[IP_ADDR_MAX_STR_SIZE+12];
int faked = 0;
struct sip_msg* msg;
int_str avp_value;
struct usr_avp *avp;
struct ip_addr to_ip;
int len;
char statusbuf[5];
if(req==NULL || sl_param==NULL)
{
LM_ERR("bad parameters\n");
goto error;
}
avp = NULL;
if(traced_user_avp.n!=0)
avp=search_first_avp(traced_user_avp_type, traced_user_avp,
&avp_value, 0);
if((avp==NULL) && trace_is_off(req))
{
LM_DBG("trace off...\n");
return;
}
msg = req;
faked = 1;
if(parse_from_header(msg)==-1 || msg->from==NULL || get_from(msg)==NULL)
{
LM_ERR("cannot parse FROM header\n");
goto error;
}
if(parse_headers(msg, HDR_CALLID_F, 0)!=0)
{
LM_ERR("cannot parse call-id\n");
return;
}
db_keys[0] = msg_column;
db_vals[0].type = DB_BLOB;
db_vals[0].nul = 0;
db_vals[0].val.blob_val.s = (sl_param->buffer)?sl_param->buffer->s:"";
db_vals[0].val.blob_val.len = (sl_param->buffer)?sl_param->buffer->len:0;
/* check Call-ID header */
if(msg->callid==NULL || msg->callid->body.s==NULL)
{
LM_ERR("cannot find Call-ID header!\n");
goto error;
}
db_keys[1] = callid_column;
db_vals[1].type = DB_STR;
db_vals[1].nul = 0;
db_vals[1].val.str_val.s = msg->callid->body.s;
db_vals[1].val.str_val.len = msg->callid->body.len;
db_keys[2] = method_column;
db_vals[2].type = DB_STR;
db_vals[2].nul = 0;
db_vals[2].val.str_val.s = msg->first_line.u.request.method.s;
db_vals[2].val.str_val.len = msg->first_line.u.request.method.len;
db_keys[4] = fromip_column;
db_vals[4].type = DB_STRING;
db_vals[4].nul = 0;
if(trace_local_ip)
db_vals[4].val.string_val = trace_local_ip;
else {
siptrace_copy_proto(msg->rcv.proto, fromip_buff);
strcat(fromip_buff, ip_addr2a(&req->rcv.dst_ip));
strcat(fromip_buff,":");
strcat(fromip_buff, int2str(req->rcv.dst_port, NULL));
db_vals[4].val.string_val = fromip_buff;
}
db_keys[3] = status_column;
db_vals[3].type = DB_STRING;
db_vals[3].nul = 0;
strcpy(statusbuf, int2str(sl_param->code, NULL));
db_vals[3].val.string_val = statusbuf;
db_keys[5] = toip_column;
db_vals[5].type = DB_STRING;
db_vals[5].nul = 0;
memset(&to_ip, 0, sizeof(struct ip_addr));
if(sl_param->dst==0)
{
db_vals[5].val.string_val = "any:255.255.255.255";
} else {
//.........这里部分代码省略.........
示例12: build_params_cb
/* Get some fields necessary to pass in function_cb*/
int build_params_cb(struct sip_msg* msg, char* callidHeader, struct parms_cb* params_cb ){
char *dialog_aux;
str from_tag;
int size_callid;
int size_dialog;
char *dialog;
if (parse_from_header(msg) != 0) {
LM_ERR(" REQUEST WITHOUT FROM HEADER\n");
}
from_tag = get_from(msg)->tag_value;
LM_DBG("FROM_TAG: %.*s\n", from_tag.len, from_tag.s);
LM_DBG("CALLID = %s \n", callidHeader);
size_callid = strlen(callidHeader);
size_dialog= size_callid + from_tag.len + 26;
dialog_aux = shm_malloc (sizeof (char)* size_dialog + 1);
if (dialog_aux == NULL) {
LM_ERR("--------------------------------------------------no more pkg memory\n");
return 0;
}
memset(dialog_aux, 0, size_dialog + 1);
dialog = dialog_aux;
memcpy(dialog_aux, "dialog; call-id=", 16);
dialog_aux += 16;
memcpy(dialog_aux, callidHeader, size_callid);
dialog_aux += size_callid;
memcpy(dialog_aux, ";from-tag=", 10);
dialog_aux += 10;
memcpy(dialog_aux, from_tag.s, from_tag.len);
LM_DBG("dialog: %s\n", dialog);
char *call_aux = shm_malloc (size_callid + 1);
if (call_aux == NULL) {
LM_ERR("--------------------------------------------------no more pkg memory\n");
return 0;
}
call_aux[size_callid] = 0;
memcpy(call_aux, callidHeader, size_callid);
char *ftag = shm_malloc (from_tag.len + 1);
if (ftag == NULL) {
LM_ERR("--------------------------------------------------no more pkg memory\n");
return 0;
}
ftag[from_tag.len] = 0;
memcpy(ftag, from_tag.s, from_tag.len);
params_cb->callid_ori.s = call_aux;
params_cb->callid_ori.len = size_callid;
params_cb->from_tag.s = ftag;
params_cb->from_tag.len = from_tag.len;
params_cb->event.s = dialog;
params_cb->event.len = size_dialog;
return 1;
}
示例13: subs_cback_func
void subs_cback_func(struct cell *t, int cb_type, struct tmcb_params *ps)
{
struct sip_msg* msg= NULL;
int lexpire= 0;
unsigned int cseq;
ua_pres_t* presentity= NULL, *hentity= NULL;
struct to_body *pto= NULL, *pfrom = NULL;
int size= 0;
int flag ;
str record_route= {0, 0};
int rt;
str contact;
int initial_request = 0;
if(ps==NULL || ps->param== NULL || *ps->param== NULL )
{
LM_ERR("null callback parameter\n");
return;
}
LM_DBG("completed with status %d\n",ps->code) ;
hentity= (ua_pres_t*)(*ps->param);
flag= hentity->flag;
if(hentity->flag & XMPP_INITIAL_SUBS)
hentity->flag= XMPP_SUBSCRIBE;
/* get dialog information from reply message: callid, to_tag, from_tag */
msg= ps->rpl;
if(msg == NULL)
{
LM_ERR("no reply message found\n ");
goto error;
}
if(msg== FAKED_REPLY)
{
/* delete record from hash_table and call registered functions */
if(hentity->call_id.s== NULL) /* if a new requets failed-> do nothing*/
{
LM_DBG("initial Subscribe request failed\n");
goto done;
}
lock_get(&HashT->p_records[hentity->hash_index].lock);
presentity = get_htable_safe(hentity->hash_index, hentity->local_index);
if(presentity)
{
delete_htable_safe(presentity, hentity->hash_index);
lock_release(&HashT->p_records[hentity->hash_index].lock);
}
lock_release(&HashT->p_records[hentity->hash_index].lock);
goto done;
}
if ( parse_headers(msg,HDR_EOH_F, 0)==-1 )
{
LM_ERR("when parsing headers\n");
goto done;
}
/*if initial request */
if(hentity->call_id.s== NULL)
{
initial_request = 1;
if(ps->code>= 300)
{
LM_DBG("initial Subscribe request failed\n");
goto done;
}
if( msg->callid==NULL || msg->callid->body.s==NULL)
{
LM_ERR("cannot parse callid header\n");
goto done;
}
if (!msg->from || !msg->from->body.s)
{
LM_ERR("cannot find 'from' header!\n");
goto done;
}
if (msg->from->parsed == NULL)
{
if ( parse_from_header( msg )<0 )
{
LM_ERR("cannot parse From header\n");
goto done;
}
}
pfrom = (struct to_body*)msg->from->parsed;
if( pfrom->tag_value.s ==NULL || pfrom->tag_value.len == 0)
{
LM_ERR("no from tag value present\n");
goto done;
}
if( msg->to==NULL || msg->to->body.s==NULL)
{
LM_ERR("cannot parse TO header\n");
goto done;
//.........这里部分代码省略.........
示例14: ac_uac_req
/*Actions are composed as follows:
* (the action length and type as always= 5 bytes)
* 4:uac_id
*
* int request(str* method, str* req_uri, str* to, str* from, str* headers, str* body, transaction_cb c, void* cp)
* TODO performance speedup: instead of using
* dynamically allocated memory for headers,body,totag,reason and my_msg
* use static buffers.
*
*/
int ac_uac_req(as_p the_as,unsigned char processor_id,unsigned int flags,char *action,int len)
{
unsigned int cseq;
char err_buf[MAX_REASON_LEN];
struct sip_msg *my_msg;
struct to_body *fb,*tb;
struct cseq_body *cseqb;
struct as_uac_param *the_param;
dlg_t *my_dlg;
int k,retval,uac_id,sip_error,ret,err_ret;
long clen;
str headers,body,fake_uri;
uac_req_t uac_r;
headers.s=body.s=fake_uri.s=NULL;
my_dlg=NULL;
my_msg=NULL;
the_param=NULL;
k=clen=0;
net2hostL(uac_id,action,k);
if(!(headers.s=pkg_malloc(MAX_HEADER))){
LM_ERR("Out of Memory!!");
goto error;
}
headers.len=0;
LM_DBG("Action UAC Message: uac_id:%d processor_id=%d\n",uac_id,processor_id);
if (!(my_msg = parse_ac_msg(HDR_EOH_F,action+k,len-k))) {
LM_ERR("out of memory!\n");
goto error;
}
if(my_msg->first_line.type==SIP_REPLY){
LM_ERR("trying to create a UAC with a SIP response!!\n");
goto error;
}
if(parse_headers(my_msg,HDR_EOH_F,0)==-1){
LM_ERR("ERROR:seas:ac_uac_req:parsing headers\n");
goto error;
}
if(parse_from_header(my_msg)<0){
LM_ERR("parsing from header ! \n");
goto error;
}
if(check_transaction_quadruple(my_msg)==0){
as_action_fail_resp(uac_id,SE_UAC,"Headers missing (to,from,call-id,cseq)?",0);
LM_ERR("Headers missing (to,from,call-id,cseq)?");
goto error;
}
if(!(get_from(my_msg)) || !(get_from(my_msg)->tag_value.s) ||
!(get_from(my_msg)->tag_value.len)){
as_action_fail_resp(uac_id,SE_UAC,"From tag missing",0);
LM_ERR("From tag missing");
goto error;
}
fb=my_msg->from->parsed;
tb=my_msg->to->parsed;
cseqb=my_msg->cseq->parsed;
if(0!=(str2int(&cseqb->number,&cseq))){
LM_DBG("unable to parse CSeq\n");
goto error;
}
if(my_msg->first_line.u.request.method_value != METHOD_ACK &&
my_msg->first_line.u.request.method_value != METHOD_CANCEL) {
/** we trick req_within */
cseq--;
}
if(seas_f.tmb.new_dlg_uac(&(my_msg->callid->body),&(fb->tag_value),cseq,\
&(fb->uri),&(tb->uri),&my_dlg) < 0) {
as_action_fail_resp(uac_id,SE_UAC,"Error creating new dialog",0);
LM_ERR("Error while creating new dialog\n");
goto error;
}
if(seas_f.tmb.dlg_add_extra(my_dlg,&(fb->display),&(tb->display)) < 0 ) {
as_action_fail_resp(uac_id,SE_UAC,
"Error adding the display names to the new dialog",0);
LM_ERR("failed to add display names to the new dialog\n");
goto error;
}
if(tb->tag_value.s && tb->tag_value.len)
shm_str_dup(&my_dlg->id.rem_tag,&tb->tag_value);
/**Awful hack: to be able to set our own CSeq, from_tag and call-ID we have
* to use req_within instead of req_outside (it sets it's own CSeq,Call-ID
* and ftag), so we have to simulate that the dialog is already in completed
* state so...
*/
server_signature=0;
my_dlg->state = DLG_CONFIRMED;
if(0>(headers.len=extract_allowed_headers(my_msg,1,-1,HDR_CONTENTLENGTH_F|HDR_ROUTE_F|HDR_TO_F|HDR_FROM_F|HDR_CALLID_F|HDR_CSEQ_F,headers.s,MAX_HEADER))) {
//.........这里部分代码省略.........
示例15: trace_onreply_in
static void trace_onreply_in(struct cell* t, int type, struct tmcb_params *ps)
{
db_key_t db_keys[NR_KEYS];
db_val_t db_vals[NR_KEYS];
static char fromip_buff[IP_ADDR_MAX_STR_SIZE+12];
static char toip_buff[IP_ADDR_MAX_STR_SIZE+12];
struct sip_msg* msg;
struct sip_msg* req;
int_str avp_value;
struct usr_avp *avp;
char statusbuf[8];
if(t==NULL || t->uas.request==0 || ps==NULL)
{
LM_DBG("no uas request, local transaction\n");
return;
}
req = ps->req;
msg = ps->rpl;
if(msg==NULL || req==NULL)
{
LM_DBG("no reply\n");
return;
}
avp = NULL;
if(traced_user_avp.n!=0)
avp=search_first_avp(traced_user_avp_type, traced_user_avp,
&avp_value, 0);
if((avp==NULL) && trace_is_off(req))
{
LM_DBG("trace off...\n");
return;
}
if(parse_from_header(msg)==-1 || msg->from==NULL || get_from(msg)==NULL)
{
LM_ERR("cannot parse FROM header\n");
goto error;
}
if(parse_headers(msg, HDR_CALLID_F, 0)!=0)
{
LM_ERR("cannot parse call-id\n");
return;
}
db_keys[0] = msg_column;
db_vals[0].type = DB_BLOB;
db_vals[0].nul = 0;
if(msg->len>0) {
db_vals[0].val.blob_val.s = msg->buf;
db_vals[0].val.blob_val.len = msg->len;
} else {
db_vals[0].val.blob_val.s = "No reply buffer";
db_vals[0].val.blob_val.len = sizeof("No reply buffer")-1;
}
/* check Call-ID header */
if(msg->callid==NULL || msg->callid->body.s==NULL)
{
LM_ERR("cannot find Call-ID header!\n");
goto error;
}
db_keys[1] = callid_column;
db_vals[1].type = DB_STR;
db_vals[1].nul = 0;
db_vals[1].val.str_val.s = msg->callid->body.s;
db_vals[1].val.str_val.len = msg->callid->body.len;
db_keys[2] = method_column;
db_vals[2].type = DB_STR;
db_vals[2].nul = 0;
db_vals[2].val.str_val.s = t->method.s;
db_vals[2].val.str_val.len = t->method.len;
db_keys[3] = status_column;
db_vals[3].type = DB_STRING;
db_vals[3].nul = 0;
strcpy(statusbuf, int2str(ps->code, NULL));
db_vals[3].val.string_val = statusbuf;
db_keys[4] = fromip_column;
db_vals[4].type = DB_STRING;
db_vals[4].nul = 0;
siptrace_copy_proto(msg->rcv.proto, fromip_buff);
strcat(fromip_buff, ip_addr2a(&msg->rcv.src_ip));
strcat(fromip_buff,":");
strcat(fromip_buff, int2str(msg->rcv.src_port, NULL));
db_vals[4].val.string_val = fromip_buff;
db_keys[5] = toip_column;
db_vals[5].type = DB_STRING;
db_vals[5].nul = 0;
// db_vals[5].val.string_val = ip_addr2a(&msg->rcv.dst_ip);;
if(trace_local_ip)
//.........这里部分代码省略.........