예제 #1
0
static inline void env_set_code_status( int code, struct sip_msg *reply)
{
	static char code_buf[INT2STR_MAX_LEN];
	str reason = {"Reason", 6};
	struct hdr_field *hf;

	acc_env.code = code;
	if (reply==FAKED_REPLY || reply==NULL) {
		/* code */
		acc_env.code_s.s =
			int2bstr((unsigned long)code, code_buf, &acc_env.code_s.len);
		/* reason */
		acc_env.reason.s = error_text(code);
		acc_env.reason.len = strlen(acc_env.reason.s);
	} else {
		acc_env.code_s = reply->first_line.u.reply.status;
		hf = NULL;
	        if (reason_from_hf) {
			/* TODO: take reason from all Reason headers */
			if(parse_headers(reply, HDR_EOH_F, 0) < 0) {
				LM_ERR("error parsing headers\n");
			} else {
				for (hf=reply->headers; hf; hf=hf->next) {
					if (cmp_hdrname_str(&hf->name, &reason)==0)
						break;
				}
			}
		}
		if (hf == NULL) {
			acc_env.reason = reply->first_line.u.reply.reason;
		} else {
			acc_env.reason = hf->body;
		}
	}
}
예제 #2
0
/*
 * Convert CSeq number into asciiz
 */
static inline int print_cseq_num(str* _s, dlg_t* _d)
{
	static char cseq[INT2STR_MAX_LEN];
	int len;

	_s->s = int2bstr(_d->loc_seq.value, cseq, &len);
	_s->len = len;
	return 0;
}
예제 #3
0
파일: acc_extra.c 프로젝트: 2pac/kamailio
int legs2strar( struct acc_extra *legs, struct sip_msg *rq, str *val_arr,
		int *int_arr, char *type_arr, int start)
{
	static struct usr_avp *avp[MAX_ACC_LEG];
	static struct search_state st[MAX_ACC_LEG];
	unsigned short name_type;
	int_str name;
	int_str value;
	int    n;
	int    found;
	int    r;

	found = 0;
	r = 0;

	for( n=0 ; legs ; legs=legs->next,n++ ) {
		/* search for the AVP */
		if (start) {
			if ( pv_get_avp_name( rq, &(legs->spec.pvp), &name, &name_type)<0 )
				goto exit;
			avp[n] = search_first_avp( name_type, name, &value, st + n);
		} else {
			avp[n] = search_next_avp(st + n, &value);
		}

		/* set new leg record */
		if (avp[n]) {
			found = 1;
			/* get its value */
			if(avp[n]->flags & AVP_VAL_STR) {
				val_arr[n] = value.s;
				type_arr[n] = TYPE_STR;
			} else {
				val_arr[n].s = int2bstr( value.n, int_buf+r*INT2STR_MAX_LEN,
					&val_arr[n].len);
				r++;
				int_arr[n] = value.n;
				type_arr[n] = TYPE_INT;
			}
		} else {
			val_arr[n].s = 0;
			val_arr[n].len = 0;
			type_arr[n] = TYPE_NULL;
		}

	}

	if (found || start)
		return n;
exit:
	return 0;
}
예제 #4
0
/*
 * raise DLG_STATE_CHANGED event
 */
static void raise_state_changed_event(unsigned int h_entry, unsigned int h_id,
									unsigned int ostate, unsigned int nstate)
{
	char b1[INT2STR_MAX_LEN], b2[INT2STR_MAX_LEN];
	str s1, s2;

	s1.s = int2bstr( (unsigned long)h_entry, b1, &s1.len );
	s2.s = int2bstr( (unsigned long)h_id, b2, &s2.len );
	if (s1.s==NULL || s2.s==NULL) {
		LM_ERR("cannot convert hash params\n");
		return;
	}
	if (evi_param_set_str(hentry_p, &s1) < 0) {
		LM_ERR("cannot set hash entry parameter\n");
		return;
	}

	if (evi_param_set_str(hid_p, &s2) < 0) {
		LM_ERR("cannot set hash id parameter\n");
		return;
	}

	if (evi_param_set_int(ostate_p, &ostate) < 0) {
		LM_ERR("cannot set old state parameter\n");
		return;
	}

	if (evi_param_set_int(nstate_p, &nstate) < 0) {
		LM_ERR("cannot set new state parameter\n");
		return;
	}

	if (evi_raise_event(ei_st_ch_id, event_params) < 0)
		LM_ERR("cannot raise event\n");

}
예제 #5
0
/*
 * Convert length of body into asciiz
 */
