~ubuntu-branches/ubuntu/hardy/linphone/hardy

« back to all changes in this revision

Viewing changes to console/linphonec.c

  • Committer: Bazaar Package Importer
  • Author(s): Samuel Mimram
  • Date: 2006-10-11 11:33:53 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20061011113353-mnnkce31bu61g80s
Tags: 1.5.0-1
* New upstream release.
* Removed ice.dpatch and stun_sparc.dpatch, integrated upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/****************************************************************************
2
2
 *
3
 
 *  $Id: linphonec.c,v 1.46 2006/03/16 17:17:40 smorlat Exp $
 
3
 *  $Id: linphonec.c,v 1.51 2006/08/21 12:49:59 smorlat Exp $
4
4
 *
5
5
 *  Copyright (C) 2006  Sandro Santilli <strk@keybit.net>
6
6
 *  Copyright (C) 2002  Florian Winterstein <flox@gmx.net>
33
33
#include <limits.h>
34
34
#include <linphonecore.h>
35
35
#include "linphonec.h"
36
 
#include "../config.h"
 
36
 
 
37
#ifdef HAVE_CONFIG_H
 
38
#include "config.h"
 
39
#endif
 
40
 
 
41
#ifdef HAVE_GETTEXT
 
42
#include <libintl.h>
 
43
#ifndef _
 
44
#define _(String) gettext(String)
 
45
#endif
 
46
#else
 
47
#define _(something)    (something)
 
48
#endif
37
49
 
38
50
/***************************************************************************
39
51
 *
69
81
static void linphonec_call_received(LinphoneCore *lc, const char *from);
70
82
static void linphonec_prompt_for_auth(LinphoneCore *lc, const char *realm,
71
83
        const char *username);
72
 
static void linphonec_display_something (LinphoneCore * lc, char *something);
73
 
static void linphonec_display_url (LinphoneCore * lc, char *something, char *url);
74
 
static void linphonec_display_warning (LinphoneCore * lc, char *something);
 
84
static void linphonec_display_something (LinphoneCore * lc, const char *something);
 
85
static void linphonec_display_url (LinphoneCore * lc, const char *something, const char *url);
 
86
static void linphonec_display_warning (LinphoneCore * lc, const char *something);
75
87
static void stub () {}
76
88
static void linphonec_notify_received(LinphoneCore *lc,LinphoneFriend *fid,
77
89
                const char *from, const char *status, const char *img);
80
92
static void linphonec_bye_received(LinphoneCore *lc, const char *from);
81
93
static void linphonec_text_received(LinphoneCore *lc, LinphoneChatRoom *cr,
82
94
                const char *from, const char *msg);
83
 
static void linphonec_display_status (LinphoneCore * lc, char *something);
 
95
static void linphonec_display_status (LinphoneCore * lc, const char *something);
84
96
 
85
97
/***************************************************************************
86
98
 *
91
103
LinphoneCore linphonec;
92
104
FILE *mylogfile;
93
105
static char *histfile_name=NULL;
94
 
static char *last_in_history=NULL;
 
106
static char last_in_history[256];
95
107
//auto answer (-a) option
96
 
static gboolean auto_answer=FALSE;
 
108
static bool_t auto_answer=FALSE;
 
109
static bool_t answer_call=FALSE;
97
110
LPC_AUTH_STACK auth_stack;
98
111
static int trace_level = 0;
99
112
static char *logfile_name = NULL;
130
143
 * Linphone core callback 
131
144
 */
132
145
static void
133
 
linphonec_display_something (LinphoneCore * lc, char *something)
134
 
{
135
 
        fprintf (stdout, "%s\n", something);
136
 
}
137
 
 
138
 
/*
139
 
 * Linphone core callback 
140
 
 */
141
 
static void
142
 
linphonec_display_status (LinphoneCore * lc, char *something)
143
 
{
144
 
        fprintf (stdout, "%s\n", something);
145
 
}
146
 
 
147
 
/*
148
 
 * Linphone core callback 
149
 
 */
