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