📄 exosip.c
字号:
several credentials are needed */ eXosip_register_send_register (jr->r_id, NULL); jr->r_retry++; } } } }}voideXosip_update (){ static int static_id = 1; eXosip_call_t *jc;#ifndef MINISIZE eXosip_subscribe_t *js; eXosip_notify_t *jn;#endif eXosip_dialog_t *jd; time_t now; if (static_id > 100000) static_id = 1; /* loop */ now = time (NULL); for (jc = eXosip.j_calls; jc != NULL; jc = jc->next) { if (jc->c_id < 1) { jc->c_id = static_id; static_id++; } for (jd = jc->c_dialogs; jd != NULL; jd = jd->next) { if (jd->d_dialog != NULL) /* finished call */ { if (jd->d_id < 1) { jd->d_id = static_id; static_id++; } } else jd->d_id = -1; } }#ifndef MINISIZE for (js = eXosip.j_subscribes; js != NULL; js = js->next) { if (js->s_id < 1) { js->s_id = static_id; static_id++; } for (jd = js->s_dialogs; jd != NULL; jd = jd->next) { if (jd->d_dialog != NULL) /* finished call */ { if (jd->d_id < 1) { jd->d_id = static_id; static_id++; } } else jd->d_id = -1; } } for (jn = eXosip.j_notifies; jn != NULL; jn = jn->next) { if (jn->n_id < 1) { jn->n_id = static_id; static_id++; } for (jd = jn->n_dialogs; jd != NULL; jd = jd->next) { if (jd->d_dialog != NULL) /* finished call */ { if (jd->d_id < 1) { jd->d_id = static_id; static_id++; } } else jd->d_id = -1; } }#endif}static jauthinfo_t *eXosip_find_authentication_info (const char *username, const char *realm){ jauthinfo_t *fallback = NULL; jauthinfo_t *authinfo; for (authinfo = eXosip.authinfos; authinfo != NULL; authinfo = authinfo->next) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO3, NULL, "INFO: authinfo: %s %s\n", realm, authinfo->realm)); if (0 == strcmp (authinfo->username, username)) { if (authinfo->realm == NULL || authinfo->realm[0] == '\0') { fallback = authinfo; } else if (strcmp (realm, authinfo->realm) == 0 || 0 == strncmp (realm + 1, authinfo->realm, strlen (realm) - 2)) { return authinfo; } } } /* no matching username has been found for this realm, try with another username... */ for (authinfo = eXosip.authinfos; authinfo != NULL; authinfo = authinfo->next) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO3, NULL, "INFO: authinfo: %s %s\n", realm, authinfo->realm)); if ((authinfo->realm == NULL || authinfo->realm[0] == '\0') && fallback==NULL) { fallback = authinfo; } else if (strcmp (realm, authinfo->realm) == 0 || 0 == strncmp (realm + 1, authinfo->realm, strlen (realm) - 2)) { return authinfo; } } return fallback;}inteXosip_clear_authentication_info (){ jauthinfo_t *jauthinfo; for (jauthinfo = eXosip.authinfos; jauthinfo != NULL; jauthinfo = eXosip.authinfos) { REMOVE_ELEMENT (eXosip.authinfos, jauthinfo); osip_free (jauthinfo); } return 0;}inteXosip_add_authentication_info (const char *username, const char *userid, const char *passwd, const char *ha1, const char *realm){ jauthinfo_t *authinfos; if (username == NULL || username[0] == '\0') return -1; if (userid == NULL || userid[0] == '\0') return -1; if (passwd != NULL && passwd[0] != '\0') { } else if (ha1 != NULL && ha1[0] != '\0') { } else return -1; authinfos = (jauthinfo_t *) osip_malloc (sizeof (jauthinfo_t)); if (authinfos == NULL) return -1; memset (authinfos, 0, sizeof (jauthinfo_t)); snprintf (authinfos->username, 50, "%s", username); snprintf (authinfos->userid, 50, "%s", userid); if (passwd != NULL && passwd[0] != '\0') snprintf (authinfos->passwd, 50, "%s", passwd); else if (ha1 != NULL && ha1[0] != '\0') snprintf (authinfos->ha1, 50, "%s", ha1); if (realm != NULL && realm[0] != '\0') snprintf (authinfos->realm, 50, "%s", realm); ADD_ELEMENT (eXosip.authinfos, authinfos); return 0;}inteXosip_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;}inteXosip_update_top_via (osip_message_t * sip){ unsigned int number; char tmp[40]; osip_generic_param_t *br=NULL; osip_via_t *via = (osip_via_t *) osip_list_get (&sip->vias, 0); if (via==NULL) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "missing via in SIP message\n")); return -1; } /* browse parameter and replace "branch" */ osip_via_param_get_byname (via, "branch", &br); if (br==NULL || br->gvalue==NULL) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "missing branch parameter via in SIP message\n")); return -1; } osip_free(br->gvalue); number = osip_build_random_number (); sprintf (tmp, "z9hG4bK%u", number); br->gvalue = osip_strdup(tmp); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -