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