static void _sal_exosip_subscription_recv(Sal *sal, eXosip_event_t *ev){ SalOp *op=sal_op_new(sal); char *tmp; op->did=ev->did; op->tid=ev->tid; op->nid=ev->nid; osip_from_to_str(ev->request->from,&tmp); sal_op_set_from(op,tmp); ms_free(tmp); osip_from_to_str(ev->request->to,&tmp); sal_op_set_to(op,tmp); ms_free(tmp); sal_add_in_subscribe(sal,op,ev->request); sal->callbacks.subscribe_received(op,sal_op_get_from(op)); }
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 SIPBuilder::CameraInfoAck(osip_message_t* msg, char** rtmsg, size_t* rtlen) { string head_line("SIP/2.0 200 OK\r\n"); osip_via_t *via; char* via_c = NULL; if( !osip_list_eol (&msg->vias, 0)) { via = (osip_via_t *) osip_list_get (&msg->vias, 0); osip_via_to_str( via, &via_c); }else{ return; } string via_header(via_c); via_header = string("Via: ")+via_header+string("\r\n"); char* from_tag_c; osip_from_to_str( msg->from, &from_tag_c ); string from_header(from_tag_c); from_header = string("From: ")+from_header+string("\r\n"); char* to_tag_c; osip_to_to_str( msg->to, &to_tag_c ); string to_header(to_tag_c); string to_tag_num = _RandomNum(); to_header = to_header + ";tag="+to_tag_num; to_header = string("To: ")+to_header+string("\r\n"); string call_id_num = string(msg->call_id->number); string call_header = string("Call-ID: ")+call_id_num+("\r\n"); string cseq_num = string(msg->cseq->number); string cseq_header = string("Cseq: ")+cseq_num+string(" MESSAGE\r\n"); string content_type_header = "Content-Type: APPLICATION/SDP\r\n"; string forwords = string("Max-Forwards: 70\r\n"); string expires = string("Expires: 3000\r\n"); string contentlenth = string("Content-Length: 0")+string("\r\n"); string cflr = string("\r\n"); string sip_msg_str = head_line + via_header + to_header + from_header + call_header + cseq_header + content_type_header + forwords + expires + contentlenth + cflr; #ifdef DEBUG cout<<"check 200ok camerainfoack:"<<endl; cout<<sip_msg_str<<endl; #endif size_t sip_len = sip_msg_str.length(); char* sip_msg_c = (char*)malloc(sizeof(char)* sip_len); memcpy( sip_msg_c, sip_msg_str.c_str(), sip_len); *rtmsg = sip_msg_c; *rtlen = sip_len; /*send 200ok, wait ack*/ return; }
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; }
/* returns null on error. */ int osip_contact_to_str(const osip_contact_t * contact, char **dest) { if (contact == NULL) return OSIP_BADPARAMETER; if (contact->displayname != NULL) { if (strncmp(contact->displayname, "*", 1) == 0) { *dest = osip_strdup("*"); if (*dest == NULL) return OSIP_NOMEM; return OSIP_SUCCESS; } } return osip_from_to_str((osip_from_t *) contact, dest); }
int from_2char_without_params(osip_from_t *from,char **str) { osip_from_t *tmpfrom=NULL; osip_from_clone(from,&tmpfrom); if (tmpfrom!=NULL){ while(!osip_list_eol(&tmpfrom->gen_params,0)){ osip_generic_param_t *param=(osip_generic_param_t*)osip_list_get(&tmpfrom->gen_params,0); osip_generic_param_free(param); osip_list_remove(&tmpfrom->gen_params,0); } }else return -1; osip_from_to_str(tmpfrom,str); osip_from_free(tmpfrom); return 0; }
void sal_exosip_in_subscription_closed(Sal *sal, eXosip_event_t *ev){ SalOp *op=sal_find_in_subscribe(sal,ev->nid); char *tmp; if (op==NULL){ ms_error("Incoming subscription closed but no associated op !"); return; } sal_remove_in_subscribe(sal,op); op->nid=-1; op->did=-1; if (ev->request){ osip_from_to_str(ev->request->from,&tmp); sal->callbacks.subscribe_closed(op,tmp); osip_free(tmp); } }
void SIPBuilder::BeenInvited( osip_message_t* msg, string port,char** rtmsg, size_t *rtlen, int*state, struct DialogInfo &dlg_info) { string uac_ip = _local_ip_str_; string uac_listen_port_str = _local_port_str_; string local_dev_name = _dev_name_; string head_line("SIP/2.0 200 OK\r\n"); osip_via_t *via; char* via_c = NULL; if( !osip_list_eol (&msg->vias, 0)) { via = (osip_via_t *) osip_list_get (&msg->vias, 0); osip_via_to_str( via, &via_c); }else{ *state = -1; return; } string via_header(via_c); via_header = string("Via: ")+via_header+string("\r\n"); char* from_tag_c; osip_from_to_str( msg->from, &from_tag_c ); string from_header(from_tag_c); from_header = string("From: ")+from_header+string("\r\n"); char* to_tag_c; osip_to_to_str( msg->to, &to_tag_c ); string to_header(to_tag_c); string to_tag_num = _RandomNum(); to_header = to_header + ";tag="+to_tag_num; to_header = string("To: ")+to_header+string("\r\n"); dlg_info.to_tag_num = to_tag_num; string contact_header; stringstream stream_contact_header; stream_contact_header<<"Contact: <sip:" << local_dev_name << "@" << uac_ip << ":"<< uac_listen_port_str<<">\r\n"; contact_header = stream_contact_header.str(); string call_id_num = string(msg->call_id->number); string call_header = string("Call-ID: ")+call_id_num+("\r\n"); string cseq_num = string(msg->cseq->number); string cseq_header = string("Cseq: ")+cseq_num+string(" INVITE\r\n"); string content_type_header = "Content-Type: APPLICATION/SDP\r\n"; string forwords = string("Max-Forwards: 70\r\n"); string expires = string("Expires: 3000\r\n"); string sdp_msg = _sdp_builder_.toString( string("##2015"), port); stringstream sdp_msg_length; sdp_msg_length<< sdp_msg.length(); string contentlenth = string("Content-Length: ")+sdp_msg_length.str()+string("\r\n"); string cflr = string("\r\n"); string sip_msg_str = head_line + via_header + to_header + from_header + call_header + cseq_header + contact_header + content_type_header + forwords + expires + contentlenth + cflr + sdp_msg; #ifdef DEBUG cout<<"check Been Invite:"<<endl; cout<<sip_msg_str<<endl; #endif size_t sip_len = sip_msg_str.length(); char* sip_msg_c = (char*)malloc(sizeof(char)* sip_len); memcpy( sip_msg_c, sip_msg_str.c_str(), sip_len); *rtmsg = sip_msg_c; *rtlen = sip_len; /*send 200ok, wait ack*/ *state = 0; return; }
/* returns null on error. */ int osip_to_to_str(const osip_to_t * to, char **dest) { return osip_from_to_str((osip_from_t *) to, dest); }
void sal_exosip_notify_recv(Sal *sal, eXosip_event_t *ev){ SalOp *op=sal_find_out_subscribe(sal,ev->sid); char *tmp; osip_from_t *from=NULL; osip_body_t *body=NULL; SalPresenceStatus estatus=SalPresenceOffline; ms_message("Receiving notify with sid=%i,nid=%i",ev->sid,ev->nid); if (op==NULL){ ms_error("No operation related to this notify !"); return; } if (ev->request==NULL) return; from=ev->request->from; osip_message_get_body(ev->request,0,&body); if (body==NULL){ ms_error("No body in NOTIFY"); return; } osip_from_to_str(from,&tmp); if (strstr(body->body,"pending")!=NULL){ estatus=SalPresenceOffline; }else if (strstr(body->body,"busy")!=NULL){ estatus=SalPresenceBusy; }else if (strstr(body->body,"berightback")!=NULL || strstr(body->body,"in-transit")!=NULL ){ estatus=SalPresenceBerightback; }else if (strstr(body->body,"away")!=NULL || strstr(body->body,"idle")){ estatus=SalPresenceAway; }else if (strstr(body->body,"onthephone")!=NULL || strstr(body->body,"on-the-phone")!=NULL){ estatus=SalPresenceOnthephone; }else if (strstr(body->body,"outtolunch")!=NULL || strstr(body->body,"lunch") != NULL || strstr(body->body,"meal")!=NULL){ estatus=SalPresenceOuttolunch; }else if (strstr(body->body,"closed")!=NULL){ estatus=SalPresenceOffline; }else if ((strstr(body->body,"online")!=NULL) || (strstr(body->body,"open")!=NULL)) { estatus=SalPresenceOnline; }else if(strstr(body->body,"vacation") != NULL) { estatus = SalPresenceOnVacation; }else{ estatus=SalPresenceOffline; } ms_message("We are notified that %s has online status %i",tmp,estatus); if (ev->ss_status==EXOSIP_SUBCRSTATE_TERMINATED) { sal_remove_out_subscribe(sal,op); op->sid=-1; op->did=-1; ms_message("And outgoing subscription terminated by remote."); } sal->callbacks.notify_presence(op,op->sid!=-1 ? SalSubscribeActive : SalSubscribeTerminated, estatus,NULL); /* try to detect presence message style used by server, * and switch our presence messages to servers style */ if (strstr (body->body, "//IETF//DTD RFCxxxx XPIDF 1.0//EN") != NULL) { presence_style = RFCxxxx; } else if (strstr(body->body,"http://schemas.microsoft.com/2002/09/sip/presence")!=NULL) { presence_style = MSOLDPRES; } osip_free(tmp); }