// Implementation of the PHP constructor. It initialize the handlers table and create a core object. void PhpLinphoneCore::__construct(Php::Parameters ¶meters) { LinphoneCoreVTable vTable = {0}; vTable.dtmf_received = dtmfHandler; const unsigned long size = parameters.size(); if (size == 1) { PhpLinphoneFactoryConfig *factoryConfig = (PhpLinphoneFactoryConfig *)parameters[0].implementation(); this->_core = linphone_core_new(&vTable,nullptr,factoryConfig->get(),nullptr); } else if (size == 2) { PhpLinphoneFactoryConfig *factoryConfig = (PhpLinphoneFactoryConfig *)parameters[0].implementation(); PhpLinphoneConfig *config = (PhpLinphoneConfig *)parameters[1].implementation(); this->_core = linphone_core_new(&vTable,config->get(),factoryConfig->get(),nullptr); } else if (size == 0) { this->_core = linphone_core_new(&vTable,nullptr,nullptr,nullptr); } }
LinphoneCore* configure_lc_from(LinphoneCoreVTable* v_table, const char* path, const char* file, void* user_data) { LinphoneCore* lc; LpConfig* config = NULL; char *filepath = NULL; char *ringpath = NULL; char *ringbackpath = NULL; char *rootcapath = NULL; char *dnsuserhostspath = NULL; char *nowebcampath = NULL; if (path==NULL) path="."; if (file){ filepath = ms_strdup_printf("%s/%s", path, file); if (ortp_file_exist(filepath) != 0) { ms_fatal("Could not find file %s in path %s, did you configured resources directory correctly?", file, path); } config = lp_config_new_with_factory(NULL,filepath); } // setup dynamic-path assets ringpath = ms_strdup_printf("%s/sounds/oldphone.wav",path); ringbackpath = ms_strdup_printf("%s/sounds/ringback.wav", path); nowebcampath = ms_strdup_printf("%s/images/nowebcamCIF.jpg", path); rootcapath = ms_strdup_printf("%s/certificates/cn/cafile.pem", path); dnsuserhostspath = ms_strdup_printf( "%s/%s", path, userhostsfile); if( config != NULL ) { lp_config_set_string(config, "sound", "remote_ring", ringbackpath); lp_config_set_string(config, "sound", "local_ring" , ringpath); lp_config_set_string(config, "sip", "root_ca" , rootcapath); lc = linphone_core_new_with_config(v_table, config, user_data); } else { lc = linphone_core_new(v_table,NULL,(filepath!=NULL&&filepath[0]!='\0') ? filepath : NULL, user_data); linphone_core_set_ring(lc, ringpath); linphone_core_set_ringback(lc, ringbackpath); linphone_core_set_root_ca(lc,rootcapath); } sal_enable_test_features(lc->sal,TRUE); sal_set_dns_user_hosts_file(lc->sal, dnsuserhostspath); linphone_core_set_static_picture(lc,nowebcampath); linphone_core_enable_ipv6(lc, liblinphone_tester_ipv6_enabled); ms_free(ringpath); ms_free(ringbackpath); ms_free(nowebcampath); ms_free(rootcapath); ms_free(dnsuserhostspath); if( filepath ) ms_free(filepath); if( config ) lp_config_unref(config); return lc; }
static void core_sip_transport_test(void) { LinphoneCoreVTable v_table; LinphoneCore* lc; LCSipTransports tr; memset (&v_table,0,sizeof(v_table)); lc = linphone_core_new(&v_table,NULL,NULL,NULL); CU_ASSERT_PTR_NOT_NULL_FATAL(lc); linphone_core_get_sip_transports(lc,&tr); CU_ASSERT_EQUAL(tr.udp_port,5060); /*default config*/ CU_ASSERT_EQUAL(tr.tcp_port,0); /*default config*/ CU_ASSERT_EQUAL(tr.tls_port,0); /*default config*/ tr.udp_port=LC_SIP_TRANSPORT_RANDOM; tr.tcp_port=LC_SIP_TRANSPORT_RANDOM; tr.tls_port=LC_SIP_TRANSPORT_RANDOM; linphone_core_set_sip_transports(lc,&tr); linphone_core_get_sip_transports(lc,&tr); CU_ASSERT_NOT_EQUAL(tr.udp_port,5060); /*default config*/ CU_ASSERT_NOT_EQUAL(tr.tcp_port,0); /*default config*/ CU_ASSERT_NOT_EQUAL(tr.tls_port,0); /*default config*/ CU_ASSERT_EQUAL(lp_config_get_int(linphone_core_get_config(lc),"sip","sip_port",-2),LC_SIP_TRANSPORT_RANDOM); CU_ASSERT_EQUAL(lp_config_get_int(linphone_core_get_config(lc),"sip","sip_tcp_port",-2),LC_SIP_TRANSPORT_RANDOM); CU_ASSERT_EQUAL(lp_config_get_int(linphone_core_get_config(lc),"sip","sip_tls_port",-2),LC_SIP_TRANSPORT_RANDOM); linphone_core_destroy(lc); }
extern "C" void Java_com_acsoftware_android_domophone_LibLP_nInitialize(JNIEnv* env, jobject thiz, int LogsOn, jstring juserConfig ,jstring jfactoryConfig) { if ( lc ) return; const char* userConfig = juserConfig?env->GetStringUTFChars(juserConfig, NULL):NULL; const char* factoryConfig = jfactoryConfig?env->GetStringUTFChars(jfactoryConfig, NULL):NULL; Java_com_acsoftware_android_domophone_LibLP_nSetLogsOn(env, thiz, LogsOn); #ifdef HAVE_X264 libmsx264_init(); #endif memset(&lp_vTable,0,sizeof(lp_vTable)); lp_vTable.registration_state_changed = _registration_state; lp_vTable.call_state_changed = _call_state; lc = linphone_core_new( &lp_vTable ,userConfig ,factoryConfig ,NULL); linphone_core_set_video_device(lc, "StaticImage: Static picture"); linphone_core_enable_video_display(lc, true); //linphone_core_enable_video_capture(lc, true); // Bez transmisji w obu kierunkach pojawiają się problemy z NAT-em i RTP/video linphone_core_set_mtu(lc, 1500); LinphoneVideoPolicy vpol; vpol.automatically_initiate = true; vpol.automatically_accept = true; linphone_core_set_video_policy(lc, &vpol); }
static LinphoneCore* configure_lc_from(LinphoneCoreVTable* v_table, const char* path, const char* file, void* user_data) { LinphoneCore* lc; char filepath[256]={0}; char ringpath[256]={0}; char ringbackpath[256]={0}; char rootcapath[256]={0}; char dnsuserhostspath[256]={0}; char nowebcampath[256]={0}; if (path==NULL) path="."; if (file){ sprintf(filepath, "%s/%s", path, file); CU_ASSERT_TRUE_FATAL(ortp_file_exist(filepath)==0); } lc = linphone_core_new(v_table,NULL,*filepath!='\0' ? filepath : NULL, user_data); sal_enable_test_features(lc->sal,TRUE); snprintf(rootcapath, sizeof(rootcapath), "%s/certificates/cn/cafile.pem", path); linphone_core_set_root_ca(lc,rootcapath); sprintf(dnsuserhostspath, "%s/%s", path, userhostsfile); sal_set_dns_user_hosts_file(lc->sal, dnsuserhostspath); snprintf(ringpath,sizeof(ringpath), "%s/sounds/oldphone.wav",path); snprintf(ringbackpath,sizeof(ringbackpath), "%s/sounds/ringback.wav", path); linphone_core_set_ring(lc, ringpath); linphone_core_set_ringback(lc, ringbackpath); snprintf(nowebcampath, sizeof(nowebcampath), "%s/images/nowebcamCIF.jpg", path); linphone_core_set_static_picture(lc,nowebcampath); return lc; }
int main(int argc, char *argv[]){ LinphoneCoreVTable vtable={0}; LinphoneCore *lc; signal(SIGINT,stop); #ifdef DEBUG linphone_core_enable_logs(NULL); /*enable liblinphone logs.*/ #endif /* Fill the LinphoneCoreVTable with application callbacks. All are optional. Here we only use the call_state_changed callbacks in order to get notifications about the progress of the call. */ vtable.call_state_changed=call_state_changed; /*to receive incoming call*/ vtable.message_received=message_received; /*to receive committed messages*/ vtable.is_composing_received=is_composing_received; /*to receive char in real time*/ /* Instanciate a LinphoneCore object given the LinphoneCoreVTable */ lc=linphone_core_new(&vtable,NULL,NULL,NULL); /* main loop for receiving notifications and doing background linphonecore work: */ while(running){ linphone_core_iterate(lc); ms_usleep(50000); } printf("Shutting down...\n"); linphone_core_destroy(lc); printf("Exited\n"); return 0; }
int main(int argc, char *argv[]){ LinphoneCoreVTable vtable={0}; LinphoneCore *lc; LinphoneCall *call=NULL; signal(SIGINT,stop); printf("Version: %s\n",linphone_core_get_version()); #ifdef DEBUG linphone_core_enable_logs(NULL); /*enable liblinphone logs.*/ #endif /* Fill the LinphoneCoreVTable with application callbacks. All are optional. Here we only use the call_state_changed callbacksestablished in order to get notifications about the progress of the call. */ vtable.call_state_changed=call_state_changed; //vtable.text_received=text_received; /* Instanciate a LinphoneCore object given the LinphoneCoreVTable */ //linphone_core_disable_logs(); lc=linphone_core_new(&vtable,NULL,NULL,NULL); linphone_core_set_sip_port(lc, 9999); const char** devs = linphone_core_get_sound_devices(lc); printf("DEVICE: %s\n",devs[0]); printf("DEVICE: %s\n",devs[1]); //linphone_core_set_playback_device(lc,devs[1]); //linphone_core_set_capture_device(lc,devs[1]); linphone_core_iterate(lc); //LinphoneChatRoom* chat_room = linphone_core_create_chat_room(lc,"sip:[email protected]:9998"); //linphone_chat_room_send_message(chat_room,"Welcome in room!\n"); /* main loop for receiving notifications and doing background linphonecore work: */ while(running){ linphone_core_iterate(lc); ms_usleep(50000); } if (call && linphone_call_get_state(call)!=LinphoneCallEnd){ /* terminate the call */ printf("Terminating the call...\n"); linphone_core_terminate_call(lc,call); /*at this stage we don't need the call object */ linphone_call_unref(call); } end: printf("Shutting down...\n"); linphone_core_destroy(lc); printf("Exited\n"); return 0; }
int main(int argc, char *argv[]){ LinphoneCore *lc; LinphoneCoreVTable vtable={0}; LinphoneSoundDaemon *lsd; LsdPlayer *p; linphone_core_enable_logs(stdout); lc=linphone_core_new(&vtable,NULL,NULL,NULL); lsd=linphone_sound_daemon_new (NULL,44100,1); linphone_core_use_sound_daemon(lc,lsd); /* start a play */ p=linphone_sound_daemon_get_player(lsd); lsd_player_set_callback (p,play_finished); lsd_player_set_user_pointer (p,"share/hello8000.wav"); lsd_player_play (p,"share/hello8000.wav"); wait_a_bit (lc,2); /*start another one */ p=linphone_sound_daemon_get_player(lsd); lsd_player_set_callback (p,play_finished); lsd_player_set_user_pointer (p,"share/hello16000.wav"); lsd_player_enable_loop (p,TRUE); lsd_player_play (p,"share/hello16000.wav"); /* after a few seconds decrease the volume */ wait_a_bit (lc,3); lsd_player_set_gain (p,0.3); wait_a_bit(lc,5); /*now play some stereo music*/ p=linphone_sound_daemon_get_player(lsd); lsd_player_set_callback (p,play_finished); lsd_player_set_user_pointer (p,"share/rings/rock.wav"); lsd_player_play(p,"share/rings/rock.wav"); wait_a_bit(lc,2); /*now play some stereo music at 22khz in order to test stereo resampling */ p=linphone_sound_daemon_get_player(lsd); lsd_player_set_callback (p,play_finished); lsd_player_set_user_pointer (p,"share/rings/bigben.wav"); lsd_player_play(p,"share/rings/bigben.wav"); wait_a_bit(lc,6); /* now place an outgoing call if sip address argument is given */ if (argc>1){ linphone_core_invite(lc,argv[1]); wait_a_bit(lc,10); linphone_core_terminate_call(lc,NULL); } linphone_core_use_sound_daemon(lc,NULL); linphone_sound_daemon_destroy(lsd); linphone_core_destroy(lc); return 0; }
int main(int argc, char *argv[]){ LinphoneCoreVTable vtable={0}; LinphoneCore *lc; LinphoneCall *call=NULL; const char *dest=NULL; /* take the destination sip uri from the command line arguments */ if (argc>1){ dest=argv[1]; } signal(SIGINT,stop); #ifdef DEBUG linphone_core_enable_logs(NULL); /*enable liblinphone logs.*/ #endif /* Fill the LinphoneCoreVTable with application callbacks. All are optional. Here we only use the call_state_changed callbacks in order to get notifications about the progress of the call. */ vtable.call_state_changed=call_state_changed; /* Instanciate a LinphoneCore object given the LinphoneCoreVTable */ lc=linphone_core_new(&vtable,NULL,NULL,NULL); if (dest){ /* Place an outgoing call */ call=linphone_core_invite(lc,dest); if (call==NULL){ printf("Could not place call to %s\n",dest); goto end; }else printf("Call to %s is in progress...",dest); linphone_call_ref(call); } /* main loop for receiving notifications and doing background linphonecore work: */ while(running){ linphone_core_iterate(lc); ms_usleep(50000); } if (call && linphone_call_get_state(call)!=LinphoneCallEnd){ /* terminate the call */ printf("Terminating the call...\n"); linphone_core_terminate_call(lc,call); /*at this stage we don't need the call object */ linphone_call_unref(call); } end: printf("Shutting down...\n"); linphone_core_destroy(lc); printf("Exited\n"); return 0; }
static void chat_room_test(void) { LinphoneCoreVTable v_table; LinphoneCore* lc; memset (&v_table,0,sizeof(v_table)); lc = linphone_core_new(&v_table,NULL,NULL,NULL); if (!BC_ASSERT_PTR_NOT_NULL(lc)) return; BC_ASSERT_PTR_NOT_NULL(linphone_core_get_chat_room_from_uri(lc,"sip:[email protected]")); linphone_core_destroy(lc); }
static void chat_root_test(void) { LinphoneCoreVTable v_table; LinphoneCore* lc; memset (&v_table,0,sizeof(v_table)); lc = linphone_core_new(&v_table,NULL,NULL,NULL); BC_ASSERT_PTR_NOT_NULL_FATAL(lc); linphone_core_create_chat_room(lc,"sip:[email protected]"); linphone_core_destroy(lc); }
static void core_init_test(void) { LinphoneCoreVTable v_table; LinphoneCore* lc; memset (&v_table,0,sizeof(v_table)); lc = linphone_core_new(&v_table,NULL,NULL,NULL); /* until we have good certificates on our test server... */ linphone_core_verify_server_certificates(lc,FALSE); CU_ASSERT_PTR_NOT_NULL_FATAL(lc); linphone_core_destroy(lc); }
static void linphone_interpret_url_test(void) { LinphoneCoreVTable v_table; LinphoneCore* lc; const char* sips_address = "sips:[email protected]"; LinphoneAddress* address; LinphoneProxyConfig *proxy_config; char *tmp; memset ( &v_table,0,sizeof ( v_table ) ); lc = linphone_core_new ( &v_table,NULL,NULL,NULL ); BC_ASSERT_PTR_NOT_NULL_FATAL ( lc ); proxy_config =linphone_core_create_proxy_config(lc); linphone_proxy_config_set_identity(proxy_config, "sip:[email protected]"); linphone_proxy_config_enable_register(proxy_config, FALSE); linphone_proxy_config_set_server_addr(proxy_config,"sip:sip.linphone.org"); linphone_core_add_proxy_config(lc, proxy_config); linphone_core_set_default_proxy_config(lc,proxy_config); linphone_proxy_config_unref(proxy_config); address = linphone_core_interpret_url(lc, sips_address); BC_ASSERT_PTR_NOT_NULL_FATAL(address); BC_ASSERT_STRING_EQUAL_FATAL(linphone_address_get_scheme(address), "sips"); BC_ASSERT_STRING_EQUAL_FATAL(linphone_address_get_username(address), "margaux"); BC_ASSERT_STRING_EQUAL_FATAL(linphone_address_get_domain(address), "sip.linphone.org"); linphone_address_destroy(address); address = linphone_core_interpret_url(lc,"23"); BC_ASSERT_PTR_NOT_NULL(address); BC_ASSERT_STRING_EQUAL(linphone_address_get_scheme(address), "sip"); BC_ASSERT_STRING_EQUAL(linphone_address_get_username(address), "23"); BC_ASSERT_STRING_EQUAL(linphone_address_get_domain(address), "sip.linphone.org"); linphone_address_destroy(address); address = linphone_core_interpret_url(lc,"#24"); BC_ASSERT_PTR_NOT_NULL(address); BC_ASSERT_STRING_EQUAL(linphone_address_get_scheme(address), "sip"); BC_ASSERT_STRING_EQUAL(linphone_address_get_username(address), "#24"); BC_ASSERT_STRING_EQUAL(linphone_address_get_domain(address), "sip.linphone.org"); tmp = linphone_address_as_string(address); BC_ASSERT_TRUE(strcmp (tmp,"sip:%[email protected]") == 0); linphone_address_destroy(address); address = linphone_core_interpret_url(lc,tmp); BC_ASSERT_STRING_EQUAL(linphone_address_get_scheme(address), "sip"); BC_ASSERT_STRING_EQUAL(linphone_address_get_username(address), "#24"); BC_ASSERT_STRING_EQUAL(linphone_address_get_domain(address), "sip.linphone.org"); linphone_address_destroy(address); ms_free(tmp); linphone_core_destroy (lc); }
QLinPhoneCore::QLinPhoneCore(int loopInterval, QObject *parent) : QObject(parent) { m_authInfo = 0; m_rstate = QLinPhoneCore::RegistrationNone; m_loopTimer = new QTimer(this); m_loopTimer->setInterval(loopInterval); connect(m_loopTimer, SIGNAL(timeout()), this, SLOT(update())); #ifdef DEBUG qDebug() << "linphone core version:" << linphone_core_get_version(); /* Enable liblinphone logs. */ linphone_core_enable_logs(NULL); #endif // Fill the LinphoneCoreVTable with application callbacks. All are optional. vtable.registration_state_changed = registration_state_changed; vtable.text_received = text_received; vtable.message_received = message_received; // vtable.call_state_changed // vtable.notify_presence_recv // vtable.new_subscription_request // vtable.auth_info_requested // vtable.call_log_updated // vtable.dtmf_received // vtable.refer_received // vtable.call_encryption_changed // vtable.transfer_state_changed // vtable.buddy_info_updated // vtable.notify_recv // vtable.call_stats_updated // vtable.display_status // vtable.display_message // vtable.display_warning // vtable.display_url // vtable.show // Instantiate a LinphoneCore object given the LinphoneCoreVTable m_lc = linphone_core_new(&vtable, NULL, NULL, NULL); linphone_core_set_user_data(m_lc, static_cast<void *>(this)); m_loopTimer->start(); }
void SipClient::init() { qDebug() << "linphone core version:" << linphone_core_get_version(); m_loopTimer->setInterval(50); connect(m_loopTimer, SIGNAL(timeout()), this, SLOT(update())); LinphoneCoreVTable vtable = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; #ifdef DEBUG /* Enable liblinphone logs. */ linphone_core_enable_logs(NULL); #endif /* Fill the LinphoneCoreVTable with application callbacks. All are optional. */ vtable.registration_state_changed = registration_state_changed; vtable.text_received = text_received; vtable.message_received = message_received; // vtable.call_state_changed // vtable.notify_presence_recv // vtable.new_subscription_request // vtable.auth_info_requested // vtable.call_log_updated // vtable.dtmf_received // vtable.refer_received // vtable.call_encryption_changed // vtable.transfer_state_changed // vtable.buddy_info_updated // vtable.notify_recv // vtable.call_stats_updated // vtable.display_status // vtable.display_message // vtable.display_warning // vtable.display_url // vtable.show /* Instantiate a LinphoneCore object given the LinphoneCoreVTable */ lc = linphone_core_new(&vtable, NULL, NULL, NULL); if (lc) { m_loopTimer->start(); } }
/*check basic things about codecs at startup: order and enablement*/ static void start_with_no_config(void){ LinphoneCoreVTable vtable={0}; LinphoneCore *lc=linphone_core_new(&vtable, NULL, NULL, NULL); const MSList *codecs=linphone_core_get_audio_codecs(lc); int opus_codec_pos; int speex_codec_pos=get_codec_position(codecs, "speex", 8000); int speex16_codec_pos=get_codec_position(codecs, "speex", 16000); PayloadType *pt; opus_codec_pos=get_codec_position(codecs, "opus", 48000); if (opus_codec_pos!=-1) CU_ASSERT_TRUE(opus_codec_pos==0); CU_ASSERT_TRUE(speex16_codec_pos<speex_codec_pos); pt=linphone_core_find_payload_type(lc, "speex", 16000, 1); CU_ASSERT_PTR_NOT_NULL(pt); if (pt) { CU_ASSERT_TRUE(linphone_core_payload_type_enabled(lc, pt)==TRUE); } linphone_core_destroy(lc); }
QLinphoneCore::QLinphoneCore(QObject *parent) : QObject(parent) { QDir confDir = QDir(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation)); confDir.mkdir("Linphone"); QString config_file = confDir.absolutePath() + "/Linphone/.linphonerc"; QString chatDb_file = confDir.absolutePath() + "/Linphone/chatdb.db"; qDebug() << "Config file:" << config_file; static LinphoneCoreVTable vtable = {0}; vtable.global_state_changed = qlinphone_global_state_changed; vtable.message_received = qlinphone_message_received; vtable.auth_info_requested = qlinphone_auth_info_requested; vtable.registration_state_changed = qlinphone_registration_state_changed; lc = linphone_core_new(&vtable, config_file.toStdString().c_str() , NULL, this); linphone_core_set_chat_database_path(lc,chatDb_file.toStdString().c_str()); // build proxies list const MSList* proxyList = linphone_core_get_proxy_config_list(lc); const MSList* proxy = proxyList; while( proxy ){ proxies.append((LinphoneProxyConfig*)proxy->data); proxy = proxy->next; } // build chatrooms list const MSList* roomsList = linphone_core_get_chat_rooms(lc); const MSList* iter = roomsList; while(iter){ rooms.append(new QLChatRoom((LinphoneChatRoom*)iter->data)); iter=iter->next; } // iterate QTimer *timer = new QTimer(); connect(timer, &QTimer::timeout, this, &QLinphoneCore::iterate); timer->start(20); }
static void linphone_interpret_url_test() { LinphoneCoreVTable v_table; LinphoneCore* lc; const char* sips_address = "sips:[email protected]"; LinphoneAddress* address; memset ( &v_table,0,sizeof ( v_table ) ); lc = linphone_core_new ( &v_table,NULL,NULL,NULL ); BC_ASSERT_PTR_NOT_NULL_FATAL ( lc ); address = linphone_core_interpret_url(lc, sips_address); BC_ASSERT_PTR_NOT_NULL_FATAL(address); BC_ASSERT_STRING_EQUAL_FATAL(linphone_address_get_scheme(address), "sips"); BC_ASSERT_STRING_EQUAL_FATAL(linphone_address_get_username(address), "margaux"); BC_ASSERT_STRING_EQUAL_FATAL(linphone_address_get_domain(address), "sip.linphone.org"); linphone_address_destroy(address); linphone_core_destroy ( lc ); }
int main(int argc, char* argv[]) { LinphoneCoreVTable vtable = {0}; LinphoneCore* p_linphone = NULL; const char** devices = NULL; unsigned int i = 0; if (argc > 1 && (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0)) { printf("This program lists the soundcards piphoned does understand. It accepts no options."); return 0; } p_linphone = linphone_core_new(&vtable, NULL, NULL, NULL); devices = linphone_core_get_sound_devices(p_linphone); printf("--- List of detected devices ---\n"); for(i=0; devices[i] != NULL; i++) { printf("Device %i: %s\n", i, devices[i]); } printf("--- End of list of detected devices ---\n"); linphone_core_destroy(p_linphone); return 0; }
int main(int argc, char *argv[]){ LinphoneCoreVTable vtable={0}; MyAppData *data=ms_new0(MyAppData,1); char* identity=NULL; char* password=NULL; int i; LinphoneProxyConfig* proxy_cfg; LinphoneAddress *from; LinphoneAuthInfo *info; const char* server_addr; /* takes sip uri identity from the command line arguments */ if (argc>1){ identity=argv[1]; } /* takes password from the command line arguments */ if (argc>2){ password=argv[2]; } signal(SIGINT,stop); #ifdef DEBUG linphone_core_enable_logs(NULL); /*enable liblinphone logs.*/ #endif /* Fill the LinphoneCoreVTable with application callbacks. All are optional. Here we only use the registration_state_changed callbacks in order to get notifications about the progress of the registration. */ vtable.registration_state_changed=registration_state_changed; vtable.subscription_state_changed=subscription_state_changed; /* Instanciate a LinphoneCore object given the LinphoneCoreVTable */ lc=linphone_core_new(&vtable,NULL,NULL,data); /*create proxy config*/ proxy_cfg = linphone_proxy_config_new(); /*parse identity*/ from = linphone_address_new(identity); if (from==NULL){ printf("%s not a valid sip uri, must be like sip:[email protected] \n",identity); goto end; } if (password!=NULL){ info=linphone_auth_info_new(linphone_address_get_username(from),NULL,password,NULL,NULL,NULL); /*create authentication structure from identity*/ linphone_core_add_auth_info(lc,info); /*add authentication info to LinphoneCore*/ } // configure proxy entries linphone_proxy_config_set_identity(proxy_cfg,identity); /*set identity with user name and domain*/ server_addr = linphone_address_get_domain(from); /*extract domain address from identity*/ linphone_proxy_config_set_server_addr(proxy_cfg,server_addr); /* we assume domain = proxy server address*/ linphone_proxy_config_enable_register(proxy_cfg,TRUE); /*activate registration for this proxy config*/ linphone_address_destroy(from); /*release resource*/ linphone_core_add_proxy_config(lc,proxy_cfg); /*add proxy config to linphone core*/ linphone_core_set_default_proxy(lc,proxy_cfg); /*set to default proxy*/ i=0; /* main loop for receiving notifications and doing background linphonecore work: */ while(running){ linphone_core_iterate(lc); /* first iterate initiates registration */ ms_usleep(50000); ++i; if (data->ev && i%100==0){ LinphoneContentPrivate content; content.type="application"; content.subtype="goodxml"; content.data="really cool"; content.size=strlen((const char*)content.data); linphone_event_notify(data->ev,LINPHONE_CONTENT(&content)); } } linphone_core_get_default_proxy(lc,&proxy_cfg); /* get default proxy config*/ linphone_proxy_config_edit(proxy_cfg); /*start editing proxy configuration*/ linphone_proxy_config_enable_register(proxy_cfg,FALSE); /*de-activate registration for this proxy config*/ linphone_proxy_config_done(proxy_cfg); /*initiate REGISTER with expire = 0*/ if (data->ev){ linphone_event_terminate(data->ev); } while(linphone_proxy_config_get_state(proxy_cfg) != LinphoneRegistrationCleared){ linphone_core_iterate(lc); /*to make sure we receive call backs before shutting down*/ ms_usleep(50000); } end: printf("Shutting down...\n"); linphone_core_destroy(lc); ms_free(data); printf("Exited\n"); return 0; }
static void friends_sqlite_storage(void) { LinphoneCoreVTable *v_table = linphone_core_v_table_new(); LinphoneCore* lc = NULL; LinphoneFriendList *lfl = NULL; LinphoneFriend *lf = NULL; LinphoneFriend *lf2 = NULL; LinphoneVcard *lvc = linphone_vcard_new(); LinphoneAddress *addr = linphone_address_new("sip:[email protected]"); const bctbx_list_t *friends = NULL; bctbx_list_t *friends_from_db = NULL; bctbx_list_t *friends_lists_from_db = NULL; char *friends_db = bc_tester_file("friends.db"); LinphoneFriendListStats *stats = (LinphoneFriendListStats *)ms_new0(LinphoneFriendListStats, 1); LinphoneAddress *laddress = NULL, *laddress2 = NULL; char *address = NULL, *address2 = NULL; v_table->friend_list_created = friend_list_created_cb; v_table->friend_list_removed = friend_list_removed_cb; lc = linphone_core_new(v_table, NULL, NULL, NULL); friends = linphone_friend_list_get_friends(linphone_core_get_default_friend_list(lc)); lfl = linphone_core_create_friend_list(lc); linphone_friend_list_set_user_data(lfl, stats); BC_ASSERT_EQUAL(bctbx_list_size(friends), 0, int, "%d"); unlink(friends_db); linphone_core_set_friends_database_path(lc, friends_db); friends_from_db = linphone_core_fetch_friends_from_db(lc, linphone_core_get_default_friend_list(lc)); BC_ASSERT_EQUAL(bctbx_list_size(friends_from_db), 0, int, "%d"); linphone_vcard_set_etag(lvc, "\"123-456789\""); linphone_vcard_set_url(lvc, "http://dav.somewhere.fr/addressbook/me/someone.vcf"); lf = linphone_friend_new_from_vcard(lvc); linphone_friend_set_address(lf, addr); linphone_friend_set_name(lf, "Sylvain"); linphone_core_add_friend_list(lc, lfl); wait_for_until(lc, NULL, &stats->new_list_count, 1, 1000); BC_ASSERT_EQUAL(stats->new_list_count, 1, int, "%i"); linphone_friend_list_unref(lfl); linphone_friend_list_set_display_name(lfl, "Test"); BC_ASSERT_EQUAL(linphone_friend_list_add_friend(lfl, lf), LinphoneFriendListOK, int, "%i"); linphone_friend_unref(lf); BC_ASSERT_EQUAL(lfl->storage_id, 1, unsigned int, "%u"); BC_ASSERT_EQUAL(lf->storage_id, 1, unsigned int, "%u"); friends = linphone_friend_list_get_friends(linphone_core_get_default_friend_list(lc)); BC_ASSERT_EQUAL(bctbx_list_size(friends), 0, int, "%d"); friends_lists_from_db = linphone_core_fetch_friends_lists_from_db(lc); BC_ASSERT_EQUAL(bctbx_list_size(friends_lists_from_db), 1, int, "%d"); friends_from_db = ((LinphoneFriendList *)friends_lists_from_db->data)->friends; BC_ASSERT_EQUAL(bctbx_list_size(friends_from_db), 1, int, "%d"); lf2 = (LinphoneFriend *)friends_from_db->data; BC_ASSERT_PTR_NOT_NULL(lf2->lc); BC_ASSERT_PTR_NOT_NULL(lf2->friend_list); friends_lists_from_db = bctbx_list_free_with_data(friends_lists_from_db, (void (*)(void *))linphone_friend_list_unref); friends_from_db = linphone_core_fetch_friends_from_db(lc, lfl); BC_ASSERT_EQUAL(bctbx_list_size(friends_from_db), 1, int, "%d"); if (bctbx_list_size(friends_from_db) < 1) { goto end; } lf2 = (LinphoneFriend *)friends_from_db->data; BC_ASSERT_STRING_EQUAL(linphone_friend_get_name(lf2), linphone_friend_get_name(lf)); BC_ASSERT_EQUAL(lf2->storage_id, lf->storage_id, unsigned int, "%u"); BC_ASSERT_STRING_EQUAL(linphone_vcard_get_etag(linphone_friend_get_vcard(lf2)), linphone_vcard_get_etag(linphone_friend_get_vcard(lf))); BC_ASSERT_STRING_EQUAL(linphone_vcard_get_url(linphone_friend_get_vcard(lf2)), linphone_vcard_get_url(linphone_friend_get_vcard(lf))); laddress = linphone_friend_get_address(lf); address = linphone_address_as_string(laddress); laddress2 = linphone_friend_get_address(lf2); address2 = linphone_address_as_string(laddress2); BC_ASSERT_STRING_EQUAL(address2, address); linphone_address_unref(laddress); linphone_address_unref(laddress2); ms_free(address); ms_free(address2); linphone_friend_edit(lf); linphone_friend_set_name(lf, "Margaux"); linphone_friend_done(lf); friends_from_db = bctbx_list_free_with_data(friends_from_db, (void (*)(void *))linphone_friend_unref); friends_from_db = linphone_core_fetch_friends_from_db(lc, lfl); BC_ASSERT_EQUAL(bctbx_list_size(friends_from_db), 1, int, "%d"); if (bctbx_list_size(friends_from_db) < 1) { goto end; } lf2 = (LinphoneFriend *)friends_from_db->data; BC_ASSERT_STRING_EQUAL(linphone_friend_get_name(lf2), "Margaux"); friends_from_db = bctbx_list_free_with_data(friends_from_db, (void (*)(void *))linphone_friend_unref); linphone_friend_list_remove_friend(lfl, lf); friends = linphone_friend_list_get_friends(linphone_core_get_default_friend_list(lc)); BC_ASSERT_EQUAL(bctbx_list_size(friends), 0, int, "%d"); friends_from_db = linphone_core_fetch_friends_from_db(lc, lfl); BC_ASSERT_EQUAL(bctbx_list_size(friends_from_db), 0, int, "%d"); linphone_core_remove_friend_list(lc, lfl); wait_for_until(lc, NULL, &stats->removed_list_count, 1, 1000); BC_ASSERT_EQUAL(stats->removed_list_count, 1, int, "%i"); end: ms_free(stats); unlink(friends_db); ms_free(friends_db); linphone_address_unref(addr); linphone_core_destroy(lc); linphone_core_v_table_destroy(v_table); }
int main (int argc, char *argv[]) { char *arg; int n; printf ("I: Phone2l " VERSION " by Gundolf Kiefer <*****@*****.**>, University of Applied Sciences Augsburg, 2015\n"); // Interpret command line... error = FALSE; for (n = 1; n < argc; n++) { arg = argv[n]; if (arg[0] != '-') { if (!argCallee) argCallee = arg; else error = TRUE; } else switch (arg[1]) { case 'h': argHelp = TRUE; break; case 'v': argVerbose = TRUE; break; case 'c': if (arg[2] == '=') argConfig = arg + 3; else error = TRUE; break; case 'f': if (arg[2] == '=') argFontFileName = arg + 3; else error = TRUE; break; case 's': if (arg[2] != '=') error = TRUE; else { argFontSize = atoi (arg + 3); if (argFontSize < 8) error = TRUE; // we assume that smaller fonts do not make sense and are unreadable } break; case 'a': argSoftwareRenderer = TRUE; break; case 'i': argInterpolation = arg[2] - '0'; if (argInterpolation < 0 || argInterpolation > 2) error = TRUE; break; default: error = TRUE; } } if (error || argHelp) { printf ("Usage: phone2l [<options>] - run phone2l in listening mode\n" " phone2l [<options>] <URL> - call <URL> and terminate with call\n" "\n" "Options:\n" " -h : show this help\n" " -v : be verbose\n" " -c=<config> : specify linphone configuration file (default: ~/.linphonerc)\n" " -f=<font>: specify ttf font file (default: %s)\n" " -s=<size>: specify font size (default: %i)\n" " -a: disable hardware acceleration, force software rendering\n" " -i[0|1|2]: set interpolation method - 0=auto, 1=nearest, 2=bilinear (default: 0)\n" "\n" "By default, debug messages from the underlying libraries (liblinphone,\n" "mediastreamer, ...) are sent to 'stderr' and can safely be redirected\n" "to /dev/null. Messages to 'stdout' can be automatically processed\n" "according to the following prefixes:\n" " S: Status messages, also shown on the screen\n" " I: Information messages\n" " W: Warnings\n" " E: Errors (typically causing the tool to exit)\n", argFontFileName, argFontSize ); exit (error ? 3 : 0); } // Set signal handlers... signal (SIGTERM, signal_handler); // for kill command / requested by project team signal (SIGINT, signal_handler); // for keyboard interrupt // Init liblinphone_core... printf ("I: Initializing 'liblinphone'...\n"); lpcVtable.display_status = cb_display_status; //lpcVtable.display_message = cb_display_message; lpcVtable.display_warning = cb_display_warning; //lpcVtable.display_url = cb_display_url; lpcVtable.call_state_changed = cb_call_state_changed; if (argVerbose) linphone_core_enable_logs (stderr); if (argConfig) strncpy (configFileName, argConfig, MAX_PATH); else snprintf (configFileName, MAX_PATH, "%s/.linphonerc", getenv ("HOME")); lpc = linphone_core_new (&lpcVtable, configFileName, NULL, NULL); linphone_core_set_user_agent (lpc, "Phone2l", VERSION); linphone_core_enable_video_capture (lpc, TRUE); linphone_core_enable_video_display (lpc, TRUE); linphone_core_enable_video_preview (lpc, TRUE); // Init 'beam-render' ... if (!BRInit (argFontFileName, argFontSize)) exit (3); if (!BRWindowOpen ("Phone2l", argSoftwareRenderer, argInterpolation)) exit (3); BRInitMediastreamer (); // The following calls only work for 3.8.1 (not 3.6.x)... //printf ("### linphone_core_set_video_display_filter (linphonec, 'BRDisplay')...\n"); linphone_core_set_video_display_filter (lpc, "BRDisplay"); // "MSVideoOut": A SDL-based video display // "MSX11Video": A video display using X11+Xv // "MSGLXVideo": A video display using GL (glx) //printf ("### linphone_core_get_video_display_filter (): %s\n", linphone_core_get_video_display_filter (lpc)); //printf ("### video_stream_get_default_video_renderer (): %s\n", video_stream_get_default_video_renderer ()); // Testing ... //BRDisplayMessage ("Hello World!"); // Initiate call if set... if (argCallee) { printf ("I: Calling '%s'...\n", argCallee); if (!linphone_core_invite (lpc, argCallee)) { printf ("E: Call initiation failed!\n"); error = TRUE; } } // Main loop ... while (running && !error) { linphone_core_iterate (lpc); BRIterate (); usleep (20000); // 20 ms / 50 Hz } // Finish ... printf ("I: Terminating all calls...\n"); linphone_core_terminate_all_calls (lpc); printf ("I: Exiting...\n"); linphone_core_destroy (lpc); BRDone (); exit (error ? 1 : 0); }
int main(int argc, char *argv[]){ LinphoneCoreVTable vtable={0}; LinphoneCore *lc; LinphoneCall *call=NULL; LinphoneChatRoom *chat_room; LinphoneChatMessage *chat_message=NULL; const char *dest=NULL; LCSipTransports tp; tp.udp_port=LC_SIP_TRANSPORT_RANDOM; tp.tcp_port=LC_SIP_TRANSPORT_RANDOM; tp.tls_port=LC_SIP_TRANSPORT_RANDOM; /* take the destination sip uri from the command line arguments */ if (argc>1){ dest=argv[1]; } signal(SIGINT,stop); #ifdef DEBUG linphone_core_enable_logs(NULL); /*enable liblinphone logs.*/ #endif /* Instanciate a LinphoneCore object given the LinphoneCoreVTable */ lc=linphone_core_new(&vtable,NULL,NULL,NULL); linphone_core_set_sip_transports(lc,&tp); /*to avoid port colliding with receiver*/ if (dest){ /* Place an outgoing call with rtt enabled */ LinphoneCallParams *cp = linphone_core_create_call_params(lc, NULL); linphone_call_params_enable_realtime_text(cp,TRUE); /*enable real time text*/ call=linphone_core_invite_with_params(lc,dest,cp); linphone_call_params_destroy(cp); if (call==NULL){ printf("Could not place call to %s\n",dest); goto end; }else printf("Call to %s is in progress...",dest); linphone_call_ref(call); } /*wait for call to be established*/ while (running && (linphone_call_get_state(call) == LinphoneCallOutgoingProgress || linphone_call_get_state(call) == LinphoneCallOutgoingInit)) { linphone_core_iterate(lc); ms_usleep(50000); } /*check if call is established*/ switch (linphone_call_get_state(call)) { case LinphoneCallError: case LinphoneCallReleased: case LinphoneCallEnd: printf("Could not place call to %s\n",dest); goto end; break; default: break; /*continue*/ } chat_room=linphone_call_get_chat_room(call); /*create a chat room associated to this call*/ /* main loop for sending message and doing background linphonecore work: */ while(running){ char character; /*to disable terminal buffering*/ if (system ("/bin/stty raw") == -1){ ms_error("/bin/stty error"); } character = getchar(); if (system("/bin/stty cooked") == -1){ ms_error("/bin/stty error"); } if (character==0x03) {/*CTRL C*/ running=0; break; } if (character != EOF) { /* user has typed something*/ if (chat_message == NULL) { /*create a new message*/ chat_message = linphone_chat_room_create_message(chat_room,""); /*create an empty message*/ } if (character == '\r') { /*new line, committing message*/ linphone_chat_room_send_chat_message(chat_room,chat_message); chat_message = NULL; /*reset message*/ } else { linphone_chat_message_put_char(chat_message,character); /*send char in realtime*/ } } linphone_core_iterate(lc); ms_usleep(50000); } if (call && linphone_call_get_state(call)!=LinphoneCallEnd){ /* terminate the call */ printf("Terminating the call...\n"); linphone_core_terminate_call(lc,call); /*at this stage we don't need the call object */ linphone_call_unref(call); } end: printf("Shutting down...\n"); linphone_core_destroy(lc); printf("Exited\n"); return 0; }
/* * Initialize linphonec */ static int linphonec_init(int argc, char **argv) { //g_mem_set_vtable(&dbgtable); /* * Set initial values for global variables */ mylogfile = NULL; #ifndef _WIN32 snprintf(configfile_name, PATH_MAX, "%s/.linphonerc", getenv("HOME")); snprintf(zrtpsecrets, PATH_MAX, "%s/.linphone-zidcache", getenv("HOME")); #elif defined(_WIN32_WCE) strncpy(configfile_name,PACKAGE_DIR "\\linphonerc",PATH_MAX); mylogfile=fopen(PACKAGE_DIR "\\" "linphonec.log","w"); printf("Logs are redirected in" PACKAGE_DIR "\\linphonec.log"); #else snprintf(configfile_name, PATH_MAX, "%s/Linphone/linphonerc", getenv("APPDATA")); snprintf(zrtpsecrets, PATH_MAX, "%s/Linphone/linphone-zidcache", getenv("APPDATA")); #endif /* Handle configuration filename changes */ switch (handle_configfile_migration()) { case -1: /* error during file copies */ fprintf(stderr, "Error in configuration file migration\n"); break; case 0: /* nothing done */ case 1: /* migrated */ default: break; } #ifdef ENABLE_NLS if (NULL == bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR)) perror ("bindtextdomain failed"); #ifndef __ARM__ bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); #endif textdomain (GETTEXT_PACKAGE); #else printf ("NLS disabled.\n"); #endif linphonec_parse_cmdline(argc, argv); if (trace_level > 0) { if (logfile_name != NULL) mylogfile = fopen (logfile_name, "w+"); if (mylogfile == NULL) { mylogfile = stdout; fprintf (stderr, "INFO: no logfile, logging to stdout\n"); } linphone_core_enable_logs(mylogfile); } else { linphone_core_disable_logs(); } /* * Initialize auth stack */ auth_stack.nitems=0; /* * Initialize linphone core */ linphonec=linphone_core_new (&linphonec_vtable, configfile_name, factory_configfile_name, NULL); linphone_core_set_zrtp_secrets_file(linphonec,zrtpsecrets); linphone_core_enable_video(linphonec,vcap_enabled,display_enabled); if (display_enabled && window_id != 0) { printf ("Setting window_id: 0x%x\n", window_id); linphone_core_set_native_video_window_id(linphonec,window_id); } linphone_core_enable_video_preview(linphonec,preview_enabled); if (!(vcap_enabled || display_enabled)) printf("Warning: video is disabled in linphonec, use -V or -C or -D to enable.\n"); #ifdef HAVE_READLINE /* * Initialize readline */ linphonec_initialize_readline(); #endif #if !defined(_WIN32_WCE) /* * Initialize signal handlers */ signal(SIGTERM, linphonec_finish); signal(SIGINT, linphonec_finish); #endif /*_WIN32_WCE*/ return 1; }
int main(int argc, char *argv[]){ LinphoneCoreVTable vtable={0}; const char* dest_friend=NULL; int i; const char* big_file_content="big file"; LinphoneChatRoom* chat_room; LinphoneContent* content; LinphoneChatMessage* chat_message; LinphoneChatMessageCbs *cbs; /*seting dummy file content to something*/ for (i=0;i<sizeof(big_file);i+=strlen(big_file_content)) memcpy(big_file+i, big_file_content, strlen(big_file_content)); big_file[0]=*"S"; big_file[sizeof(big_file)-1]=*"E"; signal(SIGINT,stop); //#define DEBUG #ifdef DEBUG linphone_core_enable_logs(NULL); /*enable liblinphone logs.*/ #endif vtable.message_received=message_received; /* Instantiate a LinphoneCore object given the LinphoneCoreVTable */ lc=linphone_core_new(&vtable,NULL,NULL,NULL); dest_friend = linphone_core_get_primary_contact(lc); printf("Send message to me : %s\n", dest_friend); /** * Globally configure an http file transfer server. */ //linphone_core_set_file_transfer_server(lc,"http://npasc.al/lft.php"); linphone_core_set_file_transfer_server(lc,"https://www.linphone.org:444/lft.php"); /*Next step is to create a chat room*/ chat_room = linphone_core_get_chat_room_from_uri(lc,dest_friend); content = linphone_core_create_content(lc); linphone_content_set_type(content,"text"); linphone_content_set_subtype(content,"plain"); linphone_content_set_size(content,sizeof(big_file)); /*total size to be transfered*/ linphone_content_set_name(content,"bigfile.txt"); /*now create a chat message with custom content*/ chat_message = linphone_chat_room_create_file_transfer_message(chat_room,content); if (chat_message == NULL) { printf("returned message is null\n"); } /** * Fill the application callbacks. The file_transfer_received callback is used in order to get notifications * about incoming file reception, file_transfer_send to feed file to be transfered and * file_transfer_progress_indication to print progress. */ cbs = linphone_chat_message_get_callbacks(chat_message); linphone_chat_message_cbs_set_file_transfer_recv(cbs, file_transfer_received); linphone_chat_message_cbs_set_file_transfer_send(cbs, file_transfer_send); linphone_chat_message_cbs_set_file_transfer_progress_indication(cbs, file_transfer_progress_indication); /*initiating file transfer*/ linphone_chat_room_send_chat_message(chat_room, chat_message); /* main loop for receiving incoming messages and doing background linphone core work: */ while(running){ linphone_core_iterate(lc); ms_usleep(50000); } printf("Shutting down...\n"); linphone_content_unref(content); linphone_core_destroy(lc); printf("Exited\n"); return 0; }