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