150
 
static void
151
 
linphonec_display_warning (LinphoneCore * lc, char *something)
 
146
linphonec_display_something (LinphoneCore * lc, const char *something)
 
147
{
 
148
        fprintf (stdout, "%s\n", something);
 
149
}
 
150
 
 
151
/*
 
152
 * Linphone core callback 
 
153
 */
 
154
static void
 
155
linphonec_display_status (LinphoneCore * lc, const char *something)
 
156
{
 
157
        fprintf (stdout, "%s\n", something);
 
158
}
 
159
 
 
160
/*
 
161
 * Linphone core callback 
 
162
 */
 
163
static void
 
164
linphonec_display_warning (LinphoneCore * lc, const char *something)
152
165
{
153
166
        fprintf (stdout, "Warning: %s\n", something);
154
167
}
157
170
 * Linphone core callback 
158
171
 */
159
172
static void
160
 
linphonec_display_url (LinphoneCore * lc, char *something, char *url)
 
173
linphonec_display_url (LinphoneCore * lc, const char *something, const char *url)
161
174
{
162
175
        fprintf (stdout, "%s : %s\n", something, url);
163
176
}
170
183
linphonec_call_received(LinphoneCore *lc, const char *from)
171
184
{
172
185
        if ( auto_answer)  {
173
 
                fprintf (stdout, "-------auto answering to call-------\n" );
174
 
                linphone_core_accept_call(lc,NULL);
 
186
                answer_call=TRUE;
175
187
        }
176
188
}
177
189
 
505
517
        /* printf(".\n"); */
506
518
 
507
519
        linphone_core_iterate(opm);
508
 
 
 
520
        if (answer_call){
 
521
                fprintf (stdout, "-------auto answering to call-------\n" );
 
522
                linphone_core_accept_call(opm,NULL);
 
523
                answer_call=FALSE;
 
524
        }
509
525
 
510
526
#if 0 /* Automatic exit should be requested with a command line switch */
511
527
        /* Quit if autocall mode was on and no call is in progress */
548
564
        rl_event_hook=linphonec_idle_call;
549
565
 
550
566
        /* Set history file and read it */
