NS_EVENT Node::ReportRCVEvent(osip_message_t *M) { osip_generic_param_t *param ; osip_uri_param_get_byname(M->from->gen_params,"user",¶m) ; // if(!strcmp(param->gvalue,"multicast")) { if(MSG_IS_REQUEST(M)) { return MULTICAST_REQ_RCV ; } else { if(MSG_IS_STATUS_2XX(M)) return MULTICAST_RESP_2XX ; else return EVT_OTHER ; } } // else if(!strcmp(param->gvalue,"join")) { if(MSG_IS_REQUEST(M)) { return JOIN_REQ_RCV ; } else { if(MSG_IS_STATUS_2XX(M)) return JOIN_RESP_2XX ; else if(MSG_IS_STATUS_3XX(M)) return JOIN_RESP_3XX ; else return EVT_OTHER ; } } // else if(!strcmp(param->gvalue,"findsucc")) { if(MSG_IS_REQUEST(M)) { return FINDSUCC_REQ_RCV ; } else { if(MSG_IS_STATUS_2XX(M)) return FINDSUCC_RESP_2XX ; else if(MSG_IS_STATUS_3XX(M)) return FINDSUCC_RESP_3XX ; else return EVT_OTHER ; } } // else if(!strcmp(param->gvalue,"stabilize")) { if(MSG_IS_REQUEST(M)) { return STABILIZE_REQ_RCV ; } else { if(MSG_IS_STATUS_2XX(M)) return STABILIZE_RESP_2XX ; else return EVT_OTHER ; } } // else if(!strcmp(param->gvalue,"leave")) { if(MSG_IS_REQUEST(M)) { return LEAVE_REQ_RCV ; } else return EVT_OTHER ; } // else if(!strcmp(param->gvalue,"user_registration")) { if(MSG_IS_REQUEST(M)) { return USER_REG_RCV ; } else if(MSG_IS_STATUS_2XX(M)) return USER_REG_RESP_2XX; else if(MSG_IS_STATUS_3XX(M)) return USER_REG_RESP_3XX; else return EVT_OTHER ; } else if(!strcmp(param->gvalue,"red_register")) { if(MSG_IS_REQUEST(M)) return RED_REGISTER_RCV; else if(MSG_IS_STATUS_2XX(M)) return RED_REGISTER_RESP_2XX; else return EVT_OTHER; } // else if(!strcmp(param->gvalue,"user_query")) { if(MSG_IS_REQUEST(M)) { return USER_QUERY_RCV ; } else if(MSG_IS_STATUS_2XX(M)) return USER_QUERY_RESP_2XX; else if(MSG_IS_STATUS_3XX(M)) return USER_QUERY_RESP_3XX; else return EVT_OTHER ; } // else { return EVT_OTHER ; } }
static int __osip_dialog_init (osip_dialog_t ** dialog, osip_message_t * invite, osip_message_t * response, osip_from_t * local, osip_to_t * remote, osip_message_t * remote_msg) { int i; int pos; osip_generic_param_t *tag; *dialog = NULL; if (response == NULL) return OSIP_BADPARAMETER; if (response->cseq == NULL || local == NULL || remote == NULL) return OSIP_SYNTAXERROR; (*dialog) = (osip_dialog_t *) osip_malloc (sizeof (osip_dialog_t)); if (*dialog == NULL) return OSIP_NOMEM; memset (*dialog, 0, sizeof (osip_dialog_t)); (*dialog)->your_instance = NULL; if (MSG_IS_STATUS_2XX (response)) (*dialog)->state = DIALOG_CONFIRMED; else /* 1XX */ (*dialog)->state = DIALOG_EARLY; i = osip_call_id_to_str (response->call_id, &((*dialog)->call_id)); if (i != 0) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "Could not establish dialog!\n")); osip_dialog_free (*dialog); *dialog = NULL; return i; } i = osip_to_get_tag (local, &tag); if (i != 0) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "Could not establish dialog!\n")); osip_dialog_free (*dialog); *dialog = NULL; return i; } (*dialog)->local_tag = osip_strdup (tag->gvalue); i = osip_from_get_tag (remote, &tag); if (i == 0) (*dialog)->remote_tag = osip_strdup (tag->gvalue); /* VR-2785: remember line value */ if (invite) { osip_uri_param_t *line_param; i = osip_uri_param_get_byname (&invite->req_uri->url_params, "line", &line_param); if (i == 0 && line_param != NULL && line_param->gvalue != NULL) (*dialog)->line_param = osip_strdup (line_param->gvalue); } osip_list_init (&(*dialog)->route_set); pos = 0; while (!osip_list_eol (&response->record_routes, pos)) { osip_record_route_t *rr; osip_record_route_t *rr2; rr = (osip_record_route_t *) osip_list_get (&response->record_routes, pos); i = osip_record_route_clone (rr, &rr2); if (i != 0) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "Could not establish dialog!\n")); osip_dialog_free (*dialog); *dialog = NULL; return i; } if (invite == NULL) osip_list_add (&(*dialog)->route_set, rr2, 0); else osip_list_add (&(*dialog)->route_set, rr2, -1); pos++; } /* local_cseq is set to response->cseq->number for better handling of bad UA */ (*dialog)->local_cseq = osip_atoi (response->cseq->number); i = osip_from_clone (remote, &((*dialog)->remote_uri)); if (i != 0) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "Could not establish dialog!\n")); osip_dialog_free (*dialog); *dialog = NULL; return i; } i = osip_to_clone (local, &((*dialog)->local_uri)); if (i != 0) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "Could not establish dialog!\n")); osip_dialog_free (*dialog); *dialog = NULL; return i; } { osip_contact_t *contact; if (!osip_list_eol (&remote_msg->contacts, 0)) { contact = osip_list_get (&remote_msg->contacts, 0); i = osip_contact_clone (contact, &((*dialog)->remote_contact_uri)); if (i != 0) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "Could not establish dialog!\n")); osip_dialog_free (*dialog); *dialog = NULL; return i; } } else { (*dialog)->remote_contact_uri = NULL; OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_WARNING, NULL, "Remote UA is not compliant: missing a contact in remote message!\n")); } } (*dialog)->secure = -1; /* non secure */ return OSIP_SUCCESS; }
int CFrom::GetTag( CUrlParam** dest ) { return osip_uri_param_get_byname(&gen_params,"tag",dest); }
int osip_dialog_match_as_uas (osip_dialog_t * dlg, osip_message_t * request) { osip_generic_param_t *tag_param_remote; int i; char *tmp; if (dlg == NULL || dlg->call_id == NULL) return OSIP_BADPARAMETER; if (request == NULL || request->call_id == NULL || request->from == NULL || request->to == NULL) return OSIP_BADPARAMETER; osip_call_id_to_str (request->call_id, &tmp); if (0 != strcmp (dlg->call_id, tmp)) { osip_free (tmp); return OSIP_UNDEFINED_ERROR; } osip_free (tmp); /* for INCOMING REQUEST: To: local_uri;local_tag <- LOCAL TAG ALWAYS EXIST From: remote_uri;remote_tag */ if (dlg->local_tag == NULL) /* NOT POSSIBLE BECAUSE I MANAGE REMOTE_TAG AND I ALWAYS ADD IT! */ return OSIP_SYNTAXERROR; #if 0 /* VR-2785: use line param to distinguish between two registrations by the same user */ if (dlg->line_param) { osip_uri_param_t *line_param; i = osip_uri_param_get_byname (&request->req_uri->url_params, "line", &line_param); if (i == 0 && strcmp (dlg->line_param, line_param->gvalue)) return OSIP_UNDEFINED_ERROR; /* both dlg and req_uri have line params and they do not match */ } #endif i = osip_from_get_tag (request->from, &tag_param_remote); if (i != 0 && dlg->remote_tag != NULL) /* no tag in request but tag in dialog */ return OSIP_SYNTAXERROR; /* impossible... */ if (i != 0 && dlg->remote_tag == NULL) { /* no tag in request AND no tag in dialog */ if (0 == osip_from_compare ((osip_from_t *) dlg->remote_uri, (osip_from_t *) request->from) && 0 == osip_from_compare (dlg->local_uri, request->to)) return OSIP_SUCCESS; return OSIP_UNDEFINED_ERROR; } if (dlg->remote_tag == NULL) { /* tag in response BUT no tag in dialog */ OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_WARNING, NULL, "Remote UA is not compliant: missing a tag in To feilds!\n")); if (0 == osip_from_compare ((osip_from_t *) dlg->remote_uri, (osip_from_t *) request->from) && 0 == osip_from_compare (dlg->local_uri, request->to)) return OSIP_SUCCESS; return OSIP_UNDEFINED_ERROR; } /* we don't have to compare remote_uri with from && local_uri with to. ----> we have both tag recognized, it's enough.. */ if (0 == strcmp (tag_param_remote->gvalue, dlg->remote_tag)) return OSIP_SUCCESS; return OSIP_UNDEFINED_ERROR; }
/* code (entry point) */ static int plugin_regex_process(sip_ticket_t *ticket) { int sts=STS_SUCCESS; osip_uri_t *req_url; osip_uri_t *to_url; osip_generic_param_t *r=NULL; /* plugin loaded and not configured, return with success */ if (plugin_cfg.regex_pattern.used==0) return STS_SUCCESS; if (plugin_cfg.regex_replace.used==0) return STS_SUCCESS; DEBUGC(DBCLASS_PLUGIN,"plugin entered"); req_url=osip_message_get_uri(ticket->sipmsg); to_url=osip_to_get_url(ticket->sipmsg); /* only outgoing direction is handled */ sip_find_direction(ticket, NULL); if (ticket->direction != DIR_OUTGOING) return STS_SUCCESS; /* only INVITE and ACK are handled */ if (!MSG_IS_INVITE(ticket->sipmsg) && !MSG_IS_ACK(ticket->sipmsg)) return STS_SUCCESS; /* expire old cache entries */ expire_redirected_cache(&redirected_cache); /* REQ URI with username must exist, prefix string must exist */ if (!req_url || !req_url->username) return STS_SUCCESS; /* ignore */ /* Loop avoidance: * If this INVITE has already been redirected by a prior 302 * moved response a "REDIRECTED_TAG" parameter should be present in the * URI. * Hopefully all UAs (Clients) do honor RFC3261 and copy the * *full* URI form the contact header into the new request header * upon a 3xx response. */ if (req_url) { osip_uri_param_get_byname(&(req_url->url_params), REDIRECTED_TAG, &r); if (r && r->gvalue && strcmp(r->gvalue,REDIRECTED_VAL)== 0) { DEBUGC(DBCLASS_PLUGIN,"Packet has already been processed (ReqURI)"); return STS_SUCCESS; } } if (to_url) { osip_uri_param_get_byname(&(to_url->url_params), REDIRECTED_TAG, &r); if (r && r->gvalue && strcmp(r->gvalue,REDIRECTED_VAL)== 0) { DEBUGC(DBCLASS_PLUGIN,"Packet has already been processed (ToURI)"); return STS_SUCCESS; } } /* * The SIP message is to be processed */ /* outgoing INVITE request */ if (MSG_IS_INVITE(ticket->sipmsg)) { DEBUGC(DBCLASS_PLUGIN,"processing INVITE"); sts=plugin_regex_redirect(ticket); } /* outgoing ACK request: is result of a local 3xx answer (moved...) * * Only consume that particular ACK that belongs to a sent 302 answer, * nothing else. Otherwise the ACK from the redirected call will get * consumed as well and causes the call to be aborted (timeout). * We keep a cache with Call-Ids of such "302 moved" dialogs. * Only consume such ACKs that are part of such a dialog. */ else if (MSG_IS_ACK(ticket->sipmsg)) { if (is_in_redirected_cache(&redirected_cache, ticket) == STS_TRUE) { DEBUGC(DBCLASS_PLUGIN,"processing ACK (consume it)"); sts=STS_SIP_SENT; /* eat up the ACK that was directed to myself */ } } return sts; }