void GB_ResetConState(GB_CONNECT_STATE *gb_cons) { if (gb_cons == NULL) return; TRACE(SCI_TRACE_NORMAL,MOD_GB,"GB_ResetConState\n"); gb_cons->cur_state = GB_STATE_IDEL; gb_cons->connfd = -1; gb_cons->local_cseq = 1; gb_cons->bUnRegister = 0; if (gb_cons->wwwa) { osip_www_authenticate_free(gb_cons->wwwa); gb_cons->wwwa = NULL; } GB_reset_recv_buffer(gb_cons, 0); if(osip_list_size(&(gb_cons->record_node_list)) > 0) { GB_reset_Record_Node_list(gb_cons); } osip_list_init(&(gb_cons->record_node_list)); gb_cons->keepalive_timeout_cnt = 0; gb_cons->last_keepalivetime = 0; gb_cons->last_sendtime = 0; gb_cons->last_registertime = 0; return ; }
int main (int argc, char **argv) { FILE *wwwauthenticates_file; osip_www_authenticate_t *wwwauthenticate; char *a_wwwauthenticate; char *dest; char *res; wwwauthenticates_file = fopen (argv[1], "r"); if (wwwauthenticates_file == NULL) { fprintf (stdout, "Failed to open %s file.\nUsage: twwwauthenticate wwwauthenticates.txt\n", argv[1]); exit (0); } a_wwwauthenticate = (char *) osip_malloc (200); res = fgets (a_wwwauthenticate, 200, wwwauthenticates_file); /* lines are under 200 */ while (res != NULL) { int errcode; /* remove the last '\n' before parsing */ strncpy (a_wwwauthenticate + strlen (a_wwwauthenticate) - 1, "\0", 1); if (0 != strncmp (a_wwwauthenticate, "#", 1)) { /* allocate & init wwwauthenticate */ osip_www_authenticate_init (&wwwauthenticate); printf ("=================================================\n"); printf ("WWWAUTHENTICATE TO PARSE: |%s|\n", a_wwwauthenticate); errcode = osip_www_authenticate_parse (wwwauthenticate, a_wwwauthenticate); if (errcode != -1) { if (osip_www_authenticate_to_str (wwwauthenticate, &dest) != -1) { printf ("result: |%s|\n", dest); osip_free (dest); } } else printf ("Bad wwwauthenticate format: %s\n", a_wwwauthenticate); osip_www_authenticate_free (wwwauthenticate); printf ("=================================================\n"); } res = fgets (a_wwwauthenticate, 200, wwwauthenticates_file); /* lines are under 200 */ } osip_free (a_wwwauthenticate); return 0; }
/* returns -1 on error. */ int osip_message_set_www_authenticate (osip_message_t * sip, const char *hvalue) { osip_www_authenticate_t *www_authenticate; int i; if (hvalue == NULL || hvalue[0] == '\0') return OSIP_SUCCESS; if (sip == NULL) return OSIP_BADPARAMETER; i = osip_www_authenticate_init (&www_authenticate); if (i != 0) return i; i = osip_www_authenticate_parse (www_authenticate, hvalue); if (i != 0) { osip_www_authenticate_free (www_authenticate); return i; } sip->message_property = 2; osip_list_add (&sip->www_authenticates, www_authenticate, -1); return OSIP_SUCCESS; }
int osip_www_authenticate_clone (const osip_www_authenticate_t * wwwa, osip_www_authenticate_t ** dest) { int i; osip_www_authenticate_t *wa; *dest = NULL; if (wwwa == NULL) return OSIP_BADPARAMETER; if (wwwa->auth_type == NULL) return OSIP_BADPARAMETER; i = osip_www_authenticate_init (&wa); if (i != 0) /* allocation failed */ return i; wa->auth_type = osip_strdup (wwwa->auth_type); if (wa->auth_type == NULL && wwwa->auth_type != NULL) { osip_www_authenticate_free (wa); return OSIP_NOMEM; } if (wwwa->realm != NULL) wa->realm = osip_strdup (wwwa->realm); if (wa->realm == NULL && wwwa->realm != NULL) { osip_www_authenticate_free (wa); return OSIP_NOMEM; } if (wwwa->domain != NULL) wa->domain = osip_strdup (wwwa->domain); if (wa->domain == NULL && wwwa->domain != NULL) { osip_www_authenticate_free (wa); return OSIP_NOMEM; } if (wwwa->nonce != NULL) wa->nonce = osip_strdup (wwwa->nonce); if (wa->nonce == NULL && wwwa->nonce != NULL) { osip_www_authenticate_free (wa); return OSIP_NOMEM; } if (wwwa->opaque != NULL) wa->opaque = osip_strdup (wwwa->opaque); if (wa->opaque == NULL && wwwa->opaque != NULL) { osip_www_authenticate_free (wa); return OSIP_NOMEM; } if (wwwa->stale != NULL) wa->stale = osip_strdup (wwwa->stale); if (wa->stale == NULL && wwwa->stale != NULL) { osip_www_authenticate_free (wa); return OSIP_NOMEM; } if (wwwa->algorithm != NULL) wa->algorithm = osip_strdup (wwwa->algorithm); if (wa->algorithm == NULL && wwwa->algorithm != NULL) { osip_www_authenticate_free (wa); return OSIP_NOMEM; } if (wwwa->qop_options != NULL) wa->qop_options = osip_strdup (wwwa->qop_options); if (wa->qop_options == NULL && wwwa->qop_options != NULL) { osip_www_authenticate_free (wa); return OSIP_NOMEM; } if (wwwa->version != NULL) wa->version = osip_strdup (wwwa->version); if (wa->version==NULL && wwwa->version!=NULL) { osip_www_authenticate_free (wa); return OSIP_NOMEM; } if (wwwa->targetname != NULL) wa->targetname = osip_strdup (wwwa->targetname); if (wa->targetname==NULL && wwwa->targetname!=NULL) { osip_www_authenticate_free (wa); return OSIP_NOMEM; } if (wwwa->gssapi_data != NULL) wa->gssapi_data = osip_strdup (wwwa->gssapi_data); if (wa->gssapi_data==NULL && wwwa->gssapi_data!=NULL) { osip_www_authenticate_free (wa); return OSIP_NOMEM; } *dest = wa; return OSIP_SUCCESS; }
int GB_handle_RCV_STATUS_4XX(GB_CONNECT_STATE *gb_cons, osip_event_t * osip_event) { if(gb_cons == NULL || osip_event == NULL || osip_event->sip == NULL) { return -1; } switch(osip_event->sip->status_code) { case 401: // 未授权 { if(gb_cons->cur_state == GB_STATE_REGISTER) { osip_www_authenticate_t * wwwa; if(gb_cons->wwwa != NULL) { TRACE(SCI_TRACE_NORMAL,MOD_GB,"%s line=%d Unauthorized, Please Check Carefully!\n",__FUNCTION__,__LINE__); } wwwa = osip_list_get (&osip_event->sip->www_authenticates, 0); if (wwwa != NULL) { osip_www_authenticate_free(gb_cons->wwwa); osip_www_authenticate_clone(wwwa, &gb_cons->wwwa); GB_sipd_register_auth(gb_cons, 0); // 带认证的注册请求 gb_cons->last_sendtime = get_cur_time()/1000; } } else if(gb_cons->cur_state == GB_STATE_RUNNING && gb_cons->bUnRegister == 1) { osip_www_authenticate_t * wwwa; wwwa = osip_list_get (&osip_event->sip->www_authenticates, 0); if (wwwa != NULL) { osip_www_authenticate_free(gb_cons->wwwa); osip_www_authenticate_clone(wwwa, &gb_cons->wwwa); GB_sipd_register_auth(gb_cons, 1); // 带认证的注销请求 gb_cons->last_sendtime = get_cur_time()/1000; } } } break; case 403: // 禁止 { // 重新认证 if(gb_cons->cur_state == GB_STATE_RUNNING && gb_cons->bUnRegister == 0) { close(gb_cons->connfd); GB_ResetConState(gb_cons); GB_Refresh_GBCfg(); GB_Set_gGBConnStatus(0); TRACE(SCI_TRACE_NORMAL,MOD_GB,"%s line=%d Get 403 err, Register again\n",__FUNCTION__,__LINE__); } } break; default: TRACE(SCI_TRACE_NORMAL,MOD_GB,"Can't handle sip->status_code=%d message\n",osip_event->sip->status_code); break; } return 0; }
int GB_handle_RCV_STATUS_2XX(GB_CONNECT_STATE *gb_cons, osip_event_t * osip_event) { GB_Record_Node *record = NULL; int index = -1; if(gb_cons == NULL || osip_event == NULL || osip_event->sip == NULL || osip_event->sip->call_id == NULL) { return -1; } record = GB_Find_Record_Node_by_Call_ID(gb_cons,osip_event->sip->call_id ,&index); if(record != NULL) { switch(record->cmd) { case gb_CommandType_KeepAlive: { gb_cons->keepalive_timeout_cnt = 0; } break; default: { TRACE(SCI_TRACE_NORMAL,MOD_GB,"Get 200 OK, But do nothing\n"); } break; } GB_Remove_Record_Node(gb_cons, index); } else { if(gb_cons->cur_state == GB_STATE_REGISTER) { gb_cons->cur_state = GB_STATE_RUNNING; // 注册成功 if (gb_cons->wwwa) { osip_www_authenticate_free(gb_cons->wwwa); gb_cons->wwwa = NULL; } gb_cons->last_registertime = gb_cons->last_keepalivetime = get_cur_time()/1000; GB_Set_gGBConnStatus(1); TRACE(SCI_TRACE_NORMAL,MOD_GB,"%s line=%d REGISTER Success!\n",__FUNCTION__,__LINE__); // GB_Change_Mode(0); } else if(gb_cons->cur_state == GB_STATE_RUNNING && gb_cons->bUnRegister == 1) { if (gb_cons->wwwa) { osip_www_authenticate_free(gb_cons->wwwa); gb_cons->wwwa = NULL; } close(gb_cons->connfd); GB_ResetConState(gb_cons); GB_Refresh_GBCfg(); GB_Set_gGBConnStatus(0); TRACE(SCI_TRACE_NORMAL,MOD_GB,"%s line=%d UNREGISTER Success!\n",__FUNCTION__,__LINE__); } } return 0; }
void osip_message_free (osip_message_t * sip) { int pos = 0; if (sip == NULL) return; osip_free (sip->sip_method); osip_free (sip->sip_version); if (sip->req_uri != NULL) { osip_uri_free (sip->req_uri); } osip_free (sip->reason_phrase); { osip_accept_t *accept; while (!osip_list_eol (&sip->accepts, pos)) { accept = (osip_accept_t *) osip_list_get (&sip->accepts, pos); osip_list_remove (&sip->accepts, pos); osip_accept_free (accept); } } { osip_accept_encoding_t *accept_encoding; while (!osip_list_eol (&sip->accept_encodings, pos)) { accept_encoding = (osip_accept_encoding_t *) osip_list_get (&sip->accept_encodings, pos); osip_list_remove (&sip->accept_encodings, pos); osip_accept_encoding_free (accept_encoding); } } { osip_accept_language_t *accept_language; while (!osip_list_eol (&sip->accept_languages, pos)) { accept_language = (osip_accept_language_t *) osip_list_get (&sip->accept_languages, pos); osip_list_remove (&sip->accept_languages, pos); osip_accept_language_free (accept_language); } } { osip_alert_info_t *alert_info; while (!osip_list_eol (&sip->alert_infos, pos)) { alert_info = (osip_alert_info_t *) osip_list_get (&sip->alert_infos, pos); osip_list_remove (&sip->alert_infos, pos); osip_alert_info_free (alert_info); } } { osip_allow_t *al; while (!osip_list_eol (&sip->allows, pos)) { al = (osip_allow_t *) osip_list_get (&sip->allows, pos); osip_list_remove (&sip->allows, pos); osip_allow_free (al); } } { osip_authentication_info_t *al; while (!osip_list_eol (&sip->authentication_infos, pos)) { al = (osip_authentication_info_t *) osip_list_get (&sip-> authentication_infos, pos); osip_list_remove (&sip->authentication_infos, pos); osip_authentication_info_free (al); } } { osip_authorization_t *al; while (!osip_list_eol (&sip->authorizations, pos)) { al = (osip_authorization_t *) osip_list_get (&sip->authorizations, pos); osip_list_remove (&sip->authorizations, pos); osip_authorization_free (al); } } if (sip->call_id != NULL) { osip_call_id_free (sip->call_id); } { osip_call_info_t *call_info; while (!osip_list_eol (&sip->call_infos, pos)) { call_info = (osip_call_info_t *) osip_list_get (&sip->call_infos, pos); osip_list_remove (&sip->call_infos, pos); osip_call_info_free (call_info); } } { osip_contact_t *contact; while (!osip_list_eol (&sip->contacts, pos)) { contact = (osip_contact_t *) osip_list_get (&sip->contacts, pos); osip_list_remove (&sip->contacts, pos); osip_contact_free (contact); } } { osip_content_encoding_t *ce; while (!osip_list_eol (&sip->content_encodings, pos)) { ce = (osip_content_encoding_t *) osip_list_get (&sip->content_encodings, pos); osip_list_remove (&sip->content_encodings, pos); osip_content_encoding_free (ce); } } if (sip->content_length != NULL) { osip_content_length_free (sip->content_length); } if (sip->content_type != NULL) { osip_content_type_free (sip->content_type); } if (sip->cseq != NULL) { osip_cseq_free (sip->cseq); } { osip_error_info_t *error_info; while (!osip_list_eol (&sip->error_infos, pos)) { error_info = (osip_error_info_t *) osip_list_get (&sip->error_infos, pos); osip_list_remove (&sip->error_infos, pos); osip_error_info_free (error_info); } } if (sip->from != NULL) { osip_from_free (sip->from); } if (sip->mime_version != NULL) { osip_mime_version_free (sip->mime_version); } { osip_proxy_authenticate_t *al; while (!osip_list_eol (&sip->proxy_authenticates, pos)) { al = (osip_proxy_authenticate_t *) osip_list_get (&sip-> proxy_authenticates, pos); osip_list_remove (&sip->proxy_authenticates, pos); osip_proxy_authenticate_free (al); } } { osip_proxy_authentication_info_t *al; while (!osip_list_eol (&sip->proxy_authentication_infos, pos)) { al = (osip_proxy_authentication_info_t *) osip_list_get (&sip-> proxy_authentication_infos, pos); osip_list_remove (&sip->proxy_authentication_infos, pos); osip_proxy_authentication_info_free (al); } } { osip_proxy_authorization_t *proxy_authorization; while (!osip_list_eol (&sip->proxy_authorizations, pos)) { proxy_authorization = (osip_proxy_authorization_t *) osip_list_get (&sip-> proxy_authorizations, pos); osip_list_remove (&sip->proxy_authorizations, pos); osip_proxy_authorization_free (proxy_authorization); } } { osip_record_route_t *record_route; while (!osip_list_eol (&sip->record_routes, pos)) { record_route = (osip_record_route_t *) osip_list_get (&sip->record_routes, pos); osip_list_remove (&sip->record_routes, pos); osip_record_route_free (record_route); } } { osip_route_t *route; while (!osip_list_eol (&sip->routes, pos)) { route = (osip_route_t *) osip_list_get (&sip->routes, pos); osip_list_remove (&sip->routes, pos); osip_route_free (route); } } if (sip->to != NULL) { osip_to_free (sip->to); } { osip_via_t *via; while (!osip_list_eol (&sip->vias, pos)) { via = (osip_via_t *) osip_list_get (&sip->vias, pos); osip_list_remove (&sip->vias, pos); osip_via_free (via); } } { osip_www_authenticate_t *al; while (!osip_list_eol (&sip->www_authenticates, pos)) { al = (osip_www_authenticate_t *) osip_list_get (&sip->www_authenticates, pos); osip_list_remove (&sip->www_authenticates, pos); osip_www_authenticate_free (al); } } { osip_header_t *header; while (!osip_list_eol (&sip->headers, pos)) { header = (osip_header_t *) osip_list_get (&sip->headers, pos); osip_list_remove (&sip->headers, pos); osip_header_free (header); } } { osip_body_t *body; while (!osip_list_eol (&sip->bodies, pos)) { body = (osip_body_t *) osip_list_get (&sip->bodies, pos); osip_list_remove (&sip->bodies, pos); osip_body_free (body); } } osip_free (sip->message); osip_free (sip); }