]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
update
authorAnthony Minessale <anthony.minessale@gmail.com>
Sun, 21 Dec 2008 21:54:43 +0000 (21:54 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Sun, 21 Dec 2008 21:54:43 +0000 (21:54 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@10898 d0543943-73ff-0310-b7d9-9358b9ac24b2

libs/esl/Makefile
libs/esl/fs_cli.c
libs/esl/src/esl.c
libs/esl/src/esl_event.c
libs/esl/src/include/esl.h
libs/esl/testclient.c

index 01065f358c1951caf3475095979f45ac3cb1ba83..8568198f7e38c367f65853b43c2a281d9fa3b329 100644 (file)
@@ -1,15 +1,19 @@
 PWD=$(shell pwd)
 INCS=-I$(PWD)/src/include
 LIBEDIT_DIR=../../libs/libedit
-CFLAGS=$(INCS) -g -ggdb -I$(LIBEDIT_DIR)/src/
+DEBUG=-g -ggdb
+PICKY=-O2 -ffast-math -Wall -Werror -Wunused-variable -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes
+CFLAGS=$(INCS) -D_GNU_SOURCE $(DEBUG) -I$(LIBEDIT_DIR)/src/ $(PICKY)
 MYLIB=libesl.a
 LIBS=-lesl -lncurses -lpthread
 LDFLAGS=-L.
 OBJS=src/esl.o src/esl_event.o src/esl_threadmutex.o src/esl_config.o
+SRC=src/esl.c src/esl_event.c src/esl_threadmutex.c src/esl_config.c
+HEADERS=src/include/esl_config.h src/include/esl_event.h src/include/esl.h src/include/esl_threadmutex.h
 
 all: $(MYLIB) fs_cli testclient testserver
 
-$(MYLIB): $(OBJS) $(HEADERS)
+$(MYLIB): $(OBJS) $(HEADERS) $(SRC)
        ar rcs $(MYLIB) $(OBJS)
        ranlib $(MYLIB)
 
index b6206b50375319dfcc879665e5a021ff518946b6..f49dd1227017407501b7198b96b6fed6891cd9cf 100644 (file)
@@ -5,28 +5,21 @@
 #include <sys/select.h>
 
 #include <histedit.h>
+
 static char prompt_str[512] = "";
 static char hostname[512] = "";
 
-char *prompt(EditLine * e)
+static char *prompt(EditLine * e)
 {
-       if (*prompt_str == '\0') {
-        gethostname(hostname, sizeof(hostname));
-        snprintf(prompt_str, sizeof(prompt_str), "freeswitch@%s> ", hostname);
-    }
-
     return prompt_str;
-
 }
 
 static EditLine *el;
 static History *myhistory;
 static HistEvent ev;
-static char *hfile = NULL;
 static int running = 1;
 static int thread_running = 0;
 
-
 static void handle_SIGINT(int sig)
 {
        if (sig);
@@ -89,8 +82,6 @@ static void *msg_thread_run(esl_thread_t *me, void *obj)
                usleep(1000);
        }
 
- done:
-
        thread_running = 0;
        esl_log(ESL_LOG_DEBUG, "Thread Done\n");
 
@@ -131,17 +122,33 @@ static int process_command(esl_handle_t *handle, const char *cmd)
 }
 
 typedef struct {
+       char name[128];
        char host[128];
-       char pass[128];
        esl_port_t port;
+       char pass[128];
 } cli_profile_t;
 
-static cli_profile_t profiles[128] = { 0 };
+static cli_profile_t profiles[128] = {{{0}}};
 static int pcount;
 
+
+static int get_profile(const char *name, cli_profile_t **profile)
+{
+       int x;
+
+       for (x = 0; x < pcount; x++) {
+               if (!strcmp(profiles[x].name, name)) {
+                       *profile = &profiles[x];
+                       return 0;
+               }
+       }
+
+       return -1;
+}
+
 int main(int argc, char *argv[])
 {
-       esl_handle_t handle = {0};
+       esl_handle_t handle = {{0}};
        int count;
        const char *line;
        char cmd_str[1024] = "";
@@ -150,11 +157,13 @@ int main(int argc, char *argv[])
        char *home = getenv("HOME");
        esl_config_t cfg;
        cli_profile_t *profile = &profiles[0];
+       int cur = 0;
        
        strncpy(profiles[0].host, "localhost", sizeof(profiles[0].host));
        strncpy(profiles[0].pass, "ClueCon", sizeof(profiles[0].pass));
+       strncpy(profiles[0].name, "default", sizeof(profiles[0].name));
        profiles[0].port = 8021;
-       pcount = 1;
+       pcount++;
        
        if (home) {
                snprintf(hfile, sizeof(hfile), "%s/.fs_cli_history", home);
@@ -165,27 +174,58 @@ int main(int argc, char *argv[])
        gethostname(hostname, sizeof(hostname));
 
        handle.debug = 0;
-
+       esl_global_set_default_logger(7);
        
        if (esl_config_open_file(&cfg, cfile)) {
                char *var, *val;
+               char cur_cat[128] = "";
+
                while (esl_config_next_pair(&cfg, &var, &val)) {
+                       if (strcmp(cur_cat, cfg.category)) {
+                               cur++;
+                               esl_set_string(cur_cat, cfg.category);
+                               esl_set_string(profiles[cur].name, cur_cat);
+                               esl_set_string(profiles[cur].host, "localhost");
+                               esl_set_string(profiles[cur].pass, "ClueCon");
+                               profiles[cur].port = 8021;
+                               esl_log(ESL_LOG_INFO, "Found Profile [%s]\n", profiles[cur].name);
+                               pcount++;
+                       }
                        
+                       if (!strcasecmp(var, "host")) {
+                               esl_set_string(profiles[cur].host, val);
+                       } else if (!strcasecmp(var, "password")) {
+                               esl_set_string(profiles[cur].pass, val);
+                       } else if (!strcasecmp(var, "port")) {
+                               int pt = atoi(val);
+                               if (pt > 0) {
+                                       profiles[cur].port = pt;
+                               }
+                       }
                }
                esl_config_close_file(&cfg);
        }
 
-       
-       if (esl_connect(&handle, profile->host, profile->port, profile->pass)) {
-               printf("Error Connecting [%s]\n", handle.err);
-               return -1;
+       if (argv[1]) {
+               if (get_profile(argv[1], &profile)) {
+                       esl_log(ESL_LOG_INFO, "Chosen profile %s does not exist using builtin default\n", argv[1]);
+                       profile = &profiles[0];
+               } else {
+                       esl_log(ESL_LOG_INFO, "Chosen profile %s\n", profile->name);
+               }
        }
 
+       esl_log(ESL_LOG_INFO, "Using profile %s\n", profile->name);
+               
+       gethostname(hostname, sizeof(hostname));
+       snprintf(prompt_str, sizeof(prompt_str), "freeswitch@%s> ", profile->name);
 
-       if (handle.debug) {
-               esl_global_set_default_logger(7);
+       
+       if (esl_connect(&handle, profile->host, profile->port, profile->pass)) {
+               esl_log(ESL_LOG_ERROR, "Error Connecting [%s]\n", handle.err);
+               return -1;
        }
-               
+       
        esl_thread_create_detached(msg_thread_run, &handle);
        
        el = el_init(__FILE__, stdout, stdout, stdout);
@@ -194,7 +234,7 @@ int main(int argc, char *argv[])
        myhistory = history_init();
 
        if (myhistory == 0) {
-               fprintf(stderr, "history could not be initialized\n");
+               esl_log(ESL_LOG_ERROR, "history could not be initialized\n");
                goto done;
        }
 
@@ -202,10 +242,11 @@ int main(int argc, char *argv[])
        el_set(el, EL_HIST, history, myhistory);
        history(myhistory, &ev, H_LOAD, hfile);
        
-
        snprintf(cmd_str, sizeof(cmd_str), "log info\n\n");
        esl_send_recv(&handle, cmd_str);
 
+       esl_log(ESL_LOG_INFO, "FS CLI Ready.\n");
+
        while (running) {
 
                line = el_gets(el, &count);
index 8e7f73f38e56bc5435ff9a7919e804519bcfc0e1..840653dd501f5b07c0f747f307d627d1dacce1e0 100644 (file)
@@ -32,7 +32,6 @@
  */
 
 #include <esl.h>
-#include <sys/signal.h>
 
 #ifndef HAVE_GETHOSTBYNAME_R
 extern int gethostbyname_r (const char *__name,
@@ -367,6 +366,8 @@ esl_status_t esl_sendevent(esl_handle_t *handle, esl_event_t *event)
        send(handle->sock, "\n\n", 2, 0);
 
        free(txt);
+
+       return ESL_SUCCESS;
 }
 
 esl_status_t esl_execute(esl_handle_t *handle, const char *app, const char *arg, const char *uuid)
@@ -390,7 +391,7 @@ esl_status_t esl_execute(esl_handle_t *handle, const char *app, const char *arg,
 
        snprintf(send_buf, sizeof(send_buf), "%s\ncall-command: execute\n%s%s\n", cmd_buf, app_buf, arg_buf);
 
-       esl_send_recv(handle, send_buf);
+       return esl_send_recv(handle, send_buf);
 }
 
 esl_status_t esl_listen(const char *host, esl_port_t port, esl_listen_callback_t callback)
@@ -452,7 +453,6 @@ esl_status_t esl_connect(esl_handle_t *handle, const char *host, esl_port_t port
 
        struct hostent *result;
        char sendbuf[256];
-       char recvbuf[256];
        int rval;
        const char *hval;
 
@@ -560,7 +560,7 @@ esl_status_t esl_recv_event_timed(esl_handle_t *handle, uint32_t ms, esl_event_t
 {
        fd_set rfds, efds;
        struct timeval tv = { 0, ms * 1000 };
-       int max, activity, i = 0;
+       int max, activity;
        esl_status_t status = ESL_SUCCESS;
 
        esl_mutex_lock(handle->mutex);
@@ -820,21 +820,31 @@ esl_status_t esl_send(esl_handle_t *handle, const char *cmd)
                esl_log(ESL_LOG_DEBUG, "SEND\n%s\n", cmd);
        }
        
-       send(handle->sock, cmd, strlen(cmd), 0);
+       if (send(handle->sock, cmd, strlen(cmd), 0)) {
+               strerror_r(handle->errno, handle->err, sizeof(handle->err));
+               return ESL_FAIL;
+       }
 
        if (!(*e == '\n' && *(e-1) == '\n')) {
-               send(handle->sock, "\n\n", 2, 0);
+               if (send(handle->sock, "\n\n", 2, 0)) {
+                       strerror_r(handle->errno, handle->err, sizeof(handle->err));
+                       return ESL_FAIL;
+               }
        }
+       
+       return ESL_SUCCESS;
+
 }
 
 
 esl_status_t esl_send_recv(esl_handle_t *handle, const char *cmd)
 {
        const char *hval;
-
+       esl_status_t status;
+       
        esl_mutex_lock(handle->mutex);
        esl_send(handle, cmd);
-       esl_recv_event(handle, &handle->last_sr_event);
+       status = esl_recv_event(handle, &handle->last_sr_event);
        
        if (handle->last_sr_event) {
                hval = esl_event_get_header(handle->last_sr_event, "reply-text");
@@ -845,6 +855,8 @@ esl_status_t esl_send_recv(esl_handle_t *handle, const char *cmd)
        }
        
        esl_mutex_unlock(handle->mutex);
+
+       return status;
 }
 
 
index 90a2e1a0c314fa1d514fb1e23f1d6061dc6bee1d..f0f99850b4ca6d787fb755ad95d24968f6c4f65a 100644 (file)
@@ -31,6 +31,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+
 #include <esl.h>
 #include <esl_event.h>
 
@@ -56,7 +57,7 @@ static char *my_dup(const char *s)
 /* make sure this is synced with the esl_event_types_t enum in esl_types.h
    also never put any new ones before EVENT_ALL
 */
-static char *EVENT_NAMES[] = {
+static const char *EVENT_NAMES[] = {
        "CUSTOM",
        "CHANNEL_CREATE",
        "CHANNEL_DESTROY",
@@ -277,7 +278,7 @@ esl_status_t esl_event_del_header(esl_event_t *event, const char *header_name)
        return status;
 }
 
-esl_status_t esl_event_base_add_header(esl_event_t *event, esl_stack_t stack, const char *header_name, char *data)
+static esl_status_t esl_event_base_add_header(esl_event_t *event, esl_stack_t stack, const char *header_name, char *data)
 {
        esl_event_header_t *header;
        esl_ssize_t hlen = -1;
index d555def0dc3b67fe1c8919d5d3810a120f6655b8..2518a2d3c328758b9dc9001971c069dfadcf0502 100644 (file)
@@ -149,15 +149,19 @@ typedef struct esl_event esl_event_t;
 #include <sys/time.h>
 #endif
 
+#include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/signal.h>
+#include <unistd.h>
+#include <ctype.h>
+
 #ifdef HAVE_STRINGS_H
 #include <strings.h>
 #endif
 #include <assert.h>
 
-
 #define esl_assert(_x) assert(_x)
 #define esl_safe_free(_x) if (_x) free(_x); _x = NULL
 #define esl_strlen_zero(s) (!s || *(s) == '\0')
@@ -261,6 +265,7 @@ void esl_global_set_default_logger(int level);
 
 size_t esl_url_encode(const char *url, char *buf, size_t len);
 char *esl_url_decode(char *s);
+const char *esl_stristr(const char *instr, const char *str);
 int esl_toupper(int c);
 int esl_tolower(int c);
 
index 383755cb79336fb4192edc1629684110235e86d6..4c61c1e58f28df5f0dbe594d3844b2f8e283064a 100644 (file)
@@ -5,7 +5,7 @@
 
 int main(void)
 {
-       esl_handle_t handle = {0};
+       esl_handle_t handle = {{0}};
 
        handle.debug = 1;