static int sip_login_do_login(SipSetupContext * ctx, const char *uri, const char *passwd){ LinphoneProxyConfig *cfg=sip_setup_context_get_proxy_config(ctx); LinphoneCore *lc=linphone_proxy_config_get_core(cfg); LinphoneAuthInfo *auth; osip_from_t *parsed_uri; char *tmp; osip_from_init(&parsed_uri); osip_from_parse(parsed_uri,uri); if (parsed_uri->displayname==NULL || strlen(parsed_uri->displayname)==0){ guess_display_name(parsed_uri); } osip_from_to_str(parsed_uri,&tmp); linphone_proxy_config_set_identity(cfg,tmp); if (passwd ) { auth=linphone_auth_info_new(parsed_uri->url->username,NULL,passwd,NULL,NULL); linphone_core_add_auth_info(lc,auth); } linphone_proxy_config_enable_register(cfg,TRUE); linphone_proxy_config_done(cfg); osip_free(tmp); osip_from_free(parsed_uri); ms_message("SipLogin: done"); return 0; }
void _eXosip_subscribe_free (struct eXosip_t *excontext, eXosip_subscribe_t * js) { /* ... */ eXosip_dialog_t *jd; if (js->s_inc_tr != NULL && js->s_inc_tr->orig_request != NULL && js->s_inc_tr->orig_request->call_id != NULL && js->s_inc_tr->orig_request->call_id->number != NULL) _eXosip_delete_nonce (excontext, js->s_inc_tr->orig_request->call_id->number); else if (js->s_out_tr != NULL && js->s_out_tr->orig_request != NULL && js->s_out_tr->orig_request->call_id != NULL && js->s_out_tr->orig_request->call_id->number != NULL) _eXosip_delete_nonce (excontext, js->s_out_tr->orig_request->call_id->number); for (jd = js->s_dialogs; jd != NULL; jd = js->s_dialogs) { REMOVE_ELEMENT (js->s_dialogs, jd); _eXosip_dialog_free (excontext, jd); } _eXosip_delete_reserved (js->s_inc_tr); _eXosip_delete_reserved (js->s_out_tr); if (js->s_inc_tr != NULL) osip_list_add (&excontext->j_transactions, js->s_inc_tr, 0); if (js->s_out_tr != NULL) osip_list_add (&excontext->j_transactions, js->s_out_tr, 0); osip_free (js); }
int sdp_message_clone (sdp_message_t * sdp, sdp_message_t ** dest) { int i; char *body; i = sdp_message_init (dest); if (i != 0) return -1; i = sdp_message_to_str (sdp, &body); if (i != 0) goto error_sc1; i = sdp_message_parse (*dest, body); osip_free (body); if (i != 0) goto error_sc1; return 0; error_sc1: sdp_message_free (*dest); return -1; }
int main(int argc, char **argv) { FILE *froms_file; osip_from_t *from; char *a_from; char *dest; char *res; froms_file = fopen(argv[1], "r"); if (froms_file == NULL) { fprintf(stdout, "Failed to open %s file.\nUsage: tfrom froms.txt\n", argv[1]); exit(0); } a_from = (char *) osip_malloc(200); res = fgets(a_from, 200, froms_file); /* lines are under 200 */ while (res != NULL) { int errcode; /* remove the last '\n' before parsing */ strncpy(a_from + strlen(a_from) - 1, "\0", 1); if (0 != strncmp(a_from, "#", 1)) { /* allocate & init from */ osip_from_init(&from); printf("=================================================\n"); printf("FROM TO PARSE: |%s|\n", a_from); errcode = osip_from_parse(from, a_from); if (errcode != -1) { if (osip_from_to_str(from, &dest) != -1) { printf("result: |%s|\n", dest); osip_free(dest); } } else printf("Bad from format: %s\n", a_from); osip_from_free(from); printf("=================================================\n"); } res = fgets(a_from, 200, froms_file); /* lines are under 200 */ } osip_free(a_from); return 0; }
int main(int argc, char **argv) { FILE *callids_file; osip_call_id_t *callid; char *a_callid; char *dest; char *res; callids_file = fopen(argv[1], "r"); if (callids_file == NULL) { fprintf(stdout, "Failed to open %s file.\nUsage: tcallid callids.txt\n", argv[1]); exit(0); } a_callid = (char *) osip_malloc(200); res = fgets(a_callid, 200, callids_file); /* lines are under 200 */ while (res != NULL) { int errcode; /* remove the last '\n' before parsing */ strncpy(a_callid + strlen(a_callid) - 1, "\0", 1); if (0 != strncmp(a_callid, "#", 1)) { /* allocate & init callid */ osip_call_id_init(&callid); printf("=================================================\n"); printf("CALLID TO PARSE: |%s|\n", a_callid); errcode = osip_call_id_parse(callid, a_callid); if (errcode != -1) { if (osip_call_id_to_str(callid, &dest) != -1) { printf("result: |%s|\n", dest); osip_free(dest); } } else printf("Bad callid format: %s\n", a_callid); osip_call_id_free(callid); printf("=================================================\n"); } res = fgets(a_callid, 200, callids_file); /* lines are under 200 */ } osip_free(a_callid); return 0; }
int __osip_nist_init (osip_nist_t ** nist, osip_t * osip, osip_message_t * invite) { int i; OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO2, NULL, "allocating NIST context\n")); *nist = (osip_nist_t *) osip_malloc (sizeof (osip_nist_t)); if (*nist == NULL) return OSIP_NOMEM; memset (*nist, 0, sizeof (osip_nist_t)); /* for INVITE retransmissions */ { osip_via_t *via; char *proto; i = osip_message_get_via (invite, 0, &via); /* get top via */ if (i < 0) { osip_free (*nist); *nist=NULL; return i; } proto = via_get_protocol (via); if (proto == NULL) { osip_free (*nist); *nist=NULL; return OSIP_UNDEFINED_ERROR; } if (osip_strcasecmp (proto, "TCP") != 0 && osip_strcasecmp (proto, "TLS") != 0 && osip_strcasecmp (proto, "SCTP") != 0) { (*nist)->timer_j_length = 64 * DEFAULT_T1; (*nist)->timer_j_start.tv_sec = -1; /* not started */ } else { /* reliable protocol is used: */ (*nist)->timer_j_length = 0; /* MUST do the transition immediatly */ (*nist)->timer_j_start.tv_sec = -1; /* not started */ } } return OSIP_SUCCESS; }
void aiptv_log_message(osip_message_t *sip_message) { char *dest = NULL; size_t length = 0; osip_message_to_str (sip_message, &dest, &length); aiptv_log(dest); osip_free(dest); }
void groups_ctx_free() { if (groups_context==NULL) return; osip_free(groups_context); groups_context = NULL; }
void eXosip_msg_free(eXosip_msg_t *jm) { __eXosip_delete_jinfo(jm->m_last_tr); if (jm->m_last_tr!=NULL) owsip_list_add_nodup(eXosip.j_transactions, jm->m_last_tr, 0); osip_free(jm); }
/* returns null on error. */ int osip_content_type_to_str(const osip_content_type_t * content_type, char **dest) { char *buf; char *tmp; size_t len; *dest = NULL; if ((content_type == NULL) || (content_type->type == NULL) || (content_type->subtype == NULL)) return OSIP_BADPARAMETER; /* try to guess a long enough length */ len = strlen(content_type->type) + strlen(content_type->subtype) + 4 /* for '/', ' ', ';' and '\0' */ + 10 * osip_list_size(&content_type->gen_params); buf = (char *) osip_malloc(len); if (buf == NULL) return OSIP_NOMEM; tmp = buf; sprintf(tmp, "%s/%s", content_type->type, content_type->subtype); tmp = tmp + strlen(tmp); { int pos = 0; osip_generic_param_t *u_param; #if 0 if (!osip_list_eol(content_type->gen_params, pos)) { /* needed for cannonical form! (authentication issue of rfc2543) */ sprintf(tmp, " "); tmp++; } #endif while (!osip_list_eol(&content_type->gen_params, pos)) { size_t tmp_len; u_param = (osip_generic_param_t *) osip_list_get(&content_type->gen_params, pos); if (u_param->gvalue == NULL) { osip_free(buf); return OSIP_SYNTAXERROR; } tmp_len = strlen(buf) + 4 + strlen(u_param->gname) + strlen(u_param->gvalue) + 1; if (len < tmp_len) { buf = osip_realloc(buf, tmp_len); len = tmp_len; tmp = buf + strlen(buf); } snprintf(tmp, len - (tmp - buf), "; %s=%s", u_param->gname, u_param->gvalue); tmp = tmp + strlen(tmp); pos++; } } *dest = buf; return OSIP_SUCCESS; }
/* * SIP_GEN_RESPONSE * * send an proxy generated response back to the client. * Only errors are reported from the proxy itself. * code = SIP result code to deliver * * RETURNS * STS_SUCCESS on success * STS_FAILURE on error */ int sip_gen_response(sip_ticket_t *ticket, int code) { osip_message_t *response; int sts; osip_via_t *via; int port; char *buffer; size_t buflen; struct in_addr addr; /* create the response template */ if ((response=msg_make_template_reply(ticket, code))==NULL) { ERROR("sip_gen_response: error in msg_make_template_reply"); return STS_FAILURE; } /* we must check if first via has x.x.x.x address. If not, we must resolve it */ osip_message_get_via (response, 0, &via); if (via == NULL) { ERROR("sip_gen_response: Cannot send response - no via field"); return STS_FAILURE; } /* name resolution */ if (utils_inet_aton(via->host, &addr) == 0) { /* need name resolution */ DEBUGC(DBCLASS_DNS,"resolving name:%s",via->host); sts = get_ip_by_host(via->host, &addr); if (sts == STS_FAILURE) { DEBUGC(DBCLASS_PROXY, "sip_gen_response: cannot resolve via [%s]", via->host); return STS_FAILURE; } } sts = sip_message_to_str(response, &buffer, &buflen); if (sts != 0) { ERROR("sip_gen_response: msg_2char failed"); return STS_FAILURE; } if (via->port) { port=atoi(via->port); } else { port=SIP_PORT; } /* send to destination */ sipsock_send(addr, port, ticket->protocol, buffer, buflen); /* free the resources */ osip_message_free(response); osip_free(buffer); return STS_SUCCESS; }
int osip_dialog_match_as_uas (osip_dialog_t * dlg, osip_message_t * request) { osip_generic_param_t *tag_param_remote; int i; char *tmp; osip_call_id_to_str (request->call_id, &tmp); if (0 != strcmp (dlg->call_id, tmp)) { osip_free (tmp); return -1; } osip_free (tmp); /* for INCOMING REQUEST: To: local_uri;local_tag <- LOCAL TAG ALWAYS EXIST From: remote_uri;remote_tag */ if (dlg->local_tag == NULL) /* NOT POSSIBLE BECAUSE I MANAGE REMOTE_TAG AND I ALWAYS ADD IT! */ return -1; i = osip_from_get_tag (request->from, &tag_param_remote); if (i != 0 && dlg->remote_tag != NULL) /* no tag in request but tag in dialog */ return -1; /* impossible... */ if (i != 0 && dlg->remote_tag == NULL) /* no tag in request AND no tag in dialog */ { if (0 == osip_from_compare ((osip_from_t *) dlg->remote_uri, (osip_from_t *) request->from) && 0 == osip_from_compare (dlg->local_uri, request->to)) return 0; return -1; } /* we don't have to compare remote_uri with from && local_uri with to. ----> we have both tag recognized, it's enough.. */ if (0 == strcmp (tag_param_remote->gvalue, dlg->remote_tag)) return 0; return -1; }
void osip_uri_free (osip_uri_t * url) { int pos = 0; if (url == NULL) return; osip_free (url->scheme); osip_free (url->username); osip_free (url->password); osip_free (url->host); osip_free (url->port); osip_uri_param_freelist (&url->url_params); { osip_uri_header_t *u_header; while (!osip_list_eol (&url->url_headers, pos)) { u_header = (osip_uri_header_t *) osip_list_get (&url->url_headers, pos); osip_list_remove (&url->url_headers, pos); osip_uri_header_free (u_header); } } osip_free (url->string); osip_free (url); }
static int strcat_simple_header (char **_string, size_t * malloc_size, char **_message, void *ptr_header, char *header_name, size_t size_of_header, int (*xxx_to_str) (void *, char **), char **next) { char *string; char *message; char *tmp; int i; string = *_string; message = *_message; if (ptr_header != NULL) { if (*malloc_size < message - string + 100 + size_of_header) /* take some memory avoid to osip_realloc too much often */ { /* should not happen often */ size_t size = message - string; *malloc_size = message - string + size_of_header + 100; string = osip_realloc (string, *malloc_size); if (string == NULL) { *_string = NULL; *_message = NULL; return OSIP_NOMEM; } message = string + size; } message = osip_strn_append (message, header_name, size_of_header); i = xxx_to_str (ptr_header, &tmp); if (i != 0) { *_string = string; *_message = message; *next = NULL; return i; } if (*malloc_size < message - string + strlen (tmp) + 100) { size_t size = message - string; *malloc_size = message - string + strlen (tmp) + 100; string = osip_realloc (string, *malloc_size); if (string == NULL) { *_string = NULL; *_message = NULL; return OSIP_NOMEM; } message = string + size; } message = osip_str_append (message, tmp); osip_free (tmp); message = osip_strn_append (message, CRLF, 2); } *_string = string; *_message = message; *next = message; return OSIP_SUCCESS; }
PPL_DECLARE (int) ppl_pipe_close (ppl_pipe_t * apipe) { if (apipe == NULL) return -1; ppl_socket_close (apipe->pipes[0]); ppl_socket_close (apipe->pipes[1]); osip_free (apipe); return 0; }
int jpipe_close (jpipe_t * apipe) { if (apipe == NULL) return -1; close (apipe->pipes[0]); close (apipe->pipes[1]); osip_free (apipe); return 0; }
int jpipe_close(jpipe_t * apipe) { if (apipe == NULL) return OSIP_BADPARAMETER; close(apipe->pipes[0]); close(apipe->pipes[1]); osip_free(apipe); return OSIP_SUCCESS; }
void osip_negotiation_ctx_free (osip_negotiation_ctx_t * con) { if (con == NULL) return; sdp_message_free (con->remote); sdp_message_free (con->local); osip_free (con); }
void ls_localdb_ctx_free () { if (ls_localdb_context == NULL) return; osip_free (ls_localdb_context); ls_localdb_context = NULL; }
void osip_mutex_destroy (struct osip_mutex *_mut) { osip_mutex_t *mut = (osip_mutex_t *) _mut; if (mut == NULL) return; CloseHandle (mut->h); osip_free (mut); }
void tlp_plugin_free (tlp_plugin_t * plug) { if (plug == NULL) return; psp_plugin_free (plug->psp_plugin); /* THIS IS NOT A DYMAMIC ELEMENT!! + THIS IS ATTACHED TO SEVERAL PSP_PLUGIN... so the next line will never be called osip_free(plug->psp_plugin); */ /* Already closed by the plugin itself. if (plug->in_socket != -1) ppl_socket_close (plug->in_socket); */ plug->in_socket = -1; osip_free (plug->rcv_func); osip_free (plug->snd_func); osip_free (plug); }
int __osip_ist_free (osip_ist_t * ist) { if (ist == NULL) return OSIP_SUCCESS; OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO2, NULL, "free ist resource\n")); osip_free (ist); return OSIP_SUCCESS; }
void osip_mutex_destroy (struct osip_mutex *_mut) { osip_mutex_t *mut = (osip_mutex_t *) _mut; if (mut == NULL) return; pthread_mutex_destroy (mut); osip_free (mut); }
int osip_sem_destroy (struct osip_sem *_sem) { osip_sem_t *sem = (osip_sem_t *) _sem; if (sem == NULL) return 0; sem_destroy (sem); osip_free (sem); return 0; }
/* Counting Semaphore is initialized to value */ struct osip_sem * osip_sem_init (unsigned int value) { osip_sem_t *sem = (osip_sem_t *) osip_malloc (sizeof (osip_sem_t)); if (sem_init (sem, 0, value) == 0) return (struct osip_sem *) sem; osip_free (sem); return NULL; }
int osip_sem_destroy (struct osip_sem *_sem) { osip_sem_t *sem = (osip_sem_t *) _sem; if (sem == NULL) return 0; sm_delete (sem->id); osip_free (sem); return (0); }
struct osip_sem * osip_sem_init (unsigned int value) { osip_sem_t *sem = (osip_sem_t *) osip_malloc (sizeof (osip_sem_t)); if (sm_create ("sem", value, 0, &sem->id) == 0) return (struct osip_sem *) (sem); osip_free (sem); return (NULL); }
void osip_mutex_destroy (struct osip_mutex *_mut) { osip_mutex_t *mut = (osip_mutex_t *) _mut; if (mut) { sm_delete (mut->id); osip_free (mut); } }
struct osip_mutex * osip_mutex_init () { osip_mutex_t *mut = (osip_mutex_t *) osip_malloc (sizeof (osip_mutex_t)); if (sm_create ("mut", 1, 0, &mut->id) == 0) return (struct osip_mutex *) (mut); osip_free (mut); return (NULL); }
int osip_sem_destroy (struct osip_sem *_sem) { osip_sem_t *sem = (osip_sem_t *) _sem; if (sem == NULL) return 0; CloseHandle (sem->h); osip_free (sem); return (0); }