]> sjero.net Git - linphone/blobdiff - console/linphonec.c
Fix bug report
[linphone] / console / linphonec.c
index de3ce9e44c740d509d6c8d5b8fb75f8bdcdfff1d..60c3c2af11c48256e6af0ccfaa290d702e683b05 100644 (file)
@@ -160,6 +160,7 @@ LPC_AUTH_STACK auth_stack;
 static int trace_level = 0;
 static char *logfile_name = NULL;
 static char configfile_name[PATH_MAX];
+static char zrtpsecrets[PATH_MAX];
 static const char *factory_configfile_name=NULL;
 static char *sip_addr_to_call = NULL; /* for autocall */
 static int window_id = 0; /* 0=standalone window, or window id for embedding video */
@@ -323,18 +324,29 @@ static void linphonec_call_updated(LinphoneCall *call){
        }
 }
 
+static void linphonec_call_encryption_changed(LinphoneCore *lc, LinphoneCall *call, bool_t encrypted, const char *auth_token) {
+       long id=(long)linphone_call_get_user_pointer (call);
+       if (!encrypted) {
+               linphonec_out("Call %i is not fully encrypted and auth token is %s.\n", id,
+                               (auth_token != NULL) ? auth_token : "absent");
+       } else {
+               linphonec_out("Call %i is fully encrypted and auth token is %s.\n", id,
+                               (auth_token != NULL) ? auth_token : "absent");
+       }
+}
+
 static void linphonec_call_state_changed(LinphoneCore *lc, LinphoneCall *call, LinphoneCallState st, const char *msg){
        char *from=linphone_call_get_remote_address_as_string(call);
        long id=(long)linphone_call_get_user_pointer (call);
        switch(st){
                case LinphoneCallEnd:
-                       linphonec_out("Call %i with %s ended.\n", id, from);
+                       linphonec_out("Call %i with %s ended (%s).\n", id, from, linphone_reason_to_string(linphone_call_get_reason(call)));
                break;
                case LinphoneCallResuming:
                        linphonec_out("Resuming call %i with %s.\n", id, from);
                break;
                case LinphoneCallStreamsRunning:
-                       linphonec_out("Media streams established with %s for call %i.\n", from,id);
+                       linphonec_out("Media streams established with %s for call %i (%s).\n", from,id,( linphone_call_params_video_enabled( linphone_call_get_current_params(call)) ? "video":"audio"));
                break;
                case LinphoneCallPausing:
                        linphonec_out("Pausing call %i with %s.\n", id, from);
@@ -358,7 +370,6 @@ static void linphonec_call_state_changed(LinphoneCore *lc, LinphoneCall *call, L
                case LinphoneCallOutgoingInit:
                        linphonec_call_identify(call);
                        id=(long)linphone_call_get_user_pointer (call);
-                       from=linphone_call_get_remote_address_as_string(call);
                        linphonec_out("Establishing call id to %s, assigned id %i\n", from,id);
                break;
                case LinphoneCallUpdatedByRemote:
@@ -543,7 +554,8 @@ char *linphonec_readline(char *prompt){
                }
        }else{
 #ifdef HAVE_READLINE
-               return readline(prompt);
+               char* ret=readline(prompt);
+               return ret;
 #endif
        }
 }
@@ -627,6 +639,7 @@ main (int argc, char *argv[]) {
        linphonec_vtable.dtmf_received=linphonec_dtmf_received;
        linphonec_vtable.refer_received=linphonec_display_refer;
        linphonec_vtable.notify_recv=linphonec_notify_received;
+       linphonec_vtable.call_encryption_changed=linphonec_call_encryption_changed;
        
        if (! linphonec_init(argc, argv) ) exit(EXIT_FAILURE);
 
@@ -655,6 +668,8 @@ linphonec_init(int argc, char **argv)
 #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");
@@ -662,6 +677,8 @@ linphonec_init(int argc, char **argv)
 #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())
@@ -716,6 +733,7 @@ linphonec_init(int argc, char **argv)
         * 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) 
        {
@@ -794,11 +812,17 @@ linphonec_finish(int exit_status)
 int
 linphonec_prompt_for_auth_final(LinphoneCore *lc)
 {
+       static int reentrancy=0;
        char *input, *iptr;
        char auth_prompt[256];
 #ifdef HAVE_READLINE
        rl_hook_func_t *old_event_hook;
 #endif
+
+       if (reentrancy!=0) return 0;
+       
+       reentrancy++;
+       
        LinphoneAuthInfo *pending_auth=auth_stack.elem[auth_stack.nitems-1];
 
        snprintf(auth_prompt, 256, "Password for %s on %s: ",
@@ -871,22 +895,22 @@ linphonec_prompt_for_auth_final(LinphoneCore *lc)
 void
 print_usage (int exit_status)
 {
-       fprintf (stdout, "\n\
-usage: linphonec [-c file] [-s sipaddr] [-a] [-V] [-d level ] [-l logfile]\n\
-       linphonec -v\n\
-\n\
-  -b  file             specify path of readonly factory configuration file.\n\
-  -c  file             specify path of configuration file.\n\
-  -d  level            be verbose. 0 is no output. 6 is all output\n\
-  -l  logfile          specify the log file for your SIP phone\n\
-  -s  sipaddress       specify the sip call to do at startup\n\
-  -a                   enable auto answering for incoming calls\n\
-  -V                   enable video features globally (disabled by default)\n\
-  -C                   enable video capture only (disabled by default)\n\
-  -D                   enable video display only (disabled by default)\n\
-  -S                   show general state messages (disabled by default)\n\
-  --wid  windowid      force embedding of video window into provided windowid (disabled by default)\n\
-  -v or --version      display version and exits.\n");
+       fprintf (stdout, "\n"
+"usage: linphonec [-c file] [-s sipaddr] [-a] [-V] [-d level ] [-l logfile]\n"
+       "linphonec -v\n"
+"\n"
+"  -b  file             specify path of readonly factory configuration file.\n"
+"  -c  file             specify path of configuration file.\n"
+"  -d  level            be verbose. 0 is no output. 6 is all output\n"
+"  -l  logfile          specify the log file for your SIP phone\n"
+"  -s  sipaddress       specify the sip call to do at startup\n"
+"  -a                   enable auto answering for incoming calls\n"
+"  -V                   enable video features globally (disabled by default)\n"
+"  -C                   enable video capture only (disabled by default)\n"
+"  -D                   enable video display only (disabled by default)\n"
+"  -S                   show general state messages (disabled by default)\n"
+"  --wid  windowid      force embedding of video window into provided windowid (disabled by default)\n"
+"  -v or --version      display version and exits.\n");
 
        exit(exit_status);
 }
@@ -901,6 +925,7 @@ static void x11_apply_video_params(VideoParams *params, Window window){
        const char *dname=getenv("DISPLAY");
 
        if (display==NULL && dname!=NULL){
+               XInitThreads();
                display=XOpenDisplay(dname);
        }
 
@@ -941,6 +966,8 @@ static void lpc_apply_video_params(){
 #ifdef HAVE_X11_XLIB_H
                if (lpc_video_params.wid==0){  // do not manage window if embedded
                        x11_apply_video_params(&lpc_video_params,wid);
+               } else {
+                       linphone_core_show_video(linphonec, lpc_video_params.show);
                }
 #endif
        }
@@ -1240,6 +1267,7 @@ linphonec_parse_cmdline(int argc, char **argv)
                        if (arg_num < argc) {
                                char *tmp;
                                window_id = strtol( argv[arg_num], &tmp, 0 );
+                               lpc_video_params.wid = window_id;
                        }
                }
                else if (old_arg_num == arg_num)
@@ -1372,6 +1400,7 @@ copy_file(const char *from, const char *to)
                snprintf(message, 255, "Can't open %s for writing: %s\n",
                        to, strerror(errno));
                fprintf(stderr, "%s", message);
+               fclose(in);
                return 0;
        }
 
@@ -1380,6 +1409,8 @@ copy_file(const char *from, const char *to)
        {
                if ( ! fwrite(buf, 1, n, out) )
                {
+                       fclose(in);
+                       fclose(out);
                        return 0;
                }
        }