]> sjero.net Git - linphone/blob - console/linphonec.c
merge patch that allow configuration change of linphonerc in linphonec shell
[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, char * sipAddr);
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 *sipAddr = 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, sipAddr);
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         char *input, *iptr;
798         char auth_prompt[256];
799 #ifdef HAVE_READLINE
800         rl_hook_func_t *old_event_hook;
801 #endif
802         LinphoneAuthInfo *pending_auth=auth_stack.elem[auth_stack.nitems-1];
803
804         snprintf(auth_prompt, 256, "Password for %s on %s: ",
805                 pending_auth->username, pending_auth->realm);
806
807         printf("\n");
808 #ifdef HAVE_READLINE
809         /*
810          * Disable event hook to avoid entering an
811          * infinite loop. This would prevent idle_call
812          * from being called during authentication reads.
813          * Note that it might be undesiderable...
814          */
815         old_event_hook=rl_event_hook;
816         rl_event_hook=NULL;
817 #endif
818
819         while (1)
820         {
821                 input=linphonec_readline(auth_prompt);
822
823                 /*
824                  * If EOF (^D) is sent you probably don't want
825                  * to provide an auth password... should give up
826                  * the operation, but there's no mechanism to
827                  * send this info back to caller currently...
828                  */
829                 if ( ! input )
830                 {
831                         printf("Cancel requested, but not implemented.\n");
832                         continue;
833                 }
834
835                 /* Strip blanks */
836                 iptr=lpc_strip_blanks(input);
837
838                 /*
839                  * Only blanks, continue asking
840                  */
841                 if ( ! *iptr )
842                 {
843                         free(input);
844                         continue;
845                 }
846
847                 /* Something typed, let's try */
848                 break;
849         }
850
851         /*
852          * No check is done here to ensure password is correct.
853          * I guess password will be asked again later.
854          */
855         linphone_auth_info_set_passwd(pending_auth, input);
856         linphone_core_add_auth_info(lc, pending_auth);
857         linphone_auth_info_destroy(pending_auth);
858         auth_stack.elem[auth_stack.nitems-1]=0;
859         --(auth_stack.nitems);
860 #ifdef HAVE_READLINE
861         /*
862          * Reset line_buffer, to avoid the password
863          * to be used again from outer readline
864          */
865         rl_line_buffer[0]='\0';
866         rl_event_hook=old_event_hook;
867 #endif
868         return 1;
869 }
870
871 void
872 print_usage (int exit_status)
873 {
874         fprintf (stdout, "\n\
875 usage: linphonec [-c file] [-s sipaddr] [-a] [-V] [-d level ] [-l logfile]\n\
876        linphonec -v\n\
877 \n\
878   -b  file             specify path of readonly factory configuration file.\n\
879   -c  file             specify path of configuration file.\n\
880   -d  level            be verbose. 0 is no output. 6 is all output\n\
881   -l  logfile          specify the log file for your SIP phone\n\
882   -s  sipaddress       specify the sip call to do at startup\n\
883   -a                   enable auto answering for incoming calls\n\
884   -V                   enable video features globally (disabled by default)\n\
885   -C                   enable video capture only (disabled by default)\n\
886   -D                   enable video display only (disabled by default)\n\
887   -S                   show general state messages (disabled by default)\n\
888   --wid  windowid      force embedding of video window into provided windowid (disabled by default)\n\
889   -v or --version      display version and exits.\n");
890
891         exit(exit_status);
892 }
893
894 #ifdef VIDEO_ENABLED
895
896 #ifdef HAVE_X11_XLIB_H
897 static void x11_apply_video_params(VideoParams *params, Window window){
898         XWindowChanges wc;
899         unsigned int flags=0;
900         static Display *display = NULL;
901         const char *dname=getenv("DISPLAY");
902
903         if (display==NULL && dname!=NULL){
904                 display=XOpenDisplay(dname);
905         }
906
907         if (display==NULL){
908                 ms_error("Could not open display %s",dname);
909                 return;
910         }
911         memset(&wc,0,sizeof(wc));
912         wc.x=params->x;
913         wc.y=params->y;
914         wc.width=params->w;
915         wc.height=params->h;
916         if (params->x!=-1 ){
917                 flags|=CWX|CWY;
918         }
919         if (params->w!=-1){
920                 flags|=CWWidth|CWHeight;
921         }
922         /*printf("XConfigureWindow x=%i,y=%i,w=%i,h=%i\n",
923                wc.x, wc.y ,wc.width, wc.height);*/
924         XConfigureWindow(display,window,flags,&wc);
925         if (params->show)
926                 XMapWindow(display,window);
927         else
928                 XUnmapWindow(display,window);
929         XSync(display,FALSE);
930 }
931 #endif
932
933
934 static void lpc_apply_video_params(){
935         static unsigned long old_wid=0,old_pwid=0;
936         unsigned long wid=linphone_core_get_native_video_window_id (linphonec);
937         unsigned long pwid=linphone_core_get_native_preview_window_id (linphonec);
938
939         if (wid!=0 && (lpc_video_params.refresh || old_wid!=wid)){
940                 lpc_video_params.refresh=FALSE;
941 #ifdef HAVE_X11_XLIB_H
942                 if (lpc_video_params.wid==0){  // do not manage window if embedded
943                         x11_apply_video_params(&lpc_video_params,wid);
944                 }
945 #endif
946         }
947         old_wid=wid;
948         if (pwid!=0 && (lpc_preview_params.refresh || old_pwid!=pwid)){
949                 lpc_preview_params.refresh=FALSE;
950 #ifdef HAVE_X11_XLIB_H
951                 /*printf("wid=%lu pwid=%lu\n",wid,pwid);*/
952                 if (lpc_preview_params.wid==0){  // do not manage window if embedded
953                         printf("Refreshing\n");
954                         x11_apply_video_params(&lpc_preview_params,pwid);
955                 }
956 #endif
957         }
958         old_pwid=pwid;
959 }
960
961 #endif
962
963
964 /*
965  *
966  * Called every second from main read loop.
967  *
968  * Will use the following globals:
969  *
970  *  - LinphoneCore linphonec
971  *  - LPC_AUTH_STACK auth_stack;
972  *
973  */
974 static int
975 linphonec_idle_call ()
976 {
977         LinphoneCore *opm=linphonec;
978
979         /* Uncomment the following to verify being called */
980         /* printf(".\n"); */
981
982         linphone_core_iterate(opm);
983         if (answer_call){
984                 fprintf (stdout, "-------auto answering to call-------\n" );
985                 linphone_core_accept_call(opm,NULL);
986                 answer_call=FALSE;
987         }
988
989         if ( auth_stack.nitems )
990         {
991                 /*
992                  * Inhibit command completion
993                  * during password prompts
994                  */
995 #ifdef HAVE_READLINE
996                 rl_inhibit_completion=1;
997 #endif
998                 linphonec_prompt_for_auth_final(opm);
999 #ifdef HAVE_READLINE
1000                 rl_inhibit_completion=0;
1001 #endif
1002         }
1003
1004 #ifdef VIDEO_ENABLED
1005         lpc_apply_video_params();
1006 #endif
1007
1008         return 0;
1009 }
1010
1011 #ifdef HAVE_READLINE
1012 /*
1013  * Use globals:
1014  *
1015  *      - char *histfile_name (also sets this)
1016  *      - char *last_in_history (allocates it)
1017  */
1018 static int
1019 linphonec_initialize_readline()
1020 {
1021         /*rl_bind_key('\t', rl_insert);*/
1022
1023         /* Allow conditional parsing of ~/.inputrc */
1024         rl_readline_name = "linphonec";
1025
1026         /* Call idle_call() every second */
1027         rl_set_keyboard_input_timeout(LPC_READLINE_TIMEOUT);
1028         rl_event_hook=linphonec_idle_call;
1029
1030         /* Set history file and read it */
1031         histfile_name = ms_strdup_printf ("%s/.linphonec_history",
1032                 getenv("HOME"));
1033         read_history(histfile_name);
1034
1035         /* Initialized last_in_history cache*/
1036         last_in_history[0] = '\0';
1037
1038         /* Register a completion function */
1039         rl_attempted_completion_function = linephonec_readline_completion;
1040
1041         /* printf("Readline initialized.\n"); */
1042         setlinebuf(stdout);
1043         return 0;
1044 }
1045
1046 /*
1047  * Uses globals:
1048  *
1049  *      - char *histfile_name (writes history to file and frees it)
1050  *      - char *last_in_history (frees it)
1051  *
1052  */
1053 static int
1054 linphonec_finish_readline()
1055 {
1056
1057         stifle_history(HISTSIZE);
1058         write_history(histfile_name);
1059         free(histfile_name);
1060         histfile_name=NULL;
1061         return 0;
1062 }
1063
1064 #endif
1065
1066 static void print_prompt(LinphoneCore *opm){
1067 #ifdef IDENTITY_AS_PROMPT
1068         snprintf(prompt, PROMPT_MAX_LEN, "%s> ",
1069                 linphone_core_get_primary_contact(opm));
1070 #else
1071         snprintf(prompt, PROMPT_MAX_LEN, "linphonec> ");
1072 #endif
1073 }
1074
1075 static int
1076 linphonec_main_loop (LinphoneCore * opm, char * sipAddr)
1077 {
1078         char buf[LINE_MAX_LEN]; /* auto call handling */
1079         char *input;
1080
1081         print_prompt(opm);
1082
1083
1084         /* auto call handling */
1085         if (sipAddr != NULL )
1086         {
1087                 snprintf (buf, sizeof(buf),"call %s", sipAddr);
1088                 linphonec_parse_command_line(linphonec, buf);
1089         }
1090
1091         while (linphonec_running && (input=linphonec_readline(prompt)))
1092         {
1093                 char *iptr; /* input and input pointer */
1094                 size_t input_len;
1095
1096                 /* Strip blanks */
1097                 iptr=lpc_strip_blanks(input);
1098
1099                 input_len = strlen(iptr);
1100
1101                 /*
1102                  * Do nothing but release memory
1103                  * if only blanks are read
1104                  */
1105                 if ( ! input_len )
1106                 {
1107                         free(input);
1108                         continue;
1109                 }
1110
1111 #ifdef HAVE_READLINE
1112                 /*
1113                  * Only add to history if not already
1114                  * last item in it, and only if the command
1115                  * doesn't start with a space (to allow for
1116                  * hiding passwords)
1117                  */
1118                 if ( iptr == input && strcmp(last_in_history, iptr) )
1119                 {
1120                         strncpy(last_in_history,iptr,sizeof(last_in_history));
1121                         last_in_history[sizeof(last_in_history)-1]='\0';
1122                         add_history(iptr);
1123                 }
1124 #endif
1125
1126                 linphonec_parse_command_line(linphonec, iptr);
1127                 linphonec_command_finished();
1128                 free(input);
1129         }
1130
1131         return 0;
1132 }
1133
1134 /*
1135  *  Parse command line switches
1136  *
1137  *  Use globals:
1138  *
1139  *      - int trace_level
1140  *      - char *logfile_name
1141  *      - char *configfile_name
1142  *      - char *sipAddr
1143  */
1144 static int
1145 linphonec_parse_cmdline(int argc, char **argv)
1146 {
1147         int arg_num=1;
1148
1149         while (arg_num < argc)
1150         {
1151                 int old_arg_num = arg_num;
1152                 if (strncmp ("-d", argv[arg_num], 2) == 0)
1153                 {
1154                         arg_num++;
1155                         if (arg_num < argc)
1156                                 trace_level = atoi (argv[arg_num]);
1157                         else
1158                                 trace_level = 1;
1159                 }
1160                 else if (strncmp ("-l", argv[arg_num], 2) == 0)
1161                 {
1162                         arg_num++;
1163                         if (arg_num < argc)
1164                                 logfile_name = argv[arg_num];
1165                 }
1166                 else if (strncmp ("-c", argv[arg_num], 2) == 0)
1167                 {
1168                         if ( ++arg_num >= argc ) print_usage(EXIT_FAILURE);
1169 #if !defined(_WIN32_WCE)
1170                         if (access(argv[arg_num],F_OK)!=0 )
1171                         {
1172                                 fprintf (stderr,
1173                                         "Cannot open config file %s.\n",
1174                                          argv[arg_num]);
1175                                 exit(EXIT_FAILURE);
1176                         }
1177 #endif /*_WIN32_WCE*/
1178                         snprintf(configfile_name, PATH_MAX, "%s", argv[arg_num]);
1179                 }
1180                 else if (strncmp ("-b", argv[arg_num], 2) == 0)
1181                 {
1182                         if ( ++arg_num >= argc ) print_usage(EXIT_FAILURE);
1183 #if !defined(_WIN32_WCE)
1184                         if (access(argv[arg_num],F_OK)!=0 )
1185                         {
1186                                 fprintf (stderr,
1187                                         "Cannot open config file %s.\n",
1188                                          argv[arg_num]);
1189                                 exit(EXIT_FAILURE);
1190                         }
1191 #endif /*_WIN32_WCE*/
1192                         factory_configfile_name = argv[arg_num];
1193                 }
1194                 else if (strncmp ("-s", argv[arg_num], 2) == 0)
1195                 {
1196                         arg_num++;
1197                         if (arg_num < argc)
1198                                 sipAddr = argv[arg_num];
1199                 }
1200                 else if (strncmp ("-a", argv[arg_num], 2) == 0)
1201                 {
1202                         auto_answer = TRUE;
1203                 }
1204                 else if (strncmp ("-C", argv[arg_num], 2) == 0)
1205                 {
1206                         vcap_enabled = TRUE;
1207                 }
1208                 else if (strncmp ("-D", argv[arg_num], 2) == 0)
1209                 {
1210                         display_enabled = TRUE;
1211                 }
1212                 else if (strncmp ("-V", argv[arg_num], 2) == 0)
1213                 {
1214                         display_enabled = TRUE;
1215                         vcap_enabled = TRUE;
1216                         preview_enabled=TRUE;
1217                 }
1218                 else if ((strncmp ("-v", argv[arg_num], 2) == 0)
1219                          ||
1220                          (strncmp
1221                           ("--version", argv[arg_num],
1222                            strlen ("--version")) == 0))
1223                 {
1224 #if !defined(_WIN32_WCE)
1225                         printf ("version: " LINPHONE_VERSION "\n");
1226 #endif
1227                         exit (EXIT_SUCCESS);
1228                 }
1229                 else if (strncmp ("-S", argv[arg_num], 2) == 0)
1230                 {
1231                         show_general_state = TRUE;
1232                 }
1233                 else if (strncmp ("--pipe", argv[arg_num], 6) == 0)
1234                 {
1235                         unix_socket=1;
1236                 }
1237                 else if (strncmp ("--wid", argv[arg_num], 5) == 0)
1238                 {
1239                         arg_num++;
1240                         if (arg_num < argc) {
1241                                 char *tmp;
1242                                 window_id = strtol( argv[arg_num], &tmp, 0 );
1243                         }
1244                 }
1245                 else if (old_arg_num == arg_num)
1246                 {
1247                         fprintf (stderr, "ERROR: bad arguments\n");
1248                         print_usage (EXIT_FAILURE);
1249                 }
1250                 arg_num++;
1251         }
1252
1253         return 1;
1254 }
1255
1256 /*
1257  * Up to version 1.2.1 linphone used ~/.linphonec for
1258  * CLI and ~/.gnome2/linphone for GUI as configuration file.
1259  * In newer version both interfaces will use ~/.linphonerc.
1260  *
1261  * This function helps transparently migrating from one
1262  * to the other layout using the following heuristic:
1263  *
1264  *      IF new_config EXISTS => do nothing
1265  *      ELSE IF old_cli_config EXISTS => copy to new_config
1266  *      ELSE IF old_gui_config EXISTS => copy to new_config
1267  *
1268  * Returns:
1269  *       0 if it did nothing
1270  *       1 if it migrated successfully
1271  *      -1 on error
1272  */
1273 static int
1274 handle_configfile_migration()
1275 {
1276 #if !defined(_WIN32_WCE)
1277         char *old_cfg_gui;
1278         char *old_cfg_cli;
1279         char *new_cfg;
1280 #if !defined(_WIN32_WCE)
1281         const char *home = getenv("HOME");
1282 #else
1283         const char *home = ".";
1284 #endif /*_WIN32_WCE*/
1285         new_cfg = ms_strdup_printf("%s/.linphonerc", home);
1286
1287         /*
1288          * If the *NEW* configuration already exists
1289          * do nothing.
1290          */
1291         if (access(new_cfg,F_OK)==0)
1292         {
1293                 free(new_cfg);
1294                 return 0;
1295         }
1296
1297         old_cfg_cli = ms_strdup_printf("%s/.linphonec", home);
1298
1299         /*
1300          * If the *OLD* CLI configurations exist copy it to
1301          * the new file and make it a symlink.
1302          */
1303         if (access(old_cfg_cli, F_OK)==0)
1304         {
1305                 if ( ! copy_file(old_cfg_cli, new_cfg) )
1306                 {
1307                         free(old_cfg_cli);
1308                         free(new_cfg);
1309                         return -1;
1310                 }
1311                 printf("%s copied to %s\n", old_cfg_cli, new_cfg);
1312                 free(old_cfg_cli);
1313                 free(new_cfg);
1314                 return 1;
1315         }
1316
1317         free(old_cfg_cli);
1318         old_cfg_gui = ms_strdup_printf("%s/.gnome2/linphone", home);
1319
1320         /*
1321          * If the *OLD* GUI configurations exist copy it to
1322          * the new file and make it a symlink.
1323          */
1324         if (access(old_cfg_gui, F_OK)==0)
1325         {
1326                 if ( ! copy_file(old_cfg_gui, new_cfg) )
1327                 {
1328                         exit(EXIT_FAILURE);
1329                         free(old_cfg_gui);
1330                         free(new_cfg);
1331                         return -1;
1332                 }
1333                 printf("%s copied to %s\n", old_cfg_gui, new_cfg);
1334                 free(old_cfg_gui);
1335                 free(new_cfg);
1336                 return 1;
1337         }
1338
1339         free(old_cfg_gui);
1340         free(new_cfg);
1341 #endif /*_WIN32_WCE*/
1342         return 0;
1343 }
1344 #if !defined(_WIN32_WCE)
1345 /*
1346  * Copy file "from" to file "to".
1347  * Destination file is truncated if existing.
1348  * Return 1 on success, 0 on error (printing an error).
1349  */
1350 static int
1351 copy_file(const char *from, const char *to)
1352 {
1353         char message[256];
1354         FILE *in, *out;
1355         char buf[256];
1356         size_t n;
1357
1358         /* Open "from" file for reading */
1359         in=fopen(from, "r");
1360         if ( in == NULL )
1361         {
1362                 snprintf(message, 255, "Can't open %s for reading: %s\n",
1363                         from, strerror(errno));
1364                 fprintf(stderr, "%s", message);
1365                 return 0;
1366         }
1367
1368         /* Open "to" file for writing (will truncate existing files) */
1369         out=fopen(to, "w");
1370         if ( out == NULL )
1371         {
1372                 snprintf(message, 255, "Can't open %s for writing: %s\n",
1373                         to, strerror(errno));
1374                 fprintf(stderr, "%s", message);
1375                 return 0;
1376         }
1377
1378         /* Copy data from "in" to "out" */
1379         while ( (n=fread(buf, 1, sizeof buf, in)) > 0 )
1380         {
1381                 if ( ! fwrite(buf, 1, n, out) )
1382                 {
1383                         return 0;
1384                 }
1385         }
1386
1387         fclose(in);
1388         fclose(out);
1389
1390         return 1;
1391 }
1392 #endif /*_WIN32_WCE*/
1393
1394 #ifdef HAVE_READLINE
1395 static char **
1396 linephonec_readline_completion(const char *text, int start, int end)
1397 {
1398         char **matches = NULL;
1399
1400         /*
1401          * Prevent readline from falling
1402          * back to filename-completion
1403          */
1404         rl_attempted_completion_over=1;
1405
1406         /*
1407          * If this is the start of line we complete with commands
1408          */
1409         if ( ! start )
1410         {
1411                 return rl_completion_matches(text, linphonec_command_generator);
1412         }
1413
1414         /*
1415          * Otherwise, we should peek at command name
1416          * or context to implement a smart completion.
1417          * For example: "call .." could return
1418          * friends' sip-uri as matches
1419          */
1420
1421         return matches;
1422 }
1423
1424 #endif
1425
1426 /*
1427  * Strip blanks from a string.
1428  * Return a pointer into the provided string.
1429  * Modifies input adding a NULL at first
1430  * of trailing blanks.
1431  */
1432 char *
1433 lpc_strip_blanks(char *input)
1434 {
1435         char *iptr;
1436
1437         /* Find first non-blank */
1438         while(*input && isspace(*input)) ++input;
1439
1440         /* Find last non-blank */
1441         iptr=input+strlen(input);
1442         if (iptr > input) {
1443                 while(isspace(*--iptr));
1444                 *(iptr+1)='\0';
1445         }
1446
1447         return input;
1448 }
1449
1450 /****************************************************************************
1451  *
1452  * $Log: linphonec.c,v $
1453  * Revision 1.57  2007/11/14 13:40:27  smorlat
1454  * fix --disable-video build.
1455  *
1456  * Revision 1.56  2007/09/26 14:07:27  fixkowalski
1457  * - ANSI/C++ compilation issues with non-GCC compilers
1458  * - Faster epm-based packaging
1459  * - Ability to build & run on FC6's eXosip/osip
1460  *
1461  * Revision 1.55  2007/09/24 16:01:58  smorlat
1462  * fix bugs.
1463  *
1464  * Revision 1.54  2007/08/22 14:06:11  smorlat
1465  * authentication bugs fixed.
1466  *
1467  * Revision 1.53  2007/02/13 21:31:01  smorlat
1468  * added patch for general state.
1469  * new doxygen for oRTP
1470  * gtk-doc removed.
1471  *
1472  * Revision 1.52  2007/01/10 14:11:24  smorlat
1473  * add --video to linphonec.
1474  *
1475  * Revision 1.51  2006/08/21 12:49:59  smorlat
1476  * merged several little patches.
1477  *
1478  * Revision 1.50  2006/07/26 08:17:28  smorlat
1479  * fix bugs.
1480  *
1481  * Revision 1.49  2006/07/17 18:45:00  smorlat
1482  * support for several event queues in ortp.
1483  * glib dependency removed from coreapi/ and console/
1484  *
1485  * Revision 1.48  2006/04/09 12:45:32  smorlat
1486  * linphonec improvements.
1487  *
1488  * Revision 1.47  2006/04/04 08:04:34  smorlat
1489  * switched to mediastreamer2, most bugs fixed.
1490  *
1491  * Revision 1.46  2006/03/16 17:17:40  smorlat
1492  * fix various bugs.
1493  *
1494  * Revision 1.45  2006/03/12 21:48:31  smorlat
1495  * gcc-2.95 compile error fixed.
1496  * mediastreamer2 in progress
1497  *
1498  * Revision 1.44  2006/03/04 11:17:10  smorlat
1499  * mediastreamer2 in progress.
1500  *
1501  * Revision 1.43  2006/02/13 09:50:50  strk
1502  * fixed unused variable warning.
1503  *
1504  * Revision 1.42  2006/02/02 15:39:18  strk
1505  * - Added 'friend list' and 'friend call' commands
1506  * - Allowed for multiple DTFM send in a single line
1507  * - Added status-specific callback (bare version)
1508  *
1509  * Revision 1.41  2006/02/02 13:30:05  strk
1510  * - Padded vtable with missing callbacks
1511  *   (fixing a segfault on friends subscription)
1512  * - Handled friends notify (bare version)
1513  * - Handled text messages receive (bare version)
1514  * - Printed message on subscription request (bare version)
1515  *
1516  * Revision 1.40  2006/01/26 09:48:05  strk
1517  * Added limits.h include
1518  *
1519  * Revision 1.39  2006/01/26 02:11:01  strk
1520  * Removed unused variables, fixed copyright date
1521  *
1522  * Revision 1.38  2006/01/25 18:33:02  strk
1523  * Removed the -t swich, terminate_on_close made the default behaviour
1524  *
1525  * Revision 1.37  2006/01/20 14:12:34  strk
1526  * Added linphonec_init() and linphonec_finish() functions.
1527  * Handled SIGINT and SIGTERM to invoke linphonec_finish().
1528  * Handling of auto-termination (-t) moved to linphonec_finish().
1529  * Reworked main (input read) loop to not rely on 'terminate'
1530  * and 'run' variable (dropped). configfile_name allocated on stack
1531  * using PATH_MAX limit. Changed print_usage signature to allow
1532  * for an exit_status specification.
1533  *
1534  * Revision 1.36  2006/01/18 09:25:32  strk
1535  * Command completion inhibited in proxy addition and auth request prompts.
1536  * Avoided use of readline's internal filename completion.
1537  *
1538  * Revision 1.35  2006/01/14 13:29:32  strk
1539  * Reworked commands interface to use a table structure,
1540  * used by command line parser and help function.
1541  * Implemented first level of completion (commands).
1542  * Added notification of invalid "answer" and "terminate"
1543  * commands (no incoming call, no active call).
1544  * Forbidden "call" intialization when a call is already active.
1545  * Cleaned up all commands, adding more feedback and error checks.
1546  *
1547  * Revision 1.34  2006/01/13 13:00:29  strk
1548  * Added linphonec.h. Code layout change (added comments, forward decl,
1549  * globals on top, copyright notices and Logs). Handled out-of-memory
1550  * condition on history management. Removed assumption on sizeof(char).
1551  * Fixed bug in authentication prompt (introduced by readline).
1552  * Added support for multiple authentication requests (up to MAX_PENDING_AUTH).
1553  *
1554  *
1555  ****************************************************************************/
1556