int osip_from_tag_match (osip_from_t * from1, osip_from_t * from2) { osip_generic_param_t *tag_from1; osip_generic_param_t *tag_from2; osip_from_param_get_byname (from1, "tag", &tag_from1); osip_from_param_get_byname (from2, "tag", &tag_from2); if (tag_from1 == NULL && tag_from2 == NULL) return 0; if ((tag_from1 != NULL && tag_from2 == NULL) || (tag_from1 == NULL && tag_from2 != NULL)) return -1; if (tag_from1->gvalue == NULL || tag_from2->gvalue == NULL) return -1; if (0 != strcmp (tag_from1->gvalue, tag_from2->gvalue)) return -1; return 0; }
int eXosip_add_authentication_information (osip_message_t * req, osip_message_t * last_response) { osip_authorization_t *aut = NULL; osip_www_authenticate_t *wwwauth = NULL; osip_proxy_authorization_t *proxy_aut = NULL; osip_proxy_authenticate_t *proxyauth = NULL; jauthinfo_t *authinfo = NULL; int pos; int i; if (req == NULL || req->from == NULL || req->from->url == NULL || req->from->url->username == NULL) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO2, NULL, "authinfo: Invalid message\n")); return -1; } if (last_response==NULL) { /* we can add all credential that belongs to the same call-id */ struct eXosip_http_auth *http_auth; int pos; /* update entries with same call_id */ for (pos=0;pos<MAX_EXOSIP_HTTP_AUTH;pos++) { http_auth = &eXosip.http_auths[pos]; if (http_auth->pszCallId[0]=='\0') continue; if (osip_strcasecmp(http_auth->pszCallId, req->call_id->number)==0) { char *uri; authinfo = eXosip_find_authentication_info (req->from->url->username, http_auth->wa->realm); if (authinfo == NULL) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO2, NULL, "authinfo: No authentication found for %s %s\n", req->from->url->username, http_auth->wa->realm)); return -1; } i = osip_uri_to_str (req->req_uri, &uri); if (i != 0) return -1; http_auth->iNonceCount++; if (osip_strcasecmp(req->sip_method, "REGISTER")==0) i = __eXosip_create_authorization_header (http_auth->wa, uri, authinfo->userid, authinfo->passwd, authinfo->ha1, &aut, req->sip_method, http_auth->pszCNonce, http_auth->iNonceCount); else i = __eXosip_create_proxy_authorization_header (http_auth->wa, uri, authinfo->userid, authinfo->passwd, authinfo->ha1, &aut, req->sip_method, http_auth->pszCNonce, http_auth->iNonceCount); osip_free (uri); if (i != 0) return -1; if (aut != NULL) { if (osip_strcasecmp(req->sip_method, "REGISTER")==0) osip_list_add (&req->authorizations, aut, -1); else osip_list_add (&req->proxy_authorizations, aut, -1); osip_message_force_update (req); } } } return 0; } pos = 0; osip_message_get_www_authenticate (last_response, pos, &wwwauth); osip_message_get_proxy_authenticate (last_response, pos, &proxyauth); if (wwwauth == NULL && proxyauth == NULL) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO2, NULL, "authinfo: No WWW-Authenticate or Proxy-Authenticate\n")); return -1; } while (wwwauth != NULL) { char *uri; authinfo = eXosip_find_authentication_info (req->from->url->username, wwwauth->realm); if (authinfo == NULL) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO2, NULL, "authinfo: No authentication found for %s %s\n", req->from->url->username, wwwauth->realm)); return -1; } i = osip_uri_to_str (req->req_uri, &uri); if (i != 0) return -1; i = __eXosip_create_authorization_header (wwwauth, uri, authinfo->userid, authinfo->passwd, authinfo->ha1, &aut, req->sip_method, "0a4f113b", 1); osip_free (uri); if (i != 0) return -1; if (aut != NULL) { osip_list_add (&req->authorizations, aut, -1); osip_message_force_update (req); } if (wwwauth->qop_options!=NULL) { if (osip_strcasecmp(req->sip_method, "REGISTER")==0 || osip_strcasecmp(req->sip_method, "INVITE")==0 || osip_strcasecmp(req->sip_method, "SUBSCRIBE")==0) _eXosip_store_nonce(req->call_id->number, wwwauth); else { osip_generic_param_t *to_tag=NULL; osip_from_param_get_byname (req->to, "tag", &to_tag); if (to_tag!=NULL) { /* if message is part of a dialog */ _eXosip_store_nonce(req->call_id->number, wwwauth); } } } pos++; osip_message_get_www_authenticate (last_response, pos, &wwwauth); } pos = 0; while (proxyauth != NULL) { char *uri; authinfo = eXosip_find_authentication_info (req->from->url->username, proxyauth->realm); if (authinfo == NULL) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO2, NULL, "authinfo: No authentication found for %s %s\n", req->from->url->username, proxyauth->realm)); return -1; } OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO1, NULL, "authinfo: %s\n", authinfo->username)); i = osip_uri_to_str (req->req_uri, &uri); if (i != 0) return -1; i = __eXosip_create_proxy_authorization_header (proxyauth, uri, authinfo->userid, authinfo->passwd, authinfo->ha1, &proxy_aut, req->sip_method, "0a4f113b", 1); osip_free (uri); if (i != 0) return -1; if (proxy_aut != NULL) { osip_list_add (&req->proxy_authorizations, proxy_aut, -1); osip_message_force_update (req); } if (proxyauth->qop_options!=NULL) { if (osip_strcasecmp(req->sip_method, "REGISTER")==0 || osip_strcasecmp(req->sip_method, "INVITE")==0 || osip_strcasecmp(req->sip_method, "SUBSCRIBE")==0) _eXosip_store_nonce(req->call_id->number, proxyauth); else { osip_generic_param_t *to_tag=NULL; osip_from_param_get_byname (req->to, "tag", &to_tag); if (to_tag!=NULL) { /* if message is part of a dialog */ _eXosip_store_nonce(req->call_id->number, proxyauth); } } } pos++; osip_message_get_proxy_authenticate (last_response, pos, &proxyauth); } return 0; }
int eXosip_call_terminate (int cid, int did) { int i; osip_transaction_t *tr; osip_message_t *request = NULL; eXosip_dialog_t *jd = NULL; eXosip_call_t *jc = NULL; if (did <= 0 && cid <= 0) return OSIP_BADPARAMETER; if (did > 0) { eXosip_call_dialog_find (did, &jc, &jd); if (jd == NULL) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: No call here?\n")); return OSIP_NOTFOUND; } } else { eXosip_call_find (cid, &jc); } if (jc == NULL) { return OSIP_NOTFOUND; } tr = eXosip_find_last_out_invite (jc, jd); if (jd != NULL && jd->d_dialog != NULL && jd->d_dialog->state == DIALOG_CONFIRMED) { /* don't send CANCEL on re-INVITE: send BYE instead */ } else if (tr != NULL && tr->last_response != NULL && MSG_IS_STATUS_1XX (tr->last_response)) { i = generating_cancel (&request, tr->orig_request); if (i != 0) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: cannot terminate this call!\n")); return i; } i = eXosip_create_cancel_transaction (jc, jd, request); if (i != 0) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: cannot initiate SIP transaction!\n")); return i; } if (jd != NULL) { osip_dialog_free (jd->d_dialog); jd->d_dialog = NULL; eXosip_update (); /* AMD 30/09/05 */ } return OSIP_SUCCESS; } if (jd == NULL || jd->d_dialog == NULL) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: No established dialog!\n")); return OSIP_WRONG_STATE; } if (tr == NULL) { /*this may not be enough if it's a re-INVITE! */ tr = eXosip_find_last_inc_invite (jc, jd); if (tr != NULL && tr->last_response != NULL && MSG_IS_STATUS_1XX (tr->last_response)) { /* answer with 603 */ osip_generic_param_t *to_tag; osip_from_param_get_byname (tr->orig_request->to, "tag", &to_tag); i = eXosip_call_send_answer (tr->transactionid, 603, NULL); if (to_tag == NULL) return i; } } if (jd->d_dialog == NULL) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: cannot terminate this call!\n")); return OSIP_WRONG_STATE; } i = generating_bye (&request, jd->d_dialog, eXosip.transport); if (i != 0) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: cannot terminate this call!\n")); return i; } eXosip_add_authentication_information (request, NULL); i = eXosip_create_transaction (jc, jd, request); if (i != 0) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: cannot initiate SIP transaction!\n")); return i; } osip_dialog_free (jd->d_dialog); jd->d_dialog = NULL; eXosip_update (); /* AMD 30/09/05 */ return OSIP_SUCCESS; }