int uac_auth(sip_msg_t *msg)
{
static struct authenticate_body auth;
struct uac_credential *crd;
int code, branch;
struct sip_msg *rpl;
struct cell *t;
struct hdr_field *hdr;
HASHHEX response;
str *new_hdr;
sr_cfgenv_t *cenv = NULL;
/* get transaction */
t = uac_tmb.t_gett();
if (t==T_UNDEFINED || t==T_NULL_CELL)
{
LM_CRIT("no current transaction found\n");
goto error;
}
/* get the selected branch */
branch = uac_tmb.t_get_picked_branch();
if (branch<0) {
LM_CRIT("no picked branch (%d)\n",branch);
goto error;
}
rpl = t->uac[branch].reply;
code = t->uac[branch].last_received;
LM_DBG("picked reply is %p, code %d\n",rpl,code);
if (rpl==0)
{
LM_CRIT("empty reply on picked branch\n");
goto error;
}
if (rpl==FAKED_REPLY)
{
LM_ERR("cannot process a FAKED reply\n");
goto error;
}
hdr = get_autenticate_hdr( rpl, code);
if (hdr==0)
{
LM_ERR("failed to extract authenticate hdr\n");
goto error;
}
LM_DBG("header found; body=<%.*s>\n",
hdr->body.len, hdr->body.s);
if (parse_authenticate_body( &hdr->body, &auth)<0)
{
LM_ERR("failed to parse auth hdr body\n");
goto error;
}
/* can we authenticate this realm? */
crd = 0;
/* first look into AVP, if set */
if ( auth_realm_spec.type!=PVT_NONE )
crd = get_avp_credential( msg, &auth.realm );
/* if not found, look into predefined credentials */
if (crd==0)
crd = lookup_realm( &auth.realm );
/* found? */
if (crd==0)
{
LM_DBG("no credential for realm \"%.*s\"\n",
auth.realm.len, auth.realm.s);
goto error;
}
/* do authentication */
do_uac_auth( &msg->first_line.u.request.method,
&t->uac[branch].uri, crd, &auth, response);
/* build the authorization header */
new_hdr = build_authorization_hdr( code, &t->uac[branch].uri,
crd, &auth, response);
if (new_hdr==0)
{
LM_ERR("failed to build authorization hdr\n");
goto error;
}
/* so far, so good -> add the header and set the proper RURI */
if ( apply_urihdr_changes( msg, &t->uac[branch].uri, new_hdr)<0 )
{
LM_ERR("failed to apply changes\n");
goto error;
}
/* mark request in T with uac auth for increase of cseq via dialog
* - this function is executed in failure route, msg_flags will be
* reset afterwards by tm fake env */
if(t->uas.request) {
t->uas.request->msg_flags |= FL_UAC_AUTH;
cenv = sr_cfgenv_get();
//.........这里部分代码省略.........
开发者ID:furmur,项目名称:kamailio,代码行数:101,代码来源:auth.c
示例5: next_state_dlg
/*!
* \brief Update a dialog state according a event and the old state
*
* This functions implement the main state machine that update a dialog
* state according a processed event and the current state. If necessary
* it will delete the processed dialog. The old and new state are also
* saved for reference.
* \param dlg updated dialog
* \param event current event
* \param old_state old dialog state
* \param new_state new dialog state
* \param unref set to 1 when the dialog was deleted, 0 otherwise
*/
void next_state_dlg(dlg_cell_t *dlg, int event,
int *old_state, int *new_state, int *unref)
{
dlg_entry_t *d_entry;
d_entry = &(d_table->entries[dlg->h_entry]);
*unref = 0;
dlg_lock( d_table, d_entry);
*old_state = dlg->state;
switch (event) {
case DLG_EVENT_TDEL:
switch (dlg->state) {
case DLG_STATE_UNCONFIRMED:
case DLG_STATE_EARLY:
dlg->state = DLG_STATE_DELETED;
unref_dlg_unsafe(dlg,1,d_entry);
*unref = 1;
break;
case DLG_STATE_CONFIRMED_NA:
case DLG_STATE_CONFIRMED:
unref_dlg_unsafe(dlg,1,d_entry);
break;
case DLG_STATE_DELETED:
*unref = 1;
break;
default:
log_next_state_dlg(event, dlg);
}
break;
case DLG_EVENT_RPL1xx:
switch (dlg->state) {
case DLG_STATE_UNCONFIRMED:
case DLG_STATE_EARLY:
dlg->state = DLG_STATE_EARLY;
break;
default:
log_next_state_dlg(event, dlg);
}
break;
case DLG_EVENT_RPL3xx:
switch (dlg->state) {
case DLG_STATE_UNCONFIRMED:
case DLG_STATE_EARLY:
dlg->state = DLG_STATE_DELETED;
*unref = 1;
break;
default:
log_next_state_dlg(event, dlg);
}
break;
case DLG_EVENT_RPL2xx:
switch (dlg->state) {
case DLG_STATE_DELETED:
if (dlg->dflags&DLG_FLAG_HASBYE) {
LM_CRIT("bogus event %d in state %d (with BYE) "
"for dlg %p [%u:%u] with clid '%.*s' and tags '%.*s' '%.*s'\n",
event, dlg->state, dlg, dlg->h_entry, dlg->h_id,
dlg->callid.len, dlg->callid.s,
dlg->tag[DLG_CALLER_LEG].len, dlg->tag[DLG_CALLER_LEG].s,
dlg->tag[DLG_CALLEE_LEG].len, dlg->tag[DLG_CALLEE_LEG].s);
break;
}
ref_dlg_unsafe(dlg,1);
case DLG_STATE_UNCONFIRMED:
case DLG_STATE_EARLY:
dlg->state = DLG_STATE_CONFIRMED_NA;
break;
case DLG_STATE_CONFIRMED_NA:
case DLG_STATE_CONFIRMED:
break;
default:
log_next_state_dlg(event, dlg);
}
break;
case DLG_EVENT_REQACK:
switch (dlg->state) {
case DLG_STATE_CONFIRMED_NA:
dlg->state = DLG_STATE_CONFIRMED;
break;
case DLG_STATE_CONFIRMED:
break;
case DLG_STATE_DELETED:
break;
//.........这里部分代码省略.........
int pv_set_tm_branch_avp(struct sip_msg *msg, pv_param_t *param, int op,
pv_value_t *val)
{
int avp_name;
int_str avp_val;
int flags, res=0;
unsigned short name_type;
int idx, idxf;
struct usr_avp **old_list=NULL;
struct usr_avp **avp_list=NULL;
if (!msg || !val)
goto error;
avp_list = get_bavp_list();
if (!avp_list) {
pv_get_null(msg, param, val);
goto success;
}
if (!param) {
LM_ERR("bad parameters\n");
goto error;
}
if (pv_get_avp_name(msg, param, &avp_name, &name_type)) {
LM_ALERT("BUG in getting bavp name\n");
goto error;
}
/* get the index */
if(pv_get_spec_index(msg, param, &idx, &idxf)!=0) {
LM_ERR("invalid index\n");
goto error;
}
/* setting the avp head */
old_list = set_avp_list(avp_list);
if (!old_list) {
LM_CRIT("no bavp head list found\n");
goto error;
}
if(val == NULL) {
if(op == COLONEQ_T || idxf == PV_IDX_ALL)
destroy_avps(name_type, avp_name, 1);
else {
if(idx < 0) {
LM_ERR("index with negative value\n");
goto error;
}
destroy_index_avp(name_type, avp_name, idx);
}
/* restoring head */
goto success;
}
if(op == COLONEQ_T || idxf == PV_IDX_ALL)
destroy_avps(name_type, avp_name, 1);
flags = name_type;
if(val->flags&PV_TYPE_INT) {
avp_val.n = val->ri;
} else {
avp_val.s = val->rs;
flags |= AVP_VAL_STR;
}
if(idxf == PV_IDX_INT || idxf == PV_IDX_PVAR) {
if(replace_avp(flags, avp_name, avp_val, idx)< 0) {
LM_ERR("failed to replace bavp\n");
goto error;
}
} else {
if (add_avp(flags, avp_name, avp_val)<0) {
LM_ERR("error - cannot add bavp\n");
goto error;
}
}
goto success;
error:
res = -1;
success:
if (old_list)
set_avp_list(old_list);
return res;
}
开发者ID:Danfx,项目名称:opensips,代码行数:88,代码来源:tm.c
示例11: mod_init
static int mod_init(void)
{
unsigned int timer_sets,set;
unsigned int roundto_init;
LM_INFO("TM - initializing...\n");
/* checking if we have sufficient bitmap capacity for given
maximum number of branches */
if (MAX_BRANCHES+1>31) {
LM_CRIT("Too many max UACs for UAC branch_bm_t bitmap: %d\n",
MAX_BRANCHES );
return -1;
}
fix_flag_name(minor_branch_flag_str, minor_branch_flag);
minor_branch_flag =
get_flag_id_by_name(FLAG_TYPE_BRANCH, minor_branch_flag_str);
if (minor_branch_flag!=-1) {
if (minor_branch_flag > (8*sizeof(int)-1)) {
LM_CRIT("invalid minor branch flag\n");
return -1;
}
minor_branch_flag = 1<<minor_branch_flag;
} else {
minor_branch_flag = 0;
}
/* if statistics are disabled, prevent their registration to core */
if (tm_enable_stats==0)
#ifdef STATIC_TM
tm_exports.stats = 0;
#else
exports.stats = 0;
#endif
if (init_callid() < 0) {
LM_CRIT("Error while initializing Call-ID generator\n");
return -1;
}
/* how many timer sets do we need to create? */
timer_sets = (timer_partitions<=1)?1:timer_partitions ;
/* try first allocating all the structures needed for syncing */
if (lock_initialize( timer_sets )==-1)
return -1;
/* building the hash table*/
if (!init_hash_table( timer_sets )) {
LM_ERR("initializing hash_table failed\n");
return -1;
}
/* init static hidden values */
init_t();
if (!tm_init_timers( timer_sets ) ) {
LM_ERR("timer init failed\n");
return -1;
}
/* the ROUNDTO macro taken from the locking interface */
#ifdef ROUNDTO
roundto_init = ROUNDTO;
#else
roundto_init = sizeof(void *);
#endif
while (roundto_init != 1) {
tm_timer_shift++;
roundto_init >>= 1;
}
LM_DBG("timer set shift is %d\n", tm_timer_shift);
/* register the timer functions */
for ( set=0 ; set<timer_sets ; set++ ) {
if (register_timer( "tm-timer", timer_routine,
(void*)(long)set, 1, TIMER_FLAG_DELAY_ON_DELAY) < 0 ) {
LM_ERR("failed to register timer for set %d\n",set);
return -1;
}
if (register_utimer( "tm-utimer", utimer_routine,
(void*)(long)set, 100*1000, TIMER_FLAG_DELAY_ON_DELAY)<0) {
LM_ERR("failed to register utimer for set %d\n",set);
return -1;
}
}
if (uac_init()==-1) {
LM_ERR("uac_init failed\n");
return -1;
}
if (init_tmcb_lists()!=1) {
LM_CRIT("failed to init tmcb lists\n");
return -1;
//.........这里部分代码省略.........
开发者ID:Danfx,项目名称:opensips,代码行数:101,代码来源:tm.c
示例12: pv_get_tm_branch_avp
int pv_get_tm_branch_avp(struct sip_msg *msg, pv_param_t *param,
pv_value_t *val)
{
int avp_name;
int_str avp_value;
unsigned short name_type;
int idx, idxf, res=0;
struct usr_avp **old_list=NULL;
struct usr_avp **avp_list=NULL;
struct usr_avp *avp;
int_str avp_value0;
struct usr_avp *avp0;
int n=0;
char *p;
if (!msg || !val)
goto error;
avp_list = get_bavp_list();
if (!avp_list) {
pv_get_null(msg, param, val);
goto success;
}
if (!param) {
LM_ERR("bad parameters\n");
goto error;
}
if (pv_get_avp_name(msg, param, &avp_name, &name_type)) {
LM_ALERT("BUG in getting bavp name\n");
goto error;
}
/* get the index */
if(pv_get_spec_index(msg, param, &idx, &idxf)!=0) {
LM_ERR("invalid index\n");
goto error;
}
/* setting the avp head */
old_list = set_avp_list(avp_list);
if (!old_list) {
LM_CRIT("no bavp head list found\n");
goto error;
}
if ((avp=search_first_avp(name_type, avp_name, &avp_value, 0))==0) {
pv_get_null(msg, param, val);
goto success;
}
val->flags = PV_VAL_STR;
if ( (idxf==0 || idxf==PV_IDX_INT) && idx==0) {
if(avp->flags & AVP_VAL_STR) {
val->rs = avp_value.s;
} else {
val->rs.s = sint2str(avp_value.n, &val->rs.len);
val->ri = avp_value.n;
val->flags |= PV_VAL_INT|PV_TYPE_INT;
}
goto success;
}
if(idxf==PV_IDX_ALL) {
p = pv_local_buf;
do {
if(avp->flags & AVP_VAL_STR) {
val->rs = avp_value.s;
} else {
val->rs.s = sint2str(avp_value.n, &val->rs.len);
}
if(p-pv_local_buf+val->rs.len+1>PV_LOCAL_BUF_SIZE) {
LM_ERR("local buffer length exceeded!\n");
pv_get_null(msg, param, val);
goto success;
}
memcpy(p, val->rs.s, val->rs.len);
p += val->rs.len;
if(p-pv_local_buf+PV_FIELD_DELIM_LEN+1>PV_LOCAL_BUF_SIZE) {
LM_ERR("local buffer length exceeded\n");
pv_get_null(msg, param, val);
goto success;
}
memcpy(p, PV_FIELD_DELIM, PV_FIELD_DELIM_LEN);
p += PV_FIELD_DELIM_LEN;
} while ((avp=search_first_avp(name_type, avp_name,
&avp_value, avp))!=0);
*p = 0;
val->rs.s = pv_local_buf;
val->rs.len = p - pv_local_buf;
goto success;
}
/* we have a numeric index */
if(idx<0) {
n = 1;
avp0 = avp;
while ((avp0=search_first_avp(name_type, avp_name,
&avp_value0, avp0))!=0) n++;
idx = -idx;
//.........这里部分代码省略.........
开发者ID:Danfx,项目名称:opensips,代码行数:101,代码来源:tm.c
示例13: dp_can_connect_str
int dp_can_connect_str(str *domain, int rec_level) {
struct rdata* head;
struct rdata* l;
struct naptr_rdata* naptr;
struct naptr_rdata* next_naptr;
int ret;
str newdomain;
char uri[MAX_URI_SIZE];
struct avp_stack stack;
int last_order = -1;
int failed = 0;
int found_anything = 0;
str pattern, replacement, result;
stack_reset(&stack);
/* If we're in a recursive call, set the domain-replacement */
if ( rec_level > 0 ) {
stack_push(&stack, domain_replacement_avp.s, domain->s);
stack.succeeded = 0;
}
if (rec_level > MAX_DDDS_RECURSIONS) {
LM_ERR("too many indirect NAPTRs. Aborting at %.*s.\n", domain->len,
ZSW(domain->s));
return(DP_DDDS_RET_DNSERROR);
}
LM_INFO("looking up Domain itself: %.*s\n",domain->len, ZSW(domain->s));
ret = check_rule(domain,"D2P+sip:dom", 11, &stack);
if (ret == 1) {
LM_INFO("found a match on domain itself\n");
stack_to_avp(&stack);
return(DP_DDDS_RET_POSITIVE);
} else if (ret == 0) {
LM_INFO("no match on domain itself.\n");
stack_reset(&stack);
/* If we're in a recursive call, set the domain-replacement */
if ( rec_level > 0 ) {
stack_push(&stack, domain_replacement_avp.s, (char *) domain->s);
stack.succeeded = 0;
}
} else {
return(DP_DDDS_RET_DNSERROR); /* actually: DB error */
}
LM_INFO("doing DDDS with %.*s\n",domain->len, ZSW(domain->s));
head = get_record(domain->s, T_NAPTR);
if (head == 0) {
LM_NOTICE("no NAPTR record found for %.*s.\n",
domain->len, ZSW(domain->s));
return(DP_DDDS_RET_NOTFOUND);
}
LM_DBG("found the following NAPTRs: \n");
for (l = head; l; l = l->next) {
if (l->type != T_NAPTR) {
LM_DBG("found non-NAPTR record.\n");
continue; /*should never happen*/
}
naptr = (struct naptr_rdata*)l->rdata;
if (naptr == 0) {
LM_CRIT("null rdata\n");
continue;
}
LM_DBG("order %u, pref %u, flen %u, flags '%.*s', slen %u, "
"services '%.*s', rlen %u, regexp '%.*s', repl '%s'\n",
naptr->order, naptr->pref,
naptr->flags_len, (int)(naptr->flags_len), ZSW(naptr->flags),
naptr->services_len,
(int)(naptr->services_len), ZSW(naptr->services), naptr->regexp_len,
(int)(naptr->regexp_len), ZSW(naptr->regexp),
ZSW(naptr->repl)
);
}
LM_DBG("sorting...\n");
naptr_sort(&head);
for (l = head; l; l = l->next) {
if (l->type != T_NAPTR) continue; /*should never happen*/
naptr = (struct naptr_rdata*)l->rdata;
if (naptr == 0) {
LM_CRIT("null rdata\n");
continue;
}
LM_DBG("considering order %u, pref %u, flen %u, flags '%.*s', slen %u, "
"services '%.*s', rlen %u, regexp '%.*s', repl '%s'\n",
naptr->order, naptr->pref,
naptr->flags_len, (int)(naptr->flags_len), ZSW(naptr->flags),
naptr->services_len,
(int)(naptr->services_len), ZSW(naptr->services), naptr->regexp_len,
(int)(naptr->regexp_len), ZSW(naptr->regexp),
ZSW(naptr->repl)
);
//.........这里部分代码省略.........
//.........这里部分代码省略.........
/* we end the program in all these cases */
if (sig_flag==SIGINT)
LM_DBG("INT received, program terminates\n");
else
LM_DBG("SIGTERM received, program terminates\n");
/* first of all, kill the children also */
kill_all_children(SIGTERM);
if (signal(SIGALRM, sig_alarm_kill) == SIG_ERR ) {
LM_ERR("could not install SIGALARM handler\n");
/* continue, the process will die anyway if no
* alarm is installed which is exactly what we want */
}
alarm(shutdown_time);
while(wait(0) > 0); /* Wait for all the children to terminate */
signal(SIGALRM, sig_alarm_abort);
cleanup(1); /* cleanup & show status*/
alarm(0);
signal(SIGALRM, SIG_IGN);
dprint("Thank you for flying " NAME "\n");
exit(0);
break;
case SIGUSR1:
#ifdef PKG_MALLOC
LM_GEN1(memdump, "Memory status (pkg):\n");
pkg_status();
#endif
#ifdef SHM_MEM
LM_GEN1(memdump, "Memory status (shm):\n");
shm_status();
#endif
break;
case SIGUSR2:
#ifdef PKG_MALLOC
set_pkg_stats( get_pkg_status_holder(process_no) );
#endif
break;
case SIGCHLD:
do_exit = 0;
while ((chld=waitpid( -1, &chld_status, WNOHANG ))>0) {
/* is it a process we know about? */
for( i=0 ; i<counted_processes ; i++ )
if (pt[i].pid==chld) break;
if (i==counted_processes) {
LM_DBG("unkown child process %d ended. Ignoring\n",chld);
continue;
}
do_exit = 1;
/* process the signal */
overall_status |= chld_status;
LM_DBG("status = %d\n",overall_status);
if (WIFEXITED(chld_status))
LM_INFO("child process %d exited normally,"
" status=%d\n", chld,
WEXITSTATUS(chld_status));
else if (WIFSIGNALED(chld_status)) {
LM_INFO("child process %d exited by a signal"
" %d\n", chld, WTERMSIG(chld_status));
#ifdef WCOREDUMP
LM_INFO("core was %sgenerated\n",
WCOREDUMP(chld_status) ? "" : "not " );
#endif
}else if (WIFSTOPPED(chld_status))
LM_INFO("child process %d stopped by a"
" signal %d\n", chld,
WSTOPSIG(chld_status));
}
if (!do_exit)
break;
LM_INFO("terminating due to SIGCHLD\n");
/* exit */
kill_all_children(SIGTERM);
if (signal(SIGALRM, sig_alarm_kill) == SIG_ERR ) {
LM_ERR("could not install SIGALARM handler\n");
/* continue, the process will die anyway if no
* alarm is installed which is exactly what we want */
}
alarm(shutdown_time);
while(wait(0) > 0); /* wait for all the children to terminate*/
signal(SIGALRM, sig_alarm_abort);
cleanup(1); /* cleanup & show status*/
alarm(0);
signal(SIGALRM, SIG_IGN);
LM_DBG("terminating due to SIGCHLD\n");
exit(overall_status ? -1 : 0);
break;
case SIGHUP: /* ignoring it*/
LM_DBG("SIGHUP received, ignoring it\n");
break;
default:
LM_CRIT("unhandled signal %d\n", sig_flag);
}
sig_flag=0;
}
开发者ID:dsandras,项目名称:opensips,代码行数:101,代码来源:main.c
示例16: mi_child_init
static int mi_child_init(void)
{
if (rls_dbf.init==0)
{
LM_CRIT("database not bound\n");
return -1;
}
/* In DB only mode do not pool the connections where possible. */
if (dbmode == RLS_DB_ONLY && rls_dbf.init2)
rls_db = rls_dbf.init2(&db_url, DB_POOLING_NONE);
else
rls_db = rls_dbf.init(&db_url);
if (!rls_db)
{
LM_ERR("Error while connecting database\n");
return -1;
}
else
{
if (rls_dbf.use_table(rls_db, &rlsubs_table) < 0)
{
LM_ERR("Error in use_table rlsubs_table\n");
return -1;
}
LM_DBG("Database connection opened successfully\n");
}
if (rlpres_dbf.init==0)
{
LM_CRIT("database not bound\n");
return -1;
}
/* In DB only mode do not pool the connections where possible. */
if (dbmode == RLS_DB_ONLY && rlpres_dbf.init2)
rlpres_db = rlpres_dbf.init2(&db_url, DB_POOLING_NONE);
else
rlpres_db = rlpres_dbf.init(&db_url);
if (!rlpres_db)
{
LM_ERR("Error while connecting database\n");
return -1;
}
else
{
if (rlpres_dbf.use_table(rlpres_db, &rlpres_table) < 0)
{
LM_ERR("Error in use_table rlpres_table\n");
return -1;
}
LM_DBG("Database connection opened successfully\n");
}
if (rls_xcap_dbf.init==0)
{
LM_CRIT("database not bound\n");
return -1;
}
rls_xcap_db = rls_xcap_dbf.init(&xcap_db_url);
if (!rls_xcap_db)
{
LM_ERR("Error while connecting database\n");
return -1;
}
else
{
if (rls_xcap_dbf.use_table(rls_xcap_db, &rls_xcap_table) < 0)
{
LM_ERR("Error in use_table rls_xcap_table\n");
return -1;
}
LM_DBG("Database connection opened successfully\n");
}
return 0;
}
请发表评论