551
 
        histfile_name = g_strdup_printf ("%s/.linphonec_history",
 
567
        histfile_name = ms_strdup_printf ("%s/.linphonec_history",
552
568
                getenv("HOME"));
553
569
        read_history(histfile_name);
554
570
 
555
 
        /* Initialized last_in_history cache */
556
 
        last_in_history = malloc(256);
 
571
        /* Initialized last_in_history cache*/
557
572
        last_in_history[0] = '\0';
558
573
 
559
574
        /* Register a completion function */
574
589
static int
575
590
linphonec_finish_readline()
576
591
{
577
 
        free(last_in_history);
578
592
 
579
593
        stifle_history(HISTSIZE);
580
594
        write_history(histfile_name);
587
601
linphonec_main_loop (LinphoneCore * opm, char * sipAddr)
588
602
{
589
603
        char buf[LINE_MAX_LEN]; /* auto call handling */
590
 
        gboolean run=TRUE;
 
604
        bool_t run=TRUE;
591
605
        char *input;
592
606
 
593
607
 
608
622
        while ((input=readline(prompt)))
609
623
        {
610
624
                char *iptr; /* input and input pointer */
611
 
                char *tmp;
612
625
                size_t input_len;
613
626
 
614
627
                /* Strip blanks */
633
646
                 */
634
647
                if ( strcmp(last_in_history, iptr) )
635
648
                {
636
 
                        if ( strlen(last_in_history) < input_len )
637
 
                        {
638
 
                                tmp=realloc(last_in_history,
639
 
                                        sizeof(char)*(input_len+1));
640
 
                                if ( tmp ) last_in_history=tmp;
641
 
                                else /* OOM */
642
 
                                {
643
 
                                        free(last_in_history);
644
 
                                        last_in_history=NULL;
645
 
                                }
646
 
                        }
647
 
                        if ( last_in_history ) /* NULL on OOM */
648
 
                        {
649
 
                                strcpy(last_in_history, iptr);
650
 
                                add_history(iptr);
651
 
                        }
 
649
                        strncpy(last_in_history,iptr,sizeof(last_in_history));
 
650
                        last_in_history[sizeof(last_in_history)-1]='\0';
 
651
                        add_history(iptr);
652
652
                }
653
653
 
654
654
                linphonec_parse_command_line(&linphonec, iptr);
694
694
                {
695
695
                        if ( ++arg_num >= argc ) print_usage(EXIT_FAILURE);
696
696
 
697
 
                        if (!g_file_test (argv[arg_num],
698
 
                                G_FILE_TEST_EXISTS) ||
699
 
                            g_file_test (argv[arg_num],
700
 
                                G_FILE_TEST_IS_DIR))
 
697
                        if (access(argv[arg_num],F_OK)!=0 )
701
698
                        {
702
699
                                fprintf (stderr,
703
700
                                        "Cannot open config file %s.\n",
761
758
        char *new_cfg;
762
759
        const char *home = getenv("HOME");
763
760
 
764
 
        new_cfg = g_strdup_printf("%s/.linphonerc", home);
 
761
        new_cfg = ms_strdup_printf("%s/.linphonerc", home);
765
762
 
766
763
        /*
767
764
         * If the *NEW* configuration already exists
768
765
         * do nothing.
769
766
         */
770
 
        if (g_file_test (new_cfg, G_FILE_TEST_EXISTS))
 
767
        if (access(new_cfg,F_OK)==0)
771
768
        {
772
769
                free(new_cfg);
773
770
                return 0;
774
771
        }
775
772
 
776
 
        old_cfg_cli = g_strdup_printf("%s/.linphonec", home);
 
773
        old_cfg_cli = ms_strdup_printf("%s/.linphonec", home);
777
774
 
778
775
        /*
779
776
         * If the *OLD* CLI configurations exist copy it to
780
777
         * the new file and make it a symlink.
781
778
         */
782
 
        if (g_file_test (old_cfg_cli, G_FILE_TEST_EXISTS))
 
779
        if (access(old_cfg_cli, F_OK)==0)
783
780
        {
784
781
                if ( ! copy_file(old_cfg_cli, new_cfg) )
785
782
                {
794
791
        }
795
792
 
796
793
        free(old_cfg_cli);
797
 
        old_cfg_gui = g_strdup_printf("%s/.gnome2/linphone", home);
 
794
        old_cfg_gui = ms_strdup_printf("%s/.gnome2/linphone", home);
798
795
 
799
796
        /*
800
797
         * If the *OLD* GUI configurations exist copy it to
801
798
         * the new file and make it a symlink.
802
799
         */
803
 
        if (g_file_test (old_cfg_gui, G_FILE_TEST_EXISTS))
 
800
        if (access(old_cfg_gui, F_OK)==0)
804
801
        {
805
802
                if ( ! copy_file(old_cfg_gui, new_cfg) )
806
803
                {
924
921
/****************************************************************************
925
922
 *
926
923
 * $Log: linphonec.c,v $
 
924
 * Revision 1.51  2006/08/21 12:49:59  smorlat
 
925
 * merged several little patches.
 
926
 *
 
927
 * Revision 1.50  2006/07/26 08:17:28  smorlat
 
928
 * fix bugs.
 
929
 *
 
930
 * Revision 1.49  2006/07/17 18:45:00  smorlat
 
931
 * support for several event queues in ortp.
 
932
 * glib dependency removed from coreapi/ and console/
 
933
 *
 
934
 * Revision 1.48  2006/04/09 12:45:32  smorlat
 
935
 * linphonec improvements.
 
936
 *
 
937
 * Revision 1.47  2006/04/04 08:04:34  smorlat
 
938
 * switched to mediastreamer2, most bugs fixed.
 
939
 *
927
940
 * Revision 1.46  2006/03/16 17:17:40  smorlat
928
941
 * fix various bugs.
929
942
 *