]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
minor adj
authorAnthony Minessale <anthony.minessale@gmail.com>
Fri, 12 Oct 2007 17:12:31 +0000 (17:12 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Fri, 12 Oct 2007 17:12:31 +0000 (17:12 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@5851 d0543943-73ff-0310-b7d9-9358b9ac24b2

conf/default_context.xml
src/include/switch_utils.h
src/mod/applications/mod_voicemail/mod_voicemail.c
src/mod/endpoints/mod_sofia/sofia.c
src/mod/endpoints/mod_sofia/sofia_reg.c
src/switch_utils.c

index 2776a48997b9b4e87a7f116612fbf13baa6c49d7..7c4a4023dfc9b1b199d2b9235da773e147cf68d3 100644 (file)
     <condition field="destination_number" expression="^7771$">
       <action application="answer"/>
       <action application="set" data="voicemail_authorized=${sip_authorized}"/>
-      <action application="voicemail" data="check demo $${domain} ${sip_from_user}"/>
+      <action application="voicemail" data="check demo $${domain} ${sip_mailbox}"/>
     </condition>
   </extension>
 
   <extension name="7772">
     <condition field="destination_number" expression="^7772$">
       <action application="answer"/>
-      <action application="voicemail" data="demo $${domain} ${sip_from_user}"/>
+      <action application="voicemail" data="demo $${domain} ${sip_mailbox}"/>
     </condition>
   </extension>
 
index 21a5fbc82a05c3fbb4ef583c468d0a818e3ae50c..1f93b89085af7d9f07a68455013e38b84463722f 100644 (file)
@@ -328,6 +328,7 @@ SWITCH_DECLARE(switch_status_t) switch_string_match(const char *string, size_t s
 #define SWITCH_READ_ACCEPTABLE(status) (status == SWITCH_STATUS_SUCCESS || status == SWITCH_STATUS_BREAK)
 SWITCH_DECLARE(size_t) switch_url_encode(char *url, char *buf, size_t len);
 SWITCH_DECLARE(char *) switch_url_decode(char *s);
+SWITCH_DECLARE(switch_bool_t) switch_simple_email(char *to, char *from, char *headers, char *body, char *file);
 
 /* malloc or DIE macros */
 #ifdef NDEBUG
index 6940d648ef39f5f3c1bbc81cade97fc68c68ce51..9b52c22c086caf4a97ff8ad2916742bc5452f45b 100644 (file)
@@ -83,136 +83,6 @@ struct vm_profile {
 };
 typedef struct vm_profile vm_profile_t;
 
-
-#define B64BUFFLEN 1024
-static const char c64[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-
-static int write_buf(int fd, char *buf)
-{
-
-       int len = (int) strlen(buf);
-       if (fd && write(fd, buf, len) != len) {
-               close(fd);
-               return 0;
-       }
-
-       return 1;
-}
-static switch_bool_t vm_email(char *to, char *from, char *headers, char *body, char *file)
-{
-       char *bound = "XXXX_boundary_XXXX";
-       char filename[80], buf[B64BUFFLEN];
-       int fd = 0, ifd = 0;
-       int x = 0, y = 0, bytes = 0, ilen = 0;
-       unsigned int b = 0, l = 0;
-       unsigned char in[B64BUFFLEN];
-       unsigned char out[B64BUFFLEN + 512];
-       char *path = NULL;
-
-    snprintf(filename, 80, "%smail.%ld%04x", SWITCH_GLOBAL_dirs.temp_dir, time(NULL), rand() & 0xffff);
-    
-    if ((fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0644))) {
-        if (file) {
-            path = file;
-            if ((ifd = open(path, O_RDONLY)) < 1) {
-                return SWITCH_FALSE;
-            }
-
-            snprintf(buf, B64BUFFLEN, "MIME-Version: 1.0\nContent-Type: multipart/mixed; boundary=\"%s\"\n", bound);
-            if (!write_buf(fd, buf)) {
-                return SWITCH_FALSE;
-            }
-        }
-
-        if (headers && !write_buf(fd, headers))
-            return SWITCH_FALSE;
-
-        if (!write_buf(fd, "\n\n"))
-            return SWITCH_FALSE;
-
-        if (file) {
-            snprintf(buf, B64BUFFLEN, "--%s\nContent-Type: text/plain\n\n", bound);
-            if (!write_buf(fd, buf))
-                return SWITCH_FALSE;
-        }
-
-        if (body) {
-            if (!write_buf(fd, body)) {
-                return SWITCH_FALSE;
-            }
-        }
-
-        if (file) {
-            snprintf(buf, B64BUFFLEN, "\n\n--%s\nContent-Type: application/octet-stream\n"
-                     "Content-Transfer-Encoding: base64\n"
-                     "Content-Description: Sound attachment.\n" "Content-Disposition: attachment; filename=\"%s\"\n\n", bound,  switch_cut_path(file));
-            if (!write_buf(fd, buf))
-                return SWITCH_FALSE;
-
-            while ((ilen = read(ifd, in, B64BUFFLEN))) {
-                for (x = 0; x < ilen; x++) {
-                    b = (b << 8) + in[x];
-                    l += 8;
-                    while (l >= 6) {
-                        out[bytes++] = c64[(b >> (l -= 6)) % 64];
-                        if (++y != 72)
-                            continue;
-                        out[bytes++] = '\n';
-                        y = 0;
-                    }
-                }
-                if (write(fd, &out, bytes) != bytes) {
-                    return -1;
-                } else
-                    bytes = 0;
-
-            }
-
-            if (l > 0) {
-                out[bytes++] = c64[((b % 16) << (6 - l)) % 64];
-            }
-            if (l != 0)
-                while (l < 6) {
-                    out[bytes++] = '=', l += 2;
-                }
-            if (write(fd, &out, bytes) != bytes) {
-                return -1;
-            }
-
-        }
-
-
-
-        if (file) {
-            snprintf(buf, B64BUFFLEN, "\n\n--%s--\n.\n", bound);
-            if (!write_buf(fd, buf))
-                return SWITCH_FALSE;
-        }
-    }
-
-    if (fd) {
-        close(fd);
-    }
-    if (ifd) {
-        close(ifd);
-    }
-    snprintf(buf, B64BUFFLEN, "/bin/cat %s | /usr/sbin/sendmail -tf \"%s\" %s", filename, from, to);
-    if(system(buf)) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to execute command: %s\n", buf);
-    }
-
-    unlink(filename);
-
-
-    if (file) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Emailed file [%s] to [%s]\n", filename, to);
-    } else {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Emailed data to [%s]\n", to);
-    }
-
-    return SWITCH_TRUE;
-}
-
 static switch_status_t vm_execute_sql(vm_profile_t *profile, char *sql, switch_mutex_t *mutex)
 {
        switch_core_db_t *db;
@@ -953,7 +823,7 @@ static switch_status_t listen_file(switch_core_session_t *session, vm_profile_t
                     }
 
                     //TBD add better formatting to the body
-                    vm_email(cbt->email, from, headers, body, cbt->file_path);
+                    switch_simple_email(cbt->email, from, headers, body, cbt->file_path);
                     switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Sending message to %s\n", cbt->email);
                     switch_safe_free(body);
                     TRY_CODE(switch_ivr_phrase_macro(session, VM_ACK_MACRO, "emailed", NULL, NULL));
@@ -1532,7 +1402,7 @@ static switch_status_t voicemail_leave_main(switch_core_session_t *session, char
         }
 
         //TBD add better formatting to the body
-        vm_email(email_vm, from, headers, body, file_path);
+        switch_simple_email(email_vm, from, headers, body, file_path);
         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Sending message to %s\n", email_vm);
         switch_safe_free(body);
         unlink(file_path);
index d72ea7b9380596235e3634e258838af6d0684ae1..f48e288b2dea1154c8286d427fe698ee5aa9c5d6 100644 (file)
@@ -1924,6 +1924,8 @@ void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_
                from_host = sip->sip_from->a_url->url_host;
                channel_name = url_set_chanvars(session, sip->sip_from->a_url, sip_from);
 
+               switch_channel_set_variable(channel, "sip_mailbox", from_user);
+
                if (!switch_strlen_zero(from_user)) {
                        if (*from_user == '+') {
                                switch_channel_set_variable(channel, "sip_from_user_stripped", (const char *) (from_user + 1));
index 6673443560ee7a23bf856f9d3d3d270250b8326a..037ff3c7b6d45b15b869f8d6faa7a2554cd503b4 100644 (file)
@@ -747,6 +747,7 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, sip_authorization_t co
        const char *passwd = NULL;
        const char *a1_hash = NULL;
        char *sql;
+       char *mailbox = NULL;
        switch_xml_t domain, xml = NULL, user, param, xparams;  
        char hexdigest[2 * SU_MD5_DIGEST_SIZE + 1] = "";
        char *pbuf = NULL;
@@ -829,7 +830,11 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, sip_authorization_t co
                ret = AUTH_FORBIDDEN;
                goto end;
        }
-               
+       
+       if (!(mailbox = (char *)switch_xml_attr(user, "mailbox"))) {
+               mailbox = username;
+       }
+
        for (param = switch_xml_child(xparams, "param"); param; param = param->next) {
                const char *var = switch_xml_attr_soft(param, "name");
                const char *val = switch_xml_attr_soft(param, "value");
@@ -899,6 +904,7 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, sip_authorization_t co
        if (first && ret == AUTH_OK) {
                if (v_event && (xparams = switch_xml_child(user, "variables"))) {
                        if (switch_event_create(v_event, SWITCH_EVENT_MESSAGE) == SWITCH_STATUS_SUCCESS) {
+                               switch_event_add_header(*v_event, SWITCH_STACK_BOTTOM, "sip_mailbox", "%s", mailbox);
                                for (param = switch_xml_child(xparams, "variable"); param; param = param->next) {
                                        const char *var = switch_xml_attr_soft(param, "name");
                                        const char *val = switch_xml_attr_soft(param, "value");
index 0287eede1782ceadb8c1ee65c06753e94bd4c08f..ce2683c3f09d54a1871fd8608c95208c73150e9d 100644 (file)
@@ -68,6 +68,135 @@ SWITCH_DECLARE(switch_status_t) switch_b64_encode(unsigned char *in, switch_size
 }
 
 
+
+static int write_buf(int fd, char *buf)
+{
+
+       int len = (int) strlen(buf);
+       if (fd && write(fd, buf, len) != len) {
+               close(fd);
+               return 0;
+       }
+
+       return 1;
+}
+
+SWITCH_DECLARE(switch_bool_t) switch_simple_email(char *to, char *from, char *headers, char *body, char *file)
+{
+       char *bound = "XXXX_boundary_XXXX";
+       char filename[80], buf[B64BUFFLEN];
+       int fd = 0, ifd = 0;
+       int x = 0, y = 0, bytes = 0, ilen = 0;
+       unsigned int b = 0, l = 0;
+       unsigned char in[B64BUFFLEN];
+       unsigned char out[B64BUFFLEN + 512];
+       char *path = NULL;
+
+    snprintf(filename, 80, "%smail.%ld%04x", SWITCH_GLOBAL_dirs.temp_dir, time(NULL), rand() & 0xffff);
+    
+    if ((fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0644))) {
+        if (file) {
+            path = file;
+            if ((ifd = open(path, O_RDONLY)) < 1) {
+                return SWITCH_FALSE;
+            }
+
+            snprintf(buf, B64BUFFLEN, "MIME-Version: 1.0\nContent-Type: multipart/mixed; boundary=\"%s\"\n", bound);
+            if (!write_buf(fd, buf)) {
+                return SWITCH_FALSE;
+            }
+        }
+
+        if (headers && !write_buf(fd, headers))
+            return SWITCH_FALSE;
+
+        if (!write_buf(fd, "\n\n"))
+            return SWITCH_FALSE;
+
+        if (file) {
+            snprintf(buf, B64BUFFLEN, "--%s\nContent-Type: text/plain\n\n", bound);
+            if (!write_buf(fd, buf))
+                return SWITCH_FALSE;
+        }
+
+        if (body) {
+            if (!write_buf(fd, body)) {
+                return SWITCH_FALSE;
+            }
+        }
+
+        if (file) {
+            snprintf(buf, B64BUFFLEN, "\n\n--%s\nContent-Type: application/octet-stream\n"
+                     "Content-Transfer-Encoding: base64\n"
+                     "Content-Description: Sound attachment.\n" "Content-Disposition: attachment; filename=\"%s\"\n\n", bound,  switch_cut_path(file));
+            if (!write_buf(fd, buf))
+                return SWITCH_FALSE;
+
+            while ((ilen = read(ifd, in, B64BUFFLEN))) {
+                for (x = 0; x < ilen; x++) {
+                    b = (b << 8) + in[x];
+                    l += 8;
+                    while (l >= 6) {
+                        out[bytes++] = switch_b64_table[(b >> (l -= 6)) % 64];
+                        if (++y != 72)
+                            continue;
+                        out[bytes++] = '\n';
+                        y = 0;
+                    }
+                }
+                if (write(fd, &out, bytes) != bytes) {
+                    return -1;
+                } else
+                    bytes = 0;
+
+            }
+
+            if (l > 0) {
+                out[bytes++] = switch_b64_table[((b % 16) << (6 - l)) % 64];
+            }
+            if (l != 0)
+                while (l < 6) {
+                    out[bytes++] = '=', l += 2;
+                }
+            if (write(fd, &out, bytes) != bytes) {
+                return -1;
+            }
+
+        }
+
+
+
+        if (file) {
+            snprintf(buf, B64BUFFLEN, "\n\n--%s--\n.\n", bound);
+            if (!write_buf(fd, buf))
+                return SWITCH_FALSE;
+        }
+    }
+
+    if (fd) {
+        close(fd);
+    }
+    if (ifd) {
+        close(ifd);
+    }
+    snprintf(buf, B64BUFFLEN, "/bin/cat %s | /usr/sbin/sendmail -tf \"%s\" %s", filename, from, to);
+    if(system(buf)) {
+        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to execute command: %s\n", buf);
+    }
+
+    unlink(filename);
+
+
+    if (file) {
+        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Emailed file [%s] to [%s]\n", filename, to);
+    } else {
+        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Emailed data to [%s]\n", to);
+    }
+
+    return SWITCH_TRUE;
+}
+
+
 SWITCH_DECLARE(switch_status_t) switch_find_local_ip(char *buf, int len, int family)
 {
        switch_status_t status = SWITCH_STATUS_FALSE;