📄 exosip.c
字号:
if (jd->d_id >= 1) { osip_transaction_t *out_tr = NULL; out_tr = osip_list_get (jd->d_out_trs, 0); if (out_tr != NULL && (out_tr->state == NICT_TERMINATED || out_tr->state == NICT_COMPLETED) && now - out_tr->birth_time < 120 && out_tr->orig_request != NULL && out_tr->last_response != NULL && (out_tr->last_response->status_code == 401 || out_tr->last_response->status_code == 407)) { /* retry with credential */ if (jd->d_retry < 3) { int i; i = _eXosip_insubscription_send_request_with_credential (jn, jd, out_tr); if (i != 0) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: could not clone notify for authentication\n")); } jd->d_retry++; } } } } } } for (jr = eXosip.j_reg; jr != NULL; jr = jr->next) { if (jr->r_id >= 1 && jr->r_last_tr != NULL) { if (jr->r_reg_period != 0 && now - jr->r_last_tr->birth_time > 900) { /* automatic refresh */ eXosip_register_send_register (jr->r_id, NULL); } else if (jr->r_reg_period != 0 && now - jr->r_last_tr->birth_time > jr->r_reg_period - 60) { /* automatic refresh */ eXosip_register_send_register (jr->r_id, NULL); } else if (jr->r_reg_period != 0 && now - jr->r_last_tr->birth_time > 120 && (jr->r_last_tr->last_response == NULL || (!MSG_IS_STATUS_2XX (jr->r_last_tr->last_response)))) { /* automatic refresh */ eXosip_register_send_register (jr->r_id, NULL); } else if (now - jr->r_last_tr->birth_time < 120 && jr->r_last_tr->orig_request != NULL && (jr->r_last_tr->last_response != NULL && (jr->r_last_tr->last_response->status_code == 401 || jr->r_last_tr->last_response->status_code == 407))) { if (jr->r_retry < 3) { /* TODO: improve support for several retries when 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; eXosip_subscribe_t *js; eXosip_notify_t *jn; 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; } } 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; } }}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 = 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; } 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 (last_response, uri, authinfo->userid, authinfo->passwd, authinfo->ha1, &aut, req->sip_method); osip_free (uri); if (i != 0) return -1; if (aut != NULL) { osip_list_add (&req->authorizations, aut, -1); osip_message_force_update (req); } 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 (last_response, uri, authinfo->userid, authinfo->passwd, authinfo->ha1, &proxy_aut, req->sip_method); 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); } 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 + -