static inline int print_content_length(str* dest, str* body)
{
	static char content_length[INT2STR_MAX_LEN];
	int len;

	/* Print Content-Length */
	if (body && body->len) {
		dest->s = int2bstr(body->len, content_length, &len);
		dest->len = len;
	} else {
		dest->s = "0";
		dest->len = 1;
	}
	return 0;
}
예제 #6
0
파일: acc_logic.c 프로젝트: UIKit0/OpenSIPS
static inline void env_set_code_status( int code, struct sip_msg *reply)
{
	static char code_buf[INT2STR_MAX_LEN];

	acc_env.code = code;
	if (reply==FAKED_REPLY || reply==NULL) {
		/* code */
		acc_env.code_s.s =
			int2bstr((unsigned long)code, code_buf, &acc_env.code_s.len);
		/* reason */
		acc_env.reason.s = error_text(code);
		acc_env.reason.len = strlen(acc_env.reason.s);
	} else {
		acc_env.code_s = reply->first_line.u.reply.status;
		acc_env.reason = reply->first_line.u.reply.reason;
	}
}
예제 #7
0
/*! \brief
 * Returns the statistic associated with 'numerical_code' and 'out_codes'.
 * Specifically:
 *
 *  - if out_codes is nonzero, then the stat_var for the number of messages
 *    _sent out_ with the 'numerical_code' will be returned if it exists.
 *  - otherwise, the stat_var for the number of messages _received_ with the
 *    'numerical_code' will be returned, if the stat exists.
 */
stat_var *get_stat_var_from_num_code(unsigned int numerical_code, int out_codes)
{
    static char msg_code[INT2STR_MAX_LEN+4];
    str stat_name;

    stat_name.s = int2bstr( (unsigned long)numerical_code, msg_code,
                            &stat_name.len);
    stat_name.s[stat_name.len++] = '_';

    if (out_codes) {
        stat_name.s[stat_name.len++] = 'o';
        stat_name.s[stat_name.len++] = 'u';
        stat_name.s[stat_name.len++] = 't';
    } else {
        stat_name.s[stat_name.len++] = 'i';
        stat_name.s[stat_name.len++] = 'n';
    }

    return get_stat(&stat_name);
}
예제 #8
0
int get_redirect( struct sip_msg *msg , int maxt, int maxb,
									struct acc_param *reason, unsigned int bflags)
{
	struct cell *t;
	str backup_uri;
	int max;
	int cts_added;
	int n;
	int i;
	int first_branch;
	char code_buf[INT2STR_MAX_LEN];

	/* get transaction */
	t = rd_tmb.t_gett();
	if (t==T_UNDEFINED || t==T_NULL_CELL)
	{
		LM_CRIT("no current transaction found\n");
		goto error;
	}
	for(first_branch=t->nr_of_outgoings-1; first_branch>=0; first_branch--)
		if(t->uac[first_branch].flags&TM_UAC_FLAG_FB)
			break;
	if(first_branch<0)
	{
		LM_CRIT("no current first branch found\n");
		goto error;
	}

	LM_DBG("resume branch=%d\n", first_branch);

	cts_added = 0; /* no contact added */
	backup_uri = msg->new_uri; /* shmcontact2dset will ater this value */

	/* look if there are any 3xx branches starting from resume_branch */
	for( i=first_branch ; i<t->nr_of_outgoings ; i++) {
		LM_DBG("checking branch=%d (added=%d)\n", i, cts_added);
		/* is a redirected branch? */
		if (t->uac[i].last_received<300 || t->uac[i].last_received>399)
			continue;
		LM_DBG("branch=%d is a redirect (added=%d)\n", i, cts_added);
		/* ok - we have a new redirected branch -> how many contacts can
		 * we get from it*/
		if (maxb==0) {
			max = maxt?(maxt-cts_added):(-1);
		} else {
			max = maxt?((maxt-cts_added>=maxb)?maxb:(maxt-cts_added)):maxb;
		}
		if (max==0)
			continue;
		if(reason!=NULL)
		{
			/* put the response code into the acc_param reason struct */
			reason->code = t->uac[i].last_received;
			reason->code_s.s = int2bstr((unsigned long)reason->code, code_buf, &reason->code_s.len);
		}
		/* get the contact from it */
		n = shmcontact2dset( msg, t->uac[i].reply, max, reason, bflags);
		if ( n<0 ) {
			LM_ERR("get contact from shm_reply branch %d failed\n",i);
			/* do not go to error, try next branches */
		} else {
			/* count the added contacts */
			cts_added += n;
		}
	}

	/* restore original new_uri */
	msg->new_uri = backup_uri;

	/* return false if no contact was appended */
	return (cts_added>0)?1:-1;
error:
	return -1;
}