[Freeswitch-svn] [commit] r5851 - in freeswitch/trunk: conf src src/include src/mod/applications/mod_voicemail src/mod/endpoints/mod_sofia
Freeswitch SVN
anthm at freeswitch.org
Fri Oct 12 13:12:31 EDT 2007
Author: anthm
Date: Fri Oct 12 13:12:31 2007
New Revision: 5851
Modified:
freeswitch/trunk/conf/default_context.xml
freeswitch/trunk/src/include/switch_utils.h
freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c
freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c
freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c
freeswitch/trunk/src/switch_utils.c
Log:
minor adj
Modified: freeswitch/trunk/conf/default_context.xml
==============================================================================
--- freeswitch/trunk/conf/default_context.xml (original)
+++ freeswitch/trunk/conf/default_context.xml Fri Oct 12 13:12:31 2007
@@ -23,14 +23,14 @@
<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>
Modified: freeswitch/trunk/src/include/switch_utils.h
==============================================================================
--- freeswitch/trunk/src/include/switch_utils.h (original)
+++ freeswitch/trunk/src/include/switch_utils.h Fri Oct 12 13:12:31 2007
@@ -328,6 +328,7 @@
#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
Modified: freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c (original)
+++ freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c Fri Oct 12 13:12:31 2007
@@ -83,136 +83,6 @@
};
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 @@
}
//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 @@
}
//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);
Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c (original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c Fri Oct 12 13:12:31 2007
@@ -1924,6 +1924,8 @@
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));
Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c (original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c Fri Oct 12 13:12:31 2007
@@ -747,6 +747,7 @@
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 @@
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 @@
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");
Modified: freeswitch/trunk/src/switch_utils.c
==============================================================================
--- freeswitch/trunk/src/switch_utils.c (original)
+++ freeswitch/trunk/src/switch_utils.c Fri Oct 12 13:12:31 2007
@@ -68,6 +68,135 @@
}
+
+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;
More information about the Freeswitch-svn
mailing list