📄 exosip.c
字号:
} 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) { if (realm != NULL && authinfo->realm != NULL) OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO3, NULL, "INFO: authinfo: %s %s\n", realm, authinfo->realm)); if (0 == osip_strcasecmp (authinfo->username, username)) { if (authinfo->realm == NULL || authinfo->realm[0] == '\0') { fallback = authinfo; } else if (realm == NULL || osip_strcasecmp (realm, authinfo->realm) == 0 || 0 == osip_strncasecmp (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) { if (realm != NULL && authinfo->realm != NULL) 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 (realm == NULL || osip_strcasecmp (realm, authinfo->realm) == 0 || 0 == osip_strncasecmp (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 OSIP_SUCCESS;}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 OSIP_BADPARAMETER; if (userid == NULL || userid[0] == '\0') return OSIP_BADPARAMETER; if (passwd != NULL && passwd[0] != '\0') { } else if (ha1 != NULL && ha1[0] != '\0') { } else return OSIP_BADPARAMETER; authinfos = (jauthinfo_t *) osip_malloc (sizeof (jauthinfo_t)); if (authinfos == NULL) return OSIP_NOMEM; 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 OSIP_SUCCESS;}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 OSIP_BADPARAMETER; } 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) { if (http_auth->wa->realm != 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 OSIP_NOTFOUND; } i = osip_uri_to_str (req->req_uri, &uri); if (i != 0) return i; http_auth->iNonceCount++; if (http_auth->answer_code == 401) /*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 i; 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 OSIP_SUCCESS; } 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 OSIP_SYNTAXERROR; } while (wwwauth != NULL) { char *uri; authinfo = eXosip_find_authentication_info (req->from->url->username, wwwauth->realm); if (authinfo == NULL) { if (wwwauth->realm != 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 OSIP_NOTFOUND; } i = osip_uri_to_str (req->req_uri, &uri); if (i != 0) return i; 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 i; if (aut != NULL) { osip_list_add (&req->authorizations, aut, -1); osip_message_force_update (req); }#if defined(AVOID_REFRESH_WITHOUT_CREDENTIAL) if (wwwauth->qop_options != NULL) {#endif 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, 401); 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, 401); } }#if defined(AVOID_REFRESH_WITHOUT_CREDENTIAL) }#endif 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) { if (proxyauth->realm != 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 OSIP_NOTFOUND; } 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 i; 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 i; if (proxy_aut != NULL) { osip_list_add (&req->proxy_authorizations, proxy_aut, -1); osip_message_force_update (req); }#if defined(AVOID_REFRESH_WITHOUT_CREDENTIAL) if (proxyauth->qop_options != NULL) {#endif 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, 407); 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, 407); } }#if defined(AVOID_REFRESH_WITHOUT_CREDENTIAL) }#endif pos++; osip_message_get_proxy_authenticate (last_response, pos, &proxyauth); } return OSIP_SUCCESS;}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 OSIP_SYNTAXERROR; } /* 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 OSIP_SYNTAXERROR; } osip_free (br->gvalue); number = osip_build_random_number (); sprintf (tmp, "z9hG4bK%u", number); br->gvalue = osip_strdup (tmp); return OSIP_SUCCESS;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -