]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
Add sorta working win32 support
authorAndrew Thompson <andrew@hijacked.us>
Thu, 11 Jun 2009 22:29:37 +0000 (22:29 +0000)
committerAndrew Thompson <andrew@hijacked.us>
Thu, 11 Jun 2009 22:29:37 +0000 (22:29 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@13764 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/event_handlers/mod_erlang_event/ei_helpers.c
src/mod/event_handlers/mod_erlang_event/handle_msg.c
src/mod/event_handlers/mod_erlang_event/mod_erlang_event.2008.vcproj [new file with mode: 0644]
src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c
src/mod/event_handlers/mod_erlang_event/mod_erlang_event.h

index c08a54dbabf3e0046504f35bb2f389bc17c68959..ee001fecfe4619db75298537d8e22d6a4c3c1e8d 100644 (file)
@@ -143,9 +143,9 @@ int ei_pid_from_rpc(struct ei_cnode_s *ec, int sockfd, erlang_ref *ref, char *mo
 /* function to spawn a process on a remote node */
 int ei_spawn(struct ei_cnode_s *ec, int sockfd, erlang_ref *ref, char *module, char *function, int argc, char **argv)
 {
+       int i;
        ei_x_buff buf;
        ei_x_new_with_version(&buf);
-       int i;
 
        ei_x_encode_tuple_header(&buf, 3);
        ei_x_encode_atom(&buf, "$gen_call");
@@ -323,7 +323,7 @@ switch_status_t initialise_ei(struct ei_cnode_s *ec)
        memset(&server_addr, 0, sizeof(server_addr));
        
        /* convert the configured IP to network byte order, handing errors */
-       rv = inet_pton(AF_INET, prefs.ip, &server_addr.sin_addr.s_addr);
+       rv = switch_inet_pton(AF_INET, prefs.ip, &server_addr.sin_addr.s_addr);
        if (rv == 0) {
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not parse invalid ip address: %s\n", prefs.ip);
                return SWITCH_STATUS_FALSE;
@@ -336,7 +336,11 @@ switch_status_t initialise_ei(struct ei_cnode_s *ec)
        server_addr.sin_family = AF_INET;
        server_addr.sin_port = htons(prefs.port);
        
-        if ((nodehost = gethostbyaddr(&server_addr.sin_addr.s_addr, sizeof(server_addr.sin_addr.s_addr), AF_INET)))
+#ifdef WIN32
+        if ((nodehost = gethostbyaddr((const char*)&server_addr.sin_addr.s_addr, sizeof(server_addr.sin_addr.s_addr), AF_INET)))
+#else
+       if ((nodehost = gethostbyaddr((const char*)&server_addr.sin_addr.s_addr, sizeof(server_addr.sin_addr.s_addr), AF_INET)))
+#endif
                memcpy(thishostname, nodehost->h_name, EI_MAXHOSTNAMELEN);
        
        if (switch_strlen_zero_buf(thishostname)) {
index 2d02bbf3da197733ef763cb0872e78867120a37b..a8711a63871330e03a43f96245510942417566f3 100644 (file)
@@ -79,10 +79,11 @@ static void *SWITCH_THREAD_FUNC api_exec(switch_thread_t *thread, void *obj)
                switch_event_t *event;
 
                if (switch_event_create(&event, SWITCH_EVENT_BACKGROUND_JOB) == SWITCH_STATUS_SUCCESS) {
+                       ei_x_buff ebuf;
+
                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Job-UUID", acs->uuid_str);
                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Job-Command", acs->api_cmd);
 
-                       ei_x_buff ebuf;
                        ei_x_new_with_version(&ebuf);
 
                        if (acs->arg) {
@@ -250,20 +251,22 @@ static switch_status_t handle_msg_event(listener_t *listener, int arity, ei_x_bu
        else {
                int custom = 0;
                switch_event_types_t type;
+               int i = 0;
                
                if (!switch_test_flag(listener, LFLAG_EVENTS)) {
                        switch_set_flag_locked(listener, LFLAG_EVENTS);
                }
                
-               for (int i = 1; i < arity; i++) {
+               for (i = 1; i < arity; i++) {
                        if (!ei_decode_atom(buf->buff, &buf->index, atom)) {
                                
                                if (custom) {
                                        switch_core_hash_insert(listener->event_hash, atom, MARKER);
                                } else if (switch_name_event(atom, &type) == SWITCH_STATUS_SUCCESS) {
                                        if (type == SWITCH_EVENT_ALL) {
-                                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "ALL events enabled\n");
                                                uint32_t x = 0;
+
+                                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "ALL events enabled\n");
                                                for (x = 0; x < SWITCH_EVENT_ALL; x++) {
                                                        listener->event_list[x] = 1;
                                                }
@@ -295,9 +298,10 @@ static switch_status_t handle_msg_nixevent(listener_t *listener, int arity, ei_x
        }
        else {
                int custom = 0;
+               int i = 0;
                switch_event_types_t type;
                
-               for (int i = 1; i < arity; i++) {
+               for (i = 1; i < arity; i++) {
                        if (!ei_decode_atom(buf->buff, &buf->index, atom)) {
                                
                                if (custom) {
diff --git a/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.2008.vcproj b/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.2008.vcproj
new file mode 100644 (file)
index 0000000..0f56db3
--- /dev/null
@@ -0,0 +1,299 @@
+<?xml version="1.0" encoding="Windows-1252"?>\r
+<VisualStudioProject\r
+       ProjectType="Visual C++"\r
+       Version="9.00"\r
+       Name="mod_erlang_event"\r
+       ProjectGUID="{024864AC-0022-45F0-AB06-915C3E2C0FF1}"\r
+       RootNamespace="mod_erlang_event"\r
+       Keyword="Win32Proj"\r
+       TargetFrameworkVersion="131072"\r
+       >\r
+       <Platforms>\r
+               <Platform\r
+                       Name="Win32"\r
+               />\r
+               <Platform\r
+                       Name="x64"\r
+               />\r
+       </Platforms>\r
+       <ToolFiles>\r
+       </ToolFiles>\r
+       <Configurations>\r
+               <Configuration\r
+                       Name="Debug|Win32"\r
+                       ConfigurationType="2"\r
+                       InheritedPropertySheets="..\..\..\..\w32\module_debug.vsprops"\r
+                       CharacterSet="2"\r
+                       >\r
+                       <Tool\r
+                               Name="VCPreBuildEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCustomBuildTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXMLDataGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebServiceProxyGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCMIDLTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCLCompilerTool"\r
+                               AdditionalOptions="/I &quot;C:\Program Files\erl5.7.1\lib\erl_interface-3.6.1\include&quot; /D &quot;WIN32&quot; /D &quot;__WIN32__&quot;"\r
+                               UsePrecompiledHeader="0"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManagedResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPreLinkEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCLinkerTool"\r
+                               AdditionalOptions="&quot;C:\cygwin\home\andrew\otp_src_R13B01\lib\erl_interface\obj.debug\win32/ei.lib&quot; /NODEFAULTLIB:libcmt"\r
+                               RandomizedBaseAddress="1"\r
+                               DataExecutionPrevention="0"\r
+                       />\r
+                       <Tool\r
+                               Name="VCALinkTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManifestTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXDCMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCBscMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCFxCopTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCAppVerifierTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPostBuildEventTool"\r
+                       />\r
+               </Configuration>\r
+               <Configuration\r
+                       Name="Release|Win32"\r
+                       ConfigurationType="2"\r
+                       InheritedPropertySheets="..\..\..\..\w32\module_release.vsprops"\r
+                       CharacterSet="2"\r
+                       >\r
+                       <Tool\r
+                               Name="VCPreBuildEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCustomBuildTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXMLDataGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebServiceProxyGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCMIDLTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCLCompilerTool"\r
+                               AdditionalOptions="/I &quot;C:\Program Files\erl5.7.1\lib\erl_interface-3.6.1\include&quot; /D &quot;WIN32&quot; /D &quot;__WIN32__&quot;"\r
+                               UsePrecompiledHeader="0"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManagedResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPreLinkEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCLinkerTool"\r
+                               AdditionalOptions="&quot;C:\cygwin\home\andrew\otp_src_R13B01\lib\erl_interface\obj.debug\win32/ei.lib&quot;"\r
+                               RandomizedBaseAddress="1"\r
+                               DataExecutionPrevention="0"\r
+                       />\r
+                       <Tool\r
+                               Name="VCALinkTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManifestTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXDCMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCBscMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCFxCopTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCAppVerifierTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPostBuildEventTool"\r
+                       />\r
+               </Configuration>\r
+               <Configuration\r
+                       Name="Debug|x64"\r
+                       ConfigurationType="2"\r
+                       InheritedPropertySheets="..\..\..\..\w32\module_debug.vsprops"\r
+                       CharacterSet="2"\r
+                       >\r
+                       <Tool\r
+                               Name="VCPreBuildEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCustomBuildTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXMLDataGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebServiceProxyGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCMIDLTool"\r
+                               TargetEnvironment="3"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCLCompilerTool"\r
+                               UsePrecompiledHeader="0"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManagedResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPreLinkEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCLinkerTool"\r
+                               OutputFile="$(SolutionDir)$(PlatformName)\$(ConfigurationName)/mod/$(ProjectName).dll"\r
+                               RandomizedBaseAddress="1"\r
+                               DataExecutionPrevention="0"\r
+                               TargetMachine="17"\r
+                       />\r
+                       <Tool\r
+                               Name="VCALinkTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManifestTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXDCMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCBscMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCFxCopTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCAppVerifierTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPostBuildEventTool"\r
+                       />\r
+               </Configuration>\r
+               <Configuration\r
+                       Name="Release|x64"\r
+                       ConfigurationType="2"\r
+                       InheritedPropertySheets="..\..\..\..\w32\module_release.vsprops"\r
+                       CharacterSet="2"\r
+                       >\r
+                       <Tool\r
+                               Name="VCPreBuildEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCustomBuildTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXMLDataGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebServiceProxyGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCMIDLTool"\r
+                               TargetEnvironment="3"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCLCompilerTool"\r
+                               UsePrecompiledHeader="0"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManagedResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPreLinkEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCLinkerTool"\r
+                               OutputFile="$(SolutionDir)$(PlatformName)\$(ConfigurationName)/mod/$(ProjectName).dll"\r
+                               RandomizedBaseAddress="1"\r
+                               DataExecutionPrevention="0"\r
+                               TargetMachine="17"\r
+                       />\r
+                       <Tool\r
+                               Name="VCALinkTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManifestTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXDCMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCBscMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCFxCopTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCAppVerifierTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPostBuildEventTool"\r
+                       />\r
+               </Configuration>\r
+       </Configurations>\r
+       <References>\r
+       </References>\r
+       <Files>\r
+               <File\r
+                       RelativePath=".\ei_helpers.c"\r
+                       >\r
+               </File>\r
+               <File\r
+                       RelativePath=".\handle_msg.c"\r
+                       >\r
+               </File>\r
+               <File\r
+                       RelativePath=".\mod_erlang_event.c"\r
+                       >\r
+               </File>\r
+               <File\r
+                       RelativePath=".\mod_erlang_event.h"\r
+                       >\r
+               </File>\r
+       </Files>\r
+       <Globals>\r
+       </Globals>\r
+</VisualStudioProject>\r
index bd208e5fa2ce99250a3d747eed734acf84502442..eeee969db221d56e0dff4b2cf13d7a2a69791c95 100644 (file)
@@ -240,14 +240,19 @@ static void event_handler(switch_event_t *event)
 }
 
 
+#ifdef WIN32
+static void close_socket(SOCKET *sock)
+#else
 static void close_socket(int *sock)
+#endif
 {
        switch_mutex_lock(listen_list.sock_mutex);
        if (*sock) {
-               shutdown(*sock, SHUT_RDWR);
 #ifdef WIN32
+               shutdown(*sock, SD_BOTH);
                closesocket(*sock);
 #else
+               shutdown(*sock, SHUT_RDWR);
                close(*sock);
 #endif
                sock = NULL;
@@ -357,21 +362,22 @@ session_elem_t * find_session_elem_by_pid(listener_t *listener, erlang_pid *pid)
 static switch_xml_t erlang_fetch(const char *sectionstr, const char *tag_name, const char *key_name, const char *key_value,
                                                                switch_event_t *params, void *user_data)
 {
-       switch_xml_t xml = NULL;
-       struct erlang_binding *ptr;
-       switch_uuid_t uuid;
        char uuid_str[SWITCH_UUID_FORMATTED_LENGTH+1];
        int type, size;
        int i = 0;
        void *p = NULL;
        char *xmlstr;
+       struct erlang_binding *ptr;
+       switch_uuid_t uuid;
+       switch_xml_section_t section;
+       switch_xml_t xml = NULL;
        ei_x_buff *rep;
        ei_x_buff buf;
        ei_x_new_with_version(&buf);
 
        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "looking for bindings\n");
 
-       switch_xml_section_t section = switch_xml_parse_section_string((char *) sectionstr);
+       section = switch_xml_parse_section_string((char *) sectionstr);
 
        for (ptr = bindings.head; ptr && ptr->section != section; ptr = ptr->next); /* just get the first match */
 
@@ -459,6 +465,7 @@ static switch_status_t notify_new_session(listener_t *listener, session_elem_t *
        switch_core_session_t *session;
        switch_event_t *call_event=NULL;
        switch_channel_t *channel=NULL;
+       ei_x_buff lbuf;
 
        /* Send a message to the associated registered process to let it know there is a call.
           Message is a tuple of the form {call, <call-event>}
@@ -480,7 +487,6 @@ static switch_status_t notify_new_session(listener_t *listener, session_elem_t *
        switch_event_add_header_string(call_event, SWITCH_STACK_BOTTOM, "Content-Type", "command/reply");
        switch_event_add_header_string(call_event, SWITCH_STACK_BOTTOM, "Reply-Text", "+OK\n");
        
-       ei_x_buff lbuf;
        ei_x_new_with_version(&lbuf);
        ei_x_encode_tuple_header(&lbuf, 2);
        ei_x_encode_atom(&lbuf, "call");
@@ -709,11 +715,10 @@ static void listener_main_loop(listener_t *listener)
 
        while ((status >= 0 || erl_errno == ETIMEDOUT || erl_errno == EAGAIN) && !prefs.done) {
                erlang_msg msg;
-
                ei_x_buff buf;
-               ei_x_new(&buf);
-
                ei_x_buff rbuf;
+               
+               ei_x_new(&buf);
                ei_x_new_with_version(&rbuf);
 
                /* do we need the mutex when reading? */
@@ -1464,7 +1469,7 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_erlang_event_runtime)
        memset(&server_addr, 0, sizeof(server_addr));
 
        /* convert the configured IP to network byte order, handing errors */
-       rv = inet_pton(AF_INET, prefs.ip, &server_addr.sin_addr.s_addr);
+       rv = switch_inet_pton(AF_INET, prefs.ip, &server_addr.sin_addr.s_addr);
        if (rv == 0) {
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not parse invalid ip address: %s\n", prefs.ip);
                goto init_failed;
@@ -1485,7 +1490,11 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_erlang_event_runtime)
                        goto sock_fail;
                }
 
+#ifdef WIN32
+               if (setsockopt(listen_list.sockfd, SOL_SOCKET, SO_REUSEADDR, (const char *)&on, sizeof(on))) {
+#else
                if (setsockopt(listen_list.sockfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on))) {
+#endif
                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to enable SO_REUSEADDR for socket on %s:%u : %s\n", prefs.ip, prefs.port, strerror(errno));
                        goto sock_fail;
                }
@@ -1500,7 +1509,7 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_erlang_event_runtime)
                        goto sock_fail;
                }
 
-               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Socket up listening on %s:%u\n", prefs.ip, prefs.port);
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Socket %d up listening on %s:%u\n", listen_list.sockfd, prefs.ip, prefs.port);
                break;
          sock_fail:
                switch_yield(100000);
@@ -1538,13 +1547,18 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_erlang_event_runtime)
 #else
                errno = 0;
 #endif
-               if ((clientfd = ei_accept_tmo(&ec, listen_list.sockfd, &conn, 100)) == ERL_ERROR) {
+               if ((clientfd = ei_accept_tmo(&ec, (int)listen_list.sockfd, &conn, 100)) == ERL_ERROR) {
                        if (prefs.done) {
                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Shutting Down\n");
                        } else if (erl_errno == ETIMEDOUT) {
                                continue;
+#ifdef WIN32
+                       } else if (WSAGetLastError()) {
+                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Socket Error %d %d\n", erl_errno, WSAGetLastError());
+#else
                        } else if (errno) {
                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Socket Error %d %d\n", erl_errno, errno);
+#endif
                        } else {
                                /* if errno didn't get set, assume nothing *too* horrible occured */
                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE,
@@ -1557,7 +1571,7 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_erlang_event_runtime)
                listener = new_listener(&ec,clientfd);
                if (listener) {
                        /* store the IP and node name we are talking with */
-                       inet_ntop(AF_INET, conn.ipadr, listener->remote_ip, sizeof(listener->remote_ip));
+                       switch_inet_ntop(AF_INET, conn.ipadr, listener->remote_ip, sizeof(listener->remote_ip));
                        listener->peer_nodename = switch_core_strdup(listener->pool,conn.nodename);
 
                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Launching listener, connection from node %s, ip %s\n", conn.nodename, listener->remote_ip);
index 248b773aa361e0961c45b9d71f2a0eef588fd265..b761ec0e1b7364b92bfe59e37d91d8f8a0201253 100644 (file)
@@ -81,7 +81,11 @@ typedef enum {
    5 call sessions will be "attached" to the same listener.
  */
 struct listener {
+#ifdef WIN32
+       SOCKET sockfd;
+#else
        int sockfd;
+#endif
        struct ei_cnode_s *ec;
        struct erlang_process log_process;
        struct erlang_process event_process;
@@ -221,7 +225,7 @@ switch_status_t initialise_ei(struct ei_cnode_s *ec);
 }
 
 #ifdef WIN32 /* MSDN suggested hack to fake errno for network operations */
-#define errno WSAGetLastError()
+/*#define errno WSAGetLastError()*/
 #endif
 
 /* mod_erlang_event.c */