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