]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add sendmsg function to esl
authorAnthony Minessale <anthm@freeswitch.org>
Tue, 6 Sep 2011 19:53:38 +0000 (14:53 -0500)
committerAnthony Minessale <anthm@freeswitch.org>
Tue, 6 Sep 2011 19:53:38 +0000 (14:53 -0500)
libs/esl/src/esl.c
libs/esl/src/esl_oop.cpp
libs/esl/src/include/esl.h
libs/esl/src/include/esl_oop.h

index ef8d7c1cb1fa6f9dc235c6750ad4fa6071394c56..cd3a7067f803ca8ef207c1e65cdbd677be6f6db5 100644 (file)
@@ -534,6 +534,39 @@ ESL_DECLARE(esl_status_t) esl_execute(esl_handle_t *handle, const char *app, con
 }
 
 
+ESL_DECLARE(esl_status_t) esl_sendmsg(esl_handle_t *handle, esl_event_t *event, const char *uuid)
+{
+       char cmd_buf[128] = "sendmsg";
+       char send_buf[1292] = "";
+       char *txt;
+       
+    if (!handle || !handle->connected || handle->sock == ESL_SOCK_INVALID) {
+        return ESL_FAIL;
+    }
+
+       if (uuid) {
+               snprintf(cmd_buf, sizeof(cmd_buf), "sendmsg %s", uuid);
+       }
+       
+       esl_event_serialize(event, &txt, ESL_FALSE);
+       esl_log(ESL_LOG_DEBUG, "SENDMSG\n%s\n", txt);
+
+       if (send(handle->sock, txt, strlen(txt), 0) <= 0) goto fail;
+       
+       free(txt);
+
+       return esl_recv(handle);
+
+ fail:
+
+       handle->connected = 0;
+
+       free(txt);
+
+       return ESL_FAIL;
+}
+
+
 ESL_DECLARE(esl_status_t) esl_filter(esl_handle_t *handle, const char *header, const char *value)
 {
        char send_buf[1024] = "";
index 0c4bbd6f908dff56f6a73b8f969e781556ee8689..4f60a928ee20fdc61fdb3ed644fea0a5f2e44374 100644 (file)
@@ -205,6 +205,15 @@ ESLevent *ESLconnection::sendEvent(ESLevent *send_me)
        return new ESLevent("server_disconnected");
 }
 
+int ESLconnection::sendMSG(ESLevent *send_me, const char *uuid)
+{
+       if (esl_sendmsg(&handle, send_me->event, uuid) == ESL_SUCCESS) {
+               return 0;
+       }
+
+       return 1;
+}
+
 ESLevent *ESLconnection::recvEvent()
 {
        if (esl_recv_event(&handle, 1, NULL) == ESL_SUCCESS) {
index 095e814a0e364896270f72d2cc3f9a0bb108b0c4..a9e5df140b271084af0e471743387e31bef206c8 100644 (file)
@@ -397,6 +397,14 @@ ESL_DECLARE(esl_status_t) esl_execute(esl_handle_t *handle, const char *app, con
 */
 ESL_DECLARE(esl_status_t) esl_sendevent(esl_handle_t *handle, esl_event_t *event);
 
+/*!
+    \brief Send an event as a message to be parsed
+    \param handle Handle to which the event should be sent
+    \param event Event to be sent
+       \param uuid a specific uuid if not the default
+*/
+ESL_DECLARE(esl_status_t) esl_sendmsg(esl_handle_t *handle, esl_event_t *event, const char *uuid);
+
 /*!
     \brief Connect a handle to a host/port with a specific password. This will also authenticate against the server
     \param handle Handle to connect
index 947fe453d778546583decaac9585e66fc740ce32..0ea1e5da89743126921fc548189d0a6c81c25b2d 100644 (file)
@@ -86,6 +86,7 @@ class ESLconnection {
        ESLevent *api(const char *cmd, const char *arg = NULL);
        ESLevent *bgapi(const char *cmd, const char *arg = NULL, const char *job_uuid = NULL);
        ESLevent *sendEvent(ESLevent *send_me);
+       int sendMSG(ESLevent *send_me, const char *uuid = NULL);
        ESLevent *recvEvent();
        ESLevent *recvEventTimed(int ms);
        ESLevent *filter(const char *header, const char *value);