]> sjero.net Git - linphone/blob - console/linphonec.c
merge public branch
[linphone] / console / linphonec.c
1 /****************************************************************************
2  *
3  *  $Id: linphonec.c,v 1.57 2007/11/14 13:40:27 smorlat Exp $
4  *
5  *  Copyright (C) 2006  Sandro Santilli <strk@keybit.net>
6  *  Copyright (C) 2002  Florian Winterstein <flox@gmx.net>
7  *  Copyright (C) 2000  Simon MORLAT <simon.morlat@free.fr>
8  *
9 ****************************************************************************
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24  *
25  ****************************************************************************/
26 #include <string.h>
27 #ifndef _WIN32_WCE
28 #include <sys/time.h>
29 #include <sys/types.h>
30 #include <unistd.h>
31 #include <errno.h>
32 #include <signal.h>
33 #include "private.h" /*coreapi/private.h, needed for LINPHONE_VERSION */
34 #endif /*_WIN32_WCE*/
35 #include <limits.h>
36 #include <ctype.h>
37 #include <stdlib.h>
38
39 #include <linphonecore.h>
40
41 #include "linphonec.h"
42
43 #ifdef WIN32
44 #include <ws2tcpip.h>
45 #include <ctype.h>
46 #ifndef _WIN32_WCE
47 #include <conio.h>
48 #endif /*_WIN32_WCE*/
49 #else
50 #include <sys/socket.h>
51 #include <netdb.h>
52 #include <sys/un.h>
53 #include <sys/stat.h>
54 #endif
55
56 #if defined(_WIN32_WCE)
57
58 #if !defined(PATH_MAX)
59 #define PATH_MAX 256
60 #endif /*PATH_MAX*/
61
62 #if !defined(strdup)
63 #define strdup _strdup
64 #endif /*strdup*/
65
66 #endif /*_WIN32_WCE*/
67
68 #ifdef HAVE_GETTEXT
69 #include <libintl.h>
70 #ifndef _
71 #define _(String) gettext(String)
72 #endif
73 #else
74 #define _(something)    (something)
75 #endif
76
77 #ifndef PACKAGE_DIR
78 #define PACKAGE_DIR ""
79 #endif
80
81 #ifdef HAVE_X11_XLIB_H
82 #include <X11/Xlib.h>
83 #endif
84
85 /***************************************************************************
86  *
87  *  Types
88  *
89  ***************************************************************************/
90
91 typedef struct {
92         LinphoneAuthInfo *elem[MAX_PENDING_AUTH];
93         int nitems;
94 } LPC_AUTH_STACK;
95
96 /***************************************************************************
97  *
98  *  Forward declarations
99  *
100  ***************************************************************************/
101
102 char *lpc_strip_blanks(char *input);
103
104 static int handle_configfile_migration(void);
105 #if !defined(_WIN32_WCE)
106 static int copy_file(const char *from, const char *to);
107 #endif /*_WIN32_WCE*/
108 static int linphonec_parse_cmdline(int argc, char **argv);
109 static int linphonec_init(int argc, char **argv);
110 static int linphonec_main_loop (LinphoneCore * opm);
111 static int linphonec_idle_call (void);
112 #ifdef HAVE_READLINE
113 static int linphonec_initialize_readline(void);
114 static int linphonec_finish_readline();
115 static char **linephonec_readline_completion(const char *text,
116         int start, int end);
117 #endif
118
119 /* These are callback for linphone core */
120 static void linphonec_prompt_for_auth(LinphoneCore *lc, const char *realm,
121         const char *username);
122 static void linphonec_display_refer (LinphoneCore * lc, const char *refer_to);
123 static void linphonec_display_something (LinphoneCore * lc, const char *something);
124 static void linphonec_display_url (LinphoneCore * lc, const char *something, const char *url);
125 static void linphonec_display_warning (LinphoneCore * lc, const char *something);
126 static void linphonec_notify_received(LinphoneCore *lc, LinphoneCall *call, const char *from,const char *event);
127
128 static void linphonec_notify_presence_received(LinphoneCore *lc,LinphoneFriend *fid);
129 static void linphonec_new_unknown_subscriber(LinphoneCore *lc,
130                 LinphoneFriend *lf, const char *url);
131
132 static void linphonec_text_received(LinphoneCore *lc, LinphoneChatRoom *cr,
133                 const LinphoneAddress *from, const char *msg);
134 static void linphonec_display_status (LinphoneCore * lc, const char *something);
135 static void linphonec_dtmf_received(LinphoneCore *lc, LinphoneCall *call, int dtmf);
136 static void print_prompt(LinphoneCore *opm);
137 void linphonec_out(const char *fmt,...);
138 /***************************************************************************
139  *
140  * Global variables
141  *
142  ***************************************************************************/
143
144 LinphoneCore *linphonec;
145 FILE *mylogfile;
146 #ifdef HAVE_READLINE
147 static char *histfile_name=NULL;
148 static char last_in_history[256];
149 #endif
150 //auto answer (-a) option
151 static bool_t auto_answer=FALSE;
152 static bool_t answer_call=FALSE;
153 static bool_t vcap_enabled=FALSE;
154 static bool_t display_enabled=FALSE;
155 static bool_t preview_enabled=FALSE;
156 static bool_t show_general_state=FALSE;
157 static bool_t unix_socket=FALSE;
158 static bool_t linphonec_running=TRUE;
159 LPC_AUTH_STACK auth_stack;
160 static int trace_level = 0;
161 static char *logfile_name = NULL;
162 static char configfile_name[PATH_MAX];
163 static const char *factory_configfile_name=NULL;
164 static char *sip_addr_to_call = NULL; /* for autocall */
165 static int window_id = 0; /* 0=standalone window, or window id for embedding video */
166 #if !defined(_WIN32_WCE)
167 static ortp_pipe_t client_sock=ORTP_PIPE_INVALID;
168 #endif /*_WIN32_WCE*/
169 char prompt[PROMPT_MAX_LEN];
170 #if !defined(_WIN32_WCE)
171 static ortp_thread_t pipe_reader_th;
172 static bool_t pipe_reader_run=FALSE;
173 #endif /*_WIN32_WCE*/
174 #if !defined(_WIN32_WCE)
175 static ortp_pipe_t server_sock;
176 #endif /*_WIN32_WCE*/
177
178 bool_t linphonec_camera_enabled=TRUE;
179
180
181
182 void linphonec_call_identify(LinphoneCall* call){
183         static long callid=1;
184         linphone_call_set_user_pointer (call,(void*)callid);
185         callid++;
186 }
187
188 LinphoneCall *linphonec_get_call(long id){
189         const MSList *elem=linphone_core_get_calls(linphonec);
190         for (;elem!=NULL;elem=elem->next){
191                 LinphoneCall *call=(LinphoneCall*)elem->data;
192                 if (linphone_call_get_user_pointer (call)==(void*)id){
193                         return call;
194                 }
195         }
196         linphonec_out("Sorry, no call with id %i exists at this time.\n",id);
197         return NULL;
198 }
199
200 /***************************************************************************
201  *
202  * Linphone core callbacks
203  *
204  ***************************************************************************/
205
206 /*
207  * Linphone core callback
208  */
209 static void
210 linphonec_display_refer (LinphoneCore * lc, const char *refer_to)
211 {
212         linphonec_out("Receiving out of call refer to %s\n", refer_to);
213 }
214
215 /*
216  * Linphone core callback
217  */
218 static void
219 linphonec_display_something (LinphoneCore * lc, const char *something)
220 {
221         fprintf (stdout, "%s\n%s", something,prompt);
222         fflush(stdout);
223 }
224
225 /*
226  * Linphone core callback
227  */
228 static void
229 linphonec_display_status (LinphoneCore * lc, const char *something)
230 {
231         fprintf (stdout, "%s\n%s", something,prompt);
232         fflush(stdout);
233 }
234
235 /*
236  * Linphone core callback
237  */
238 static void
239 linphonec_display_warning (LinphoneCore * lc, const char *something)
240 {
241         fprintf (stdout, "Warning: %s\n%s", something,prompt);
242         fflush(stdout);
243 }
244
245 /*
246  * Linphone core callback
247  */
248 static void
249 linphonec_display_url (LinphoneCore * lc, const char *something, const char *url)
250 {
251         fprintf (stdout, "%s : %s\n", something, url);
252 }
253
254 /*
255  * Linphone core callback
256  */
257 static void
258 linphonec_prompt_for_auth(LinphoneCore *lc, const char *realm, const char *username)
259 {
260         /* no prompt possible when using pipes or tcp mode*/
261         if (unix_socket){
262                 linphone_core_abort_authentication(lc,NULL);
263         }else{
264                 LinphoneAuthInfo *pending_auth;
265
266                 if ( auth_stack.nitems+1 > MAX_PENDING_AUTH )
267                 {
268                         fprintf(stderr,
269                                 "Can't accept another authentication request.\n"
270                                 "Consider incrementing MAX_PENDING_AUTH macro.\n");
271                         return;
272                 }
273
274                 pending_auth=linphone_auth_info_new(username,NULL,NULL,NULL,realm);
275                 auth_stack.elem[auth_stack.nitems++]=pending_auth;
276         }
277 }
278
279 /*
280  * Linphone core callback
281  */
282 static void
283 linphonec_notify_received(LinphoneCore *lc, LinphoneCall *call, const char *from,const char *event)
284 {
285         if(!strcmp(event,"refer"))
286         {
287                 linphonec_out("The distand endpoint %s of call %li has been transfered, you can safely close the call.\n",
288                               from,(long)linphone_call_get_user_pointer (call));
289         }
290 }
291
292
293 /*
294  * Linphone core callback
295  */
296 static void
297 linphonec_notify_presence_received(LinphoneCore *lc,LinphoneFriend *fid)
298 {
299         char *tmp=linphone_address_as_string(linphone_friend_get_address(fid));
300         printf("Friend %s is %s\n", tmp, linphone_online_status_to_string(linphone_friend_get_status(fid)));
301         ms_free(tmp);
302         // todo: update Friend list state (unimplemented)
303 }
304
305 /*
306  * Linphone core callback
307  */
308 static void
309 linphonec_new_unknown_subscriber(LinphoneCore *lc, LinphoneFriend *lf,
310                 const char *url)
311 {
312         printf("Friend %s requested subscription "
313                 "(accept/deny is not implemented yet)\n", url);
314         // This means that this person wishes to be notified
315         // of your presence information (online, busy, away...).
316
317 }
318
319 static void linphonec_call_updated(LinphoneCall *call){
320         const LinphoneCallParams *cp=linphone_call_get_current_params(call);
321         if (!linphone_call_camera_enabled (call) && linphone_call_params_video_enabled (cp)){
322                 linphonec_out("Far end requests to share video.\nType 'camera on' if you agree.\n");
323         }
324 }
325
326 static void linphonec_call_state_changed(LinphoneCore *lc, LinphoneCall *call, LinphoneCallState st, const char *msg){
327         char *from=linphone_call_get_remote_address_as_string(call);
328         long id=(long)linphone_call_get_user_pointer (call);
329         switch(st){
330                 case LinphoneCallEnd:
331                         linphonec_out("Call %i with %s ended (%s).\n", id, from, linphone_reason_to_string(linphone_call_get_reason(call)));
332                 break;
333                 case LinphoneCallResuming:
334                         linphonec_out("Resuming call %i with %s.\n", id, from);
335                 break;
336                 case LinphoneCallStreamsRunning:
337                         linphonec_out("Media streams established with %s for call %i.\n", from,id);
338                 break;
339                 case LinphoneCallPausing:
340                         linphonec_out("Pausing call %i with %s.\n", id, from);
341                 break;
342                 case LinphoneCallPaused:
343                         linphonec_out("Call %i with %s is now paused.\n", id, from);
344                 break;
345                 case LinphoneCallPausedByRemote:
346                         linphonec_out("Call %i has been paused by %s.\n",id,from);
347                 break;
348                 case LinphoneCallIncomingReceived:
349                         linphonec_call_identify(call);
350                         linphone_call_enable_camera (call,linphonec_camera_enabled);
351                         id=(long)linphone_call_get_user_pointer (call);
352                         linphonec_set_caller(from);
353                         if ( auto_answer)  {
354                                 answer_call=TRUE;
355                         }
356                         linphonec_out("Receiving new incoming call from %s, assigned id %i\n", from,id);
357                 break;
358                 case LinphoneCallOutgoingInit:
359                         linphonec_call_identify(call);
360                         id=(long)linphone_call_get_user_pointer (call);
361                         linphonec_out("Establishing call id to %s, assigned id %i\n", from,id);
362                 break;
363                 case LinphoneCallUpdatedByRemote:
364                         linphonec_call_updated(call);
365                 break;
366                 case LinphoneCallOutgoingProgress:
367                         linphonec_out("Call %i to %s in progress.\n", id, from);
368                         break;
369                 case LinphoneCallOutgoingRinging:
370                         linphonec_out("Call %i to %s ringing.\n", id, from);
371                         break;
372                 case LinphoneCallConnected:
373                         linphonec_out("Call %i with %s connected.\n", id, from);
374                         break;
375                 case LinphoneCallOutgoingEarlyMedia:
376                         linphonec_out("Call %i with %s early media.\n", id, from);
377                         break;
378                 case LinphoneCallError:
379                         linphonec_out("Call %i with %s error.\n", id, from);
380                         break;
381                 default:
382                 break;
383         }
384         ms_free(from);
385 }
386
387 /*
388  * Linphone core callback
389  */
390 static void
391 linphonec_text_received(LinphoneCore *lc, LinphoneChatRoom *cr,
392                 const LinphoneAddress *from, const char *msg)
393 {
394         linphonec_out("Message received from %s: %s\n", linphone_address_as_string(from), msg);
395         // TODO: provide mechanism for answering.. ('say' command?)
396 }
397
398
399 static void linphonec_dtmf_received(LinphoneCore *lc, LinphoneCall *call, int dtmf){
400         char *from=linphone_call_get_remote_address_as_string(call);
401         fprintf(stdout,"Receiving tone %c from %s\n",dtmf,from);
402         fflush(stdout);
403         ms_free(from);
404 }
405
406 static char received_prompt[PROMPT_MAX_LEN];
407 static ms_mutex_t prompt_mutex;
408 static bool_t have_prompt=FALSE;
409
410 static void *prompt_reader_thread(void *arg){
411         char *ret;
412         char tmp[PROMPT_MAX_LEN];
413         while ((ret=fgets(tmp,sizeof(tmp),stdin))!=NULL){
414                 ms_mutex_lock(&prompt_mutex);
415                 strcpy(received_prompt,ret);
416                 have_prompt=TRUE;
417                 ms_mutex_unlock(&prompt_mutex);
418         }
419         return NULL;
420 }
421
422 static void start_prompt_reader(void){
423         ortp_thread_t th;
424         ms_mutex_init(&prompt_mutex,NULL);
425         ortp_thread_create(&th,NULL,prompt_reader_thread,NULL);
426 }
427 #if !defined(_WIN32_WCE)
428 static ortp_pipe_t create_server_socket(void){
429         char path[128];
430 #ifndef WIN32
431         snprintf(path,sizeof(path)-1,"linphonec-%i",getuid());
432 #else
433         {
434                 TCHAR username[128];
435                 DWORD size=sizeof(username)-1;
436                 GetUserName(username,&size);
437                 snprintf(path,sizeof(path)-1,"linphonec-%s",username);
438         }
439 #endif
440         return ortp_server_pipe_create(path);
441 }
442
443
444 static void *pipe_thread(void*p){
445         char tmp[250];
446         server_sock=create_server_socket();
447         if (server_sock==ORTP_PIPE_INVALID) return NULL;
448         while(pipe_reader_run){
449                 while(client_sock!=ORTP_PIPE_INVALID){ /*sleep until the last command is finished*/
450 #ifndef WIN32
451                         usleep(20000);
452 #else
453                         Sleep(20);
454 #endif
455                 }
456                 client_sock=ortp_server_pipe_accept_client(server_sock);
457                 if (client_sock!=ORTP_PIPE_INVALID){
458                         int len;
459                         /*now read from the client */
460                         if ((len=ortp_pipe_read(client_sock,(uint8_t*)tmp,sizeof(tmp)-1))>0){
461                                 ortp_mutex_lock(&prompt_mutex);
462                                 tmp[len]='\0';
463                                 strcpy(received_prompt,tmp);
464                                 printf("Receiving command '%s'\n",received_prompt);fflush(stdout);
465                                 have_prompt=TRUE;
466                                 ortp_mutex_unlock(&prompt_mutex);
467                         }else{
468                                 printf("read nothing\n");fflush(stdout);
469                                 ortp_server_pipe_close_client(client_sock);
470                                 client_sock=ORTP_PIPE_INVALID;
471                         }
472
473                 }else{
474                         if (pipe_reader_run) fprintf(stderr,"accept() failed: %s\n",strerror(errno));
475                 }
476         }
477         ms_message("Exiting pipe_reader_thread.");
478         fflush(stdout);
479         return NULL;
480 }
481
482 static void start_pipe_reader(void){
483         ms_mutex_init(&prompt_mutex,NULL);
484         pipe_reader_run=TRUE;
485         ortp_thread_create(&pipe_reader_th,NULL,pipe_thread,NULL);
486 }
487
488 static void stop_pipe_reader(void){
489         pipe_reader_run=FALSE;
490         linphonec_command_finished();
491         ortp_server_pipe_close(server_sock);
492         ortp_thread_join(pipe_reader_th,NULL);
493 }
494 #endif /*_WIN32_WCE*/
495
496 #ifdef HAVE_READLINE
497 #define BOOL_HAVE_READLINE 1
498 #else
499 #define BOOL_HAVE_READLINE 0
500 #endif
501
502 char *linphonec_readline(char *prompt){
503         if (unix_socket || !BOOL_HAVE_READLINE ){
504                 static bool_t prompt_reader_started=FALSE;
505                 static bool_t pipe_reader_started=FALSE;
506                 if (!prompt_reader_started){
507                         start_prompt_reader();
508                         prompt_reader_started=TRUE;
509                 }
510                 if (unix_socket && !pipe_reader_started){
511 #if !defined(_WIN32_WCE)
512                         start_pipe_reader();
513                         pipe_reader_started=TRUE;
514 #endif /*_WIN32_WCE*/
515                 }
516                 fprintf(stdout,"%s",prompt);
517                 fflush(stdout);
518                 while(1){
519                         ms_mutex_lock(&prompt_mutex);
520                         if (have_prompt){
521                                 char *ret=strdup(received_prompt);
522                                 have_prompt=FALSE;
523                                 ms_mutex_unlock(&prompt_mutex);
524                                 return ret;
525                         }
526                         ms_mutex_unlock(&prompt_mutex);
527                         linphonec_idle_call();
528 #ifdef WIN32
529                         Sleep(20);
530                         /* Following is to get the video window going as it
531                                  should. Maybe should we only have this on when the option -V
532                                  or -D is on? */
533                         MSG msg;
534         
535                         if (PeekMessage(&msg, NULL, 0, 0,1)) {
536                                 TranslateMessage(&msg);
537                                 DispatchMessage(&msg);
538                         }
539 #else
540                         usleep(20000);
541 #endif
542                 }
543         }else{
544 #ifdef HAVE_READLINE
545                 return readline(prompt);
546 #endif
547         }
548 }
549
550 void linphonec_out(const char *fmt,...){
551         char *res;
552         va_list args;
553         va_start (args, fmt);
554         res=ortp_strdup_vprintf(fmt,args);
555         va_end (args);
556         printf("%s",res);
557         fflush(stdout);
558 #if !defined(_WIN32_WCE)
559         if (client_sock!=ORTP_PIPE_INVALID){
560                 if (ortp_pipe_write(client_sock,(uint8_t*)res,strlen(res))==-1){
561                         fprintf(stderr,"Fail to send output via pipe: %s",strerror(errno));
562                 }
563         }
564 #endif /*_WIN32_WCE*/
565         ortp_free(res);
566 }
567
568 void linphonec_command_finished(void){
569 #if !defined(_WIN32_WCE)
570         if (client_sock!=ORTP_PIPE_INVALID){
571                 ortp_server_pipe_close_client(client_sock);
572                 client_sock=ORTP_PIPE_INVALID;
573         }
574 #endif /*_WIN32_WCE*/
575 }
576
577 void linphonec_set_autoanswer(bool_t enabled){
578         auto_answer=enabled;
579 }
580
581 bool_t linphonec_get_autoanswer(){
582         return auto_answer;
583 }
584
585 LinphoneCoreVTable linphonec_vtable={0};
586
587 /***************************************************************************/
588 /*
589  * Main
590  *
591  * Use globals:
592  *
593  *      - char *histfile_name
594  *      - FILE *mylogfile
595  */
596 #if defined (_WIN32_WCE)
597
598 char **convert_args_to_ascii(int argc, _TCHAR **wargv){
599         int i;
600         char **result=malloc(argc*sizeof(char*));
601         char argtmp[128];
602         for(i=0;i<argc;++i){
603                 wcstombs(argtmp,wargv[i],sizeof(argtmp));
604                 result[i]=strdup(argtmp);
605         }
606         return result;
607 }
608
609 int _tmain(int argc, _TCHAR* wargv[]) {
610         char **argv=convert_args_to_ascii(argc,wargv);
611         trace_level=6;
612
613 #else
614 int
615 main (int argc, char *argv[]) {
616 #endif
617         linphonec_vtable.call_state_changed=linphonec_call_state_changed;
618         linphonec_vtable.notify_presence_recv = linphonec_notify_presence_received;
619         linphonec_vtable.new_subscription_request = linphonec_new_unknown_subscriber;
620         linphonec_vtable.auth_info_requested = linphonec_prompt_for_auth;
621         linphonec_vtable.display_status = linphonec_display_status;
622         linphonec_vtable.display_message=linphonec_display_something;
623         linphonec_vtable.display_warning=linphonec_display_warning;
624         linphonec_vtable.display_url=linphonec_display_url;
625         linphonec_vtable.text_received=linphonec_text_received;
626         linphonec_vtable.dtmf_received=linphonec_dtmf_received;
627         linphonec_vtable.refer_received=linphonec_display_refer;
628         linphonec_vtable.notify_recv=linphonec_notify_received;
629         
630         if (! linphonec_init(argc, argv) ) exit(EXIT_FAILURE);
631
632         linphonec_main_loop (linphonec);
633
634         linphonec_finish(EXIT_SUCCESS);
635
636         exit(EXIT_SUCCESS); /* should never reach here */
637 }
638
639 /*
640  * Initialize linphonec
641  */
642 static int
643 linphonec_init(int argc, char **argv)
644 {
645
646         //g_mem_set_vtable(&dbgtable);
647
648         /*
649          * Set initial values for global variables
650          */
651         mylogfile = NULL;
652         
653         
654 #ifndef _WIN32
655         snprintf(configfile_name, PATH_MAX, "%s/.linphonerc",
656                         getenv("HOME"));
657 #elif defined(_WIN32_WCE)
658         strncpy(configfile_name,PACKAGE_DIR "\\linphonerc",PATH_MAX);
659         mylogfile=fopen(PACKAGE_DIR "\\" "linphonec.log","w");
660         printf("Logs are redirected in" PACKAGE_DIR "\\linphonec.log");
661 #else
662         snprintf(configfile_name, PATH_MAX, "%s/Linphone/linphonerc",
663                         getenv("APPDATA"));
664 #endif
665         /* Handle configuration filename changes */
666         switch (handle_configfile_migration())
667         {
668                 case -1: /* error during file copies */
669                         fprintf(stderr,
670                                 "Error in configuration file migration\n");
671                         break;
672
673                 case 0: /* nothing done */
674                 case 1: /* migrated */
675                 default:
676                         break;
677         }
678
679 #ifdef ENABLE_NLS
680         if (NULL == bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR))
681                 perror ("bindtextdomain failed");
682 #ifndef __ARM__
683         bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
684 #endif
685         textdomain (GETTEXT_PACKAGE);
686 #else
687         printf ("NLS disabled.\n");
688 #endif
689
690         linphonec_parse_cmdline(argc, argv);
691
692         if (trace_level > 0)
693         {
694                 if (logfile_name != NULL)
695                         mylogfile = fopen (logfile_name, "w+");
696
697                 if (mylogfile == NULL)
698                 {
699                         mylogfile = stdout;
700                         fprintf (stderr,
701                                  "INFO: no logfile, logging to stdout\n");
702                 }
703                 linphone_core_enable_logs(mylogfile);
704         }
705         else
706         {
707                 linphone_core_disable_logs();
708         }
709         /*
710          * Initialize auth stack
711          */
712         auth_stack.nitems=0;
713
714         /*
715          * Initialize linphone core
716          */
717         linphonec=linphone_core_new (&linphonec_vtable, configfile_name, factory_configfile_name, NULL);
718         linphone_core_enable_video(linphonec,vcap_enabled,display_enabled);
719         if (display_enabled && window_id != 0) 
720         {
721                 printf ("Setting window_id: 0x%x\n", window_id);
722                 linphone_core_set_native_video_window_id(linphonec,window_id);
723         }
724
725         linphone_core_enable_video_preview(linphonec,preview_enabled);
726         if (!(vcap_enabled || display_enabled)) printf("Warning: video is disabled in linphonec, use -V or -C or -D to enable.\n");
727 #ifdef HAVE_READLINE
728         /*
729          * Initialize readline
730          */
731         linphonec_initialize_readline();
732 #endif
733 #if !defined(_WIN32_WCE)
734         /*
735          * Initialize signal handlers
736          */
737         signal(SIGTERM, linphonec_finish);
738         signal(SIGINT, linphonec_finish);
739 #endif /*_WIN32_WCE*/
740         return 1;
741 }
742
743
744 void linphonec_main_loop_exit(void){
745         linphonec_running=FALSE;
746 }
747
748 /*
749  * Close linphonec, cleanly terminating
750  * any pending call
751  */
752 void
753 linphonec_finish(int exit_status)
754 {
755         // Do not allow concurrent destroying to prevent glibc errors
756         static bool_t terminating=FALSE;
757         if (terminating) return; 
758         terminating=TRUE;
759         linphonec_out("Terminating...\n");
760
761         /* Terminate any pending call */
762         linphone_core_terminate_all_calls(linphonec);
763 #ifdef HAVE_READLINE
764         linphonec_finish_readline();
765 #endif
766 #if !defined(_WIN32_WCE)
767         if (pipe_reader_run)
768                 stop_pipe_reader();
769 #endif /*_WIN32_WCE*/
770
771         linphone_core_destroy (linphonec);
772
773         if (mylogfile != NULL && mylogfile != stdout)
774         {
775                 fclose (mylogfile);
776         }
777         printf("\n");
778         exit(exit_status);
779
780 }
781
782 /*
783  * This is called from idle_call() whenever
784  * pending_auth != NULL.
785  *
786  * It prompts user for a password.
787  * Hitting ^D (EOF) would make this function
788  * return 0 (Cancel).
789  * Any other input would try to set linphone core
790  * auth_password for the pending_auth, add the auth_info
791  * and return 1.
792  */
793 int
794 linphonec_prompt_for_auth_final(LinphoneCore *lc)
795 {
796         static int reentrancy=0;
797         char *input, *iptr;
798         char auth_prompt[256];
799 #ifdef HAVE_READLINE
800         rl_hook_func_t *old_event_hook;
801 #endif
802
803         if (reentrancy!=0) return 0;
804         
805         reentrancy++;
806         
807         LinphoneAuthInfo *pending_auth=auth_stack.elem[auth_stack.nitems-1];
808
809         snprintf(auth_prompt, 256, "Password for %s on %s: ",
810                 pending_auth->username, pending_auth->realm);
811
812         printf("\n");
813 #ifdef HAVE_READLINE
814         /*
815          * Disable event hook to avoid entering an
816          * infinite loop. This would prevent idle_call
817          * from being called during authentication reads.
818          * Note that it might be undesiderable...
819          */
820         old_event_hook=rl_event_hook;
821         rl_event_hook=NULL;
822 #endif
823
824         while (1)
825         {
826                 input=linphonec_readline(auth_prompt);
827
828                 /*
829                  * If EOF (^D) is sent you probably don't want
830                  * to provide an auth password... should give up
831                  * the operation, but there's no mechanism to
832                  * send this info back to caller currently...
833                  */
834                 if ( ! input )
835                 {
836                         printf("Cancel requested, but not implemented.\n");
837                         continue;
838                 }
839
840                 /* Strip blanks */
841                 iptr=lpc_strip_blanks(input);
842
843                 /*
844                  * Only blanks, continue asking
845                  */
846                 if ( ! *iptr )
847                 {
848                         free(input);
849                         continue;
850                 }
851
852                 /* Something typed, let's try */
853                 break;
854         }
855
856         /*
857          * No check is done here to ensure password is correct.
858          * I guess password will be asked again later.
859          */
860         linphone_auth_info_set_passwd(pending_auth, input);
861         linphone_core_add_auth_info(lc, pending_auth);
862         linphone_auth_info_destroy(pending_auth);
863         auth_stack.elem[auth_stack.nitems-1]=0;
864         --(auth_stack.nitems);
865 #ifdef HAVE_READLINE
866         /*
867          * Reset line_buffer, to avoid the password
868          * to be used again from outer readline
869          */
870         rl_line_buffer[0]='\0';
871         rl_event_hook=old_event_hook;
872 #endif
873         return 1;
874 }
875
876 void
877 print_usage (int exit_status)
878 {
879         fprintf (stdout, "\n\
880 usage: linphonec [-c file] [-s sipaddr] [-a] [-V] [-d level ] [-l logfile]\n\
881        linphonec -v\n\
882 \n\
883   -b  file             specify path of readonly factory configuration file.\n\
884   -c  file             specify path of configuration file.\n\
885   -d  level            be verbose. 0 is no output. 6 is all output\n\
886   -l  logfile          specify the log file for your SIP phone\n\
887   -s  sipaddress       specify the sip call to do at startup\n\
888   -a                   enable auto answering for incoming calls\n\
889   -V                   enable video features globally (disabled by default)\n\
890   -C                   enable video capture only (disabled by default)\n\
891   -D                   enable video display only (disabled by default)\n\
892   -S                   show general state messages (disabled by default)\n\
893   --wid  windowid      force embedding of video window into provided windowid (disabled by default)\n\
894   -v or --version      display version and exits.\n");
895
896         exit(exit_status);
897 }
898
899 #ifdef VIDEO_ENABLED
900
901 #ifdef HAVE_X11_XLIB_H
902 static void x11_apply_video_params(VideoParams *params, Window window){
903         XWindowChanges wc;
904         unsigned int flags=0;
905         static Display *display = NULL;
906         const char *dname=getenv("DISPLAY");
907
908         if (display==NULL && dname!=NULL){
909                 display=XOpenDisplay(dname);
910         }
911
912         if (display==NULL){
913                 ms_error("Could not open display %s",dname);
914                 return;
915         }
916         memset(&wc,0,sizeof(wc));
917         wc.x=params->x;
918         wc.y=params->y;
919         wc.width=params->w;
920         wc.height=params->h;
921         if (params->x!=-1 ){
922                 flags|=CWX|CWY;
923         }
924         if (params->w!=-1){
925                 flags|=CWWidth|CWHeight;
926         }
927         /*printf("XConfigureWindow x=%i,y=%i,w=%i,h=%i\n",
928                wc.x, wc.y ,wc.width, wc.height);*/
929         XConfigureWindow(display,window,flags,&wc);
930         if (params->show)
931                 XMapWindow(display,window);
932         else
933                 XUnmapWindow(display,window);
934         XSync(display,FALSE);
935 }
936 #endif
937
938
939 static void lpc_apply_video_params(){
940         static unsigned long old_wid=0,old_pwid=0;
941         unsigned long wid=linphone_core_get_native_video_window_id (linphonec);
942         unsigned long pwid=linphone_core_get_native_preview_window_id (linphonec);
943
944         if (wid!=0 && (lpc_video_params.refresh || old_wid!=wid)){
945                 lpc_video_params.refresh=FALSE;
946 #ifdef HAVE_X11_XLIB_H
947                 if (lpc_video_params.wid==0){  // do not manage window if embedded
948                         x11_apply_video_params(&lpc_video_params,wid);
949                 }
950 #endif
951         }
952         old_wid=wid;
953         if (pwid!=0 && (lpc_preview_params.refresh || old_pwid!=pwid)){
954                 lpc_preview_params.refresh=FALSE;
955 #ifdef HAVE_X11_XLIB_H
956                 /*printf("wid=%lu pwid=%lu\n",wid,pwid);*/
957                 if (lpc_preview_params.wid==0){  // do not manage window if embedded
958                         printf("Refreshing\n");
959                         x11_apply_video_params(&lpc_preview_params,pwid);
960                 }
961 #endif
962         }
963         old_pwid=pwid;
964 }
965
966 #endif
967
968
969 /*
970  *
971  * Called every second from main read loop.
972  *
973  * Will use the following globals:
974  *
975  *  - LinphoneCore linphonec
976  *  - LPC_AUTH_STACK auth_stack;
977  *
978  */
979 static int
980 linphonec_idle_call ()
981 {
982         LinphoneCore *opm=linphonec;
983
984         /* Uncomment the following to verify being called */
985         /* printf(".\n"); */
986
987         linphone_core_iterate(opm);
988         if (answer_call){
989                 fprintf (stdout, "-------auto answering to call-------\n" );
990                 linphone_core_accept_call(opm,NULL);
991                 answer_call=FALSE;
992         }
993         /* auto call handling */
994         if (sip_addr_to_call != NULL )
995         {
996                 char buf[512];
997                 snprintf (buf, sizeof(buf),"call %s", sip_addr_to_call);
998                 sip_addr_to_call=NULL;
999                 linphonec_parse_command_line(linphonec, buf);
1000         }
1001
1002         if ( auth_stack.nitems )
1003         {
1004                 /*
1005                  * Inhibit command completion
1006                  * during password prompts
1007                  */
1008 #ifdef HAVE_READLINE
1009                 rl_inhibit_completion=1;
1010 #endif
1011                 linphonec_prompt_for_auth_final(opm);
1012 #ifdef HAVE_READLINE
1013                 rl_inhibit_completion=0;
1014 #endif
1015         }
1016
1017 #ifdef VIDEO_ENABLED
1018         lpc_apply_video_params();
1019 #endif
1020
1021         return 0;
1022 }
1023
1024 #ifdef HAVE_READLINE
1025 /*
1026  * Use globals:
1027  *
1028  *      - char *histfile_name (also sets this)
1029  *      - char *last_in_history (allocates it)
1030  */
1031 static int
1032 linphonec_initialize_readline()
1033 {
1034         /*rl_bind_key('\t', rl_insert);*/
1035
1036         /* Allow conditional parsing of ~/.inputrc */
1037         rl_readline_name = "linphonec";
1038
1039         /* Call idle_call() every second */
1040         rl_set_keyboard_input_timeout(LPC_READLINE_TIMEOUT);
1041         rl_event_hook=linphonec_idle_call;
1042
1043         /* Set history file and read it */
1044         histfile_name = ms_strdup_printf ("%s/.linphonec_history",
1045                 getenv("HOME"));
1046         read_history(histfile_name);
1047
1048         /* Initialized last_in_history cache*/
1049         last_in_history[0] = '\0';
1050
1051         /* Register a completion function */
1052         rl_attempted_completion_function = linephonec_readline_completion;
1053
1054         /* printf("Readline initialized.\n"); */
1055         setlinebuf(stdout);
1056         return 0;
1057 }
1058
1059 /*
1060  * Uses globals:
1061  *
1062  *      - char *histfile_name (writes history to file and frees it)
1063  *      - char *last_in_history (frees it)
1064  *
1065  */
1066 static int
1067 linphonec_finish_readline()
1068 {
1069
1070         stifle_history(HISTSIZE);
1071         write_history(histfile_name);
1072         free(histfile_name);
1073         histfile_name=NULL;
1074         return 0;
1075 }
1076
1077 #endif
1078
1079 static void print_prompt(LinphoneCore *opm){
1080 #ifdef IDENTITY_AS_PROMPT
1081         snprintf(prompt, PROMPT_MAX_LEN, "%s> ",
1082                 linphone_core_get_primary_contact(opm));
1083 #else
1084         snprintf(prompt, PROMPT_MAX_LEN, "linphonec> ");
1085 #endif
1086 }
1087
1088 static int
1089 linphonec_main_loop (LinphoneCore * opm)
1090 {
1091         char *input;
1092
1093         print_prompt(opm);
1094
1095
1096         while (linphonec_running && (input=linphonec_readline(prompt)))
1097         {
1098                 char *iptr; /* input and input pointer */
1099                 size_t input_len;
1100
1101                 /* Strip blanks */
1102                 iptr=lpc_strip_blanks(input);
1103
1104                 input_len = strlen(iptr);
1105
1106                 /*
1107                  * Do nothing but release memory
1108                  * if only blanks are read
1109                  */
1110                 if ( ! input_len )
1111                 {
1112                         free(input);
1113                         continue;
1114                 }
1115
1116 #ifdef HAVE_READLINE
1117                 /*
1118                  * Only add to history if not already
1119                  * last item in it, and only if the command
1120                  * doesn't start with a space (to allow for
1121                  * hiding passwords)
1122                  */
1123                 if ( iptr == input && strcmp(last_in_history, iptr) )
1124                 {
1125                         strncpy(last_in_history,iptr,sizeof(last_in_history));
1126                         last_in_history[sizeof(last_in_history)-1]='\0';
1127                         add_history(iptr);
1128                 }
1129 #endif
1130
1131                 linphonec_parse_command_line(linphonec, iptr);
1132                 linphonec_command_finished();
1133                 free(input);
1134         }
1135
1136         return 0;
1137 }
1138
1139 /*
1140  *  Parse command line switches
1141  *
1142  *  Use globals:
1143  *
1144  *      - int trace_level
1145  *      - char *logfile_name
1146  *      - char *configfile_name
1147  *      - char *sipAddr
1148  */
1149 static int
1150 linphonec_parse_cmdline(int argc, char **argv)
1151 {
1152         int arg_num=1;
1153
1154         while (arg_num < argc)
1155         {
1156                 int old_arg_num = arg_num;
1157                 if (strncmp ("-d", argv[arg_num], 2) == 0)
1158                 {
1159                         arg_num++;
1160                         if (arg_num < argc)
1161                                 trace_level = atoi (argv[arg_num]);
1162                         else
1163                                 trace_level = 1;
1164                 }
1165                 else if (strncmp ("-l", argv[arg_num], 2) == 0)
1166                 {
1167                         arg_num++;
1168                         if (arg_num < argc)
1169                                 logfile_name = argv[arg_num];
1170                 }
1171                 else if (strncmp ("-c", argv[arg_num], 2) == 0)
1172                 {
1173                         if ( ++arg_num >= argc ) print_usage(EXIT_FAILURE);
1174 #if !defined(_WIN32_WCE)
1175                         if (access(argv[arg_num],F_OK)!=0 )
1176                         {
1177                                 fprintf (stderr,
1178                                         "Cannot open config file %s.\n",
1179                                          argv[arg_num]);
1180                                 exit(EXIT_FAILURE);
1181                         }
1182 #endif /*_WIN32_WCE*/
1183                         snprintf(configfile_name, PATH_MAX, "%s", argv[arg_num]);
1184                 }
1185                 else if (strncmp ("-b", argv[arg_num], 2) == 0)
1186                 {
1187                         if ( ++arg_num >= argc ) print_usage(EXIT_FAILURE);
1188 #if !defined(_WIN32_WCE)
1189                         if (access(argv[arg_num],F_OK)!=0 )
1190                         {
1191                                 fprintf (stderr,
1192                                         "Cannot open config file %s.\n",
1193                                          argv[arg_num]);
1194                                 exit(EXIT_FAILURE);
1195                         }
1196 #endif /*_WIN32_WCE*/
1197                         factory_configfile_name = argv[arg_num];
1198                 }
1199                 else if (strncmp ("-s", argv[arg_num], 2) == 0)
1200                 {
1201                         arg_num++;
1202                         if (arg_num < argc)
1203                                 sip_addr_to_call = argv[arg_num];
1204                 }
1205                 else if (strncmp ("-a", argv[arg_num], 2) == 0)
1206                 {
1207                         auto_answer = TRUE;
1208                 }
1209                 else if (strncmp ("-C", argv[arg_num], 2) == 0)
1210                 {
1211                         vcap_enabled = TRUE;
1212                 }
1213                 else if (strncmp ("-D", argv[arg_num], 2) == 0)
1214                 {
1215                         display_enabled = TRUE;
1216                 }
1217                 else if (strncmp ("-V", argv[arg_num], 2) == 0)
1218                 {
1219                         display_enabled = TRUE;
1220                         vcap_enabled = TRUE;
1221                         preview_enabled=TRUE;
1222                 }
1223                 else if ((strncmp ("-v", argv[arg_num], 2) == 0)
1224                          ||
1225                          (strncmp
1226                           ("--version", argv[arg_num],
1227                            strlen ("--version")) == 0))
1228                 {
1229 #if !defined(_WIN32_WCE)
1230                         printf ("version: " LINPHONE_VERSION "\n");
1231 #endif
1232                         exit (EXIT_SUCCESS);
1233                 }
1234                 else if (strncmp ("-S", argv[arg_num], 2) == 0)
1235                 {
1236                         show_general_state = TRUE;
1237                 }
1238                 else if (strncmp ("--pipe", argv[arg_num], 6) == 0)
1239                 {
1240                         unix_socket=1;
1241                 }
1242                 else if (strncmp ("--wid", argv[arg_num], 5) == 0)
1243                 {
1244                         arg_num++;
1245                         if (arg_num < argc) {
1246                                 char *tmp;
1247                                 window_id = strtol( argv[arg_num], &tmp, 0 );
1248                         }
1249                 }
1250                 else if (old_arg_num == arg_num)
1251                 {
1252                         fprintf (stderr, "ERROR: bad arguments\n");
1253                         print_usage (EXIT_FAILURE);
1254                 }
1255                 arg_num++;
1256         }
1257
1258         return 1;
1259 }
1260
1261 /*
1262  * Up to version 1.2.1 linphone used ~/.linphonec for
1263  * CLI and ~/.gnome2/linphone for GUI as configuration file.
1264  * In newer version both interfaces will use ~/.linphonerc.
1265  *
1266  * This function helps transparently migrating from one
1267  * to the other layout using the following heuristic:
1268  *
1269  *      IF new_config EXISTS => do nothing
1270  *      ELSE IF old_cli_config EXISTS => copy to new_config
1271  *      ELSE IF old_gui_config EXISTS => copy to new_config
1272  *
1273  * Returns:
1274  *       0 if it did nothing
1275  *       1 if it migrated successfully
1276  *      -1 on error
1277  */
1278 static int
1279 handle_configfile_migration()
1280 {
1281 #if !defined(_WIN32_WCE)
1282         char *old_cfg_gui;
1283         char *old_cfg_cli;
1284         char *new_cfg;
1285 #if !defined(_WIN32_WCE)
1286         const char *home = getenv("HOME");
1287 #else
1288         const char *home = ".";
1289 #endif /*_WIN32_WCE*/
1290         new_cfg = ms_strdup_printf("%s/.linphonerc", home);
1291
1292         /*
1293          * If the *NEW* configuration already exists
1294          * do nothing.
1295          */
1296         if (access(new_cfg,F_OK)==0)
1297         {
1298                 free(new_cfg);
1299                 return 0;
1300         }
1301
1302         old_cfg_cli = ms_strdup_printf("%s/.linphonec", home);
1303
1304         /*
1305          * If the *OLD* CLI configurations exist copy it to
1306          * the new file and make it a symlink.
1307          */
1308         if (access(old_cfg_cli, F_OK)==0)
1309         {
1310                 if ( ! copy_file(old_cfg_cli, new_cfg) )
1311                 {
1312                         free(old_cfg_cli);
1313                         free(new_cfg);
1314                         return -1;
1315                 }
1316                 printf("%s copied to %s\n", old_cfg_cli, new_cfg);
1317                 free(old_cfg_cli);
1318                 free(new_cfg);
1319                 return 1;
1320         }
1321
1322         free(old_cfg_cli);
1323         old_cfg_gui = ms_strdup_printf("%s/.gnome2/linphone", home);
1324
1325         /*
1326          * If the *OLD* GUI configurations exist copy it to
1327          * the new file and make it a symlink.
1328          */
1329         if (access(old_cfg_gui, F_OK)==0)
1330         {
1331                 if ( ! copy_file(old_cfg_gui, new_cfg) )
1332                 {
1333                         exit(EXIT_FAILURE);
1334                         free(old_cfg_gui);
1335                         free(new_cfg);
1336                         return -1;
1337                 }
1338                 printf("%s copied to %s\n", old_cfg_gui, new_cfg);
1339                 free(old_cfg_gui);
1340                 free(new_cfg);
1341                 return 1;
1342         }
1343
1344         free(old_cfg_gui);
1345         free(new_cfg);
1346 #endif /*_WIN32_WCE*/
1347         return 0;
1348 }
1349 #if !defined(_WIN32_WCE)
1350 /*
1351  * Copy file "from" to file "to".
1352  * Destination file is truncated if existing.
1353  * Return 1 on success, 0 on error (printing an error).
1354  */
1355 static int
1356 copy_file(const char *from, const char *to)
1357 {
1358         char message[256];
1359         FILE *in, *out;
1360         char buf[256];
1361         size_t n;
1362
1363         /* Open "from" file for reading */
1364         in=fopen(from, "r");
1365         if ( in == NULL )
1366         {
1367                 snprintf(message, 255, "Can't open %s for reading: %s\n",
1368                         from, strerror(errno));
1369                 fprintf(stderr, "%s", message);
1370                 return 0;
1371         }
1372
1373         /* Open "to" file for writing (will truncate existing files) */
1374         out=fopen(to, "w");
1375         if ( out == NULL )
1376         {
1377                 snprintf(message, 255, "Can't open %s for writing: %s\n",
1378                         to, strerror(errno));
1379                 fprintf(stderr, "%s", message);
1380                 return 0;
1381         }
1382
1383         /* Copy data from "in" to "out" */
1384         while ( (n=fread(buf, 1, sizeof buf, in)) > 0 )
1385         {
1386                 if ( ! fwrite(buf, 1, n, out) )
1387                 {
1388                         return 0;
1389                 }
1390         }
1391
1392         fclose(in);
1393         fclose(out);
1394
1395         return 1;
1396 }
1397 #endif /*_WIN32_WCE*/
1398
1399 #ifdef HAVE_READLINE
1400 static char **
1401 linephonec_readline_completion(const char *text, int start, int end)
1402 {
1403         char **matches = NULL;
1404
1405         /*
1406          * Prevent readline from falling
1407          * back to filename-completion
1408          */
1409         rl_attempted_completion_over=1;
1410
1411         /*
1412          * If this is the start of line we complete with commands
1413          */
1414         if ( ! start )
1415         {
1416                 return rl_completion_matches(text, linphonec_command_generator);
1417         }
1418
1419         /*
1420          * Otherwise, we should peek at command name
1421          * or context to implement a smart completion.
1422          * For example: "call .." could return
1423          * friends' sip-uri as matches
1424          */
1425
1426         return matches;
1427 }
1428
1429 #endif
1430
1431 /*
1432  * Strip blanks from a string.
1433  * Return a pointer into the provided string.
1434  * Modifies input adding a NULL at first
1435  * of trailing blanks.
1436  */
1437 char *
1438 lpc_strip_blanks(char *input)
1439 {
1440         char *iptr;
1441
1442         /* Find first non-blank */
1443         while(*input && isspace(*input)) ++input;
1444
1445         /* Find last non-blank */
1446         iptr=input+strlen(input);
1447         if (iptr > input) {
1448                 while(isspace(*--iptr));
1449                 *(iptr+1)='\0';
1450         }
1451
1452         return input;
1453 }
1454
1455 /****************************************************************************
1456  *
1457  * $Log: linphonec.c,v $
1458  * Revision 1.57  2007/11/14 13:40:27  smorlat
1459  * fix --disable-video build.
1460  *
1461  * Revision 1.56  2007/09/26 14:07:27  fixkowalski
1462  * - ANSI/C++ compilation issues with non-GCC compilers
1463  * - Faster epm-based packaging
1464  * - Ability to build & run on FC6's eXosip/osip
1465  *
1466  * Revision 1.55  2007/09/24 16:01:58  smorlat
1467  * fix bugs.
1468  *
1469  * Revision 1.54  2007/08/22 14:06:11  smorlat
1470  * authentication bugs fixed.
1471  *
1472  * Revision 1.53  2007/02/13 21:31:01  smorlat
1473  * added patch for general state.
1474  * new doxygen for oRTP
1475  * gtk-doc removed.
1476  *
1477  * Revision 1.52  2007/01/10 14:11:24  smorlat
1478  * add --video to linphonec.
1479  *
1480  * Revision 1.51  2006/08/21 12:49:59  smorlat
1481  * merged several little patches.
1482  *
1483  * Revision 1.50  2006/07/26 08:17:28  smorlat
1484  * fix bugs.
1485  *
1486  * Revision 1.49  2006/07/17 18:45:00  smorlat
1487  * support for several event queues in ortp.
1488  * glib dependency removed from coreapi/ and console/
1489  *
1490  * Revision 1.48  2006/04/09 12:45:32  smorlat
1491  * linphonec improvements.
1492  *
1493  * Revision 1.47  2006/04/04 08:04:34  smorlat
1494  * switched to mediastreamer2, most bugs fixed.
1495  *
1496  * Revision 1.46  2006/03/16 17:17:40  smorlat
1497  * fix various bugs.
1498  *
1499  * Revision 1.45  2006/03/12 21:48:31  smorlat
1500  * gcc-2.95 compile error fixed.
1501  * mediastreamer2 in progress
1502  *
1503  * Revision 1.44  2006/03/04 11:17:10  smorlat
1504  * mediastreamer2 in progress.
1505  *
1506  * Revision 1.43  2006/02/13 09:50:50  strk
1507  * fixed unused variable warning.
1508  *
1509  * Revision 1.42  2006/02/02 15:39:18  strk
1510  * - Added 'friend list' and 'friend call' commands
1511  * - Allowed for multiple DTFM send in a single line
1512  * - Added status-specific callback (bare version)
1513  *
1514  * Revision 1.41  2006/02/02 13:30:05  strk
1515  * - Padded vtable with missing callbacks
1516  *   (fixing a segfault on friends subscription)
1517  * - Handled friends notify (bare version)
1518  * - Handled text messages receive (bare version)
1519  * - Printed message on subscription request (bare version)
1520  *
1521  * Revision 1.40  2006/01/26 09:48:05  strk
1522  * Added limits.h include
1523  *
1524  * Revision 1.39  2006/01/26 02:11:01  strk
1525  * Removed unused variables, fixed copyright date
1526  *
1527  * Revision 1.38  2006/01/25 18:33:02  strk
1528  * Removed the -t swich, terminate_on_close made the default behaviour
1529  *
1530  * Revision 1.37  2006/01/20 14:12:34  strk
1531  * Added linphonec_init() and linphonec_finish() functions.
1532  * Handled SIGINT and SIGTERM to invoke linphonec_finish().
1533  * Handling of auto-termination (-t) moved to linphonec_finish().
1534  * Reworked main (input read) loop to not rely on 'terminate'
1535  * and 'run' variable (dropped). configfile_name allocated on stack
1536  * using PATH_MAX limit. Changed print_usage signature to allow
1537  * for an exit_status specification.
1538  *
1539  * Revision 1.36  2006/01/18 09:25:32  strk
1540  * Command completion inhibited in proxy addition and auth request prompts.
1541  * Avoided use of readline's internal filename completion.
1542  *
1543  * Revision 1.35  2006/01/14 13:29:32  strk
1544  * Reworked commands interface to use a table structure,
1545  * used by command line parser and help function.
1546  * Implemented first level of completion (commands).
1547  * Added notification of invalid "answer" and "terminate"
1548  * commands (no incoming call, no active call).
1549  * Forbidden "call" intialization when a call is already active.
1550  * Cleaned up all commands, adding more feedback and error checks.
1551  *
1552  * Revision 1.34  2006/01/13 13:00:29  strk
1553  * Added linphonec.h. Code layout change (added comments, forward decl,
1554  * globals on top, copyright notices and Logs). Handled out-of-memory
1555  * condition on history management. Removed assumption on sizeof(char).
1556  * Fixed bug in authentication prompt (introduced by readline).
1557  * Added support for multiple authentication requests (up to MAX_PENDING_AUTH).
1558  *
1559  *
1560  ****************************************************************************/
1561