[Freeswitch-svn] [commit] r5847 - in freeswitch/trunk: conf src/mod/applications/mod_voicemail src/mod/languages/mod_spidermonkey_etpan

Freeswitch SVN anthm at freeswitch.org
Fri Oct 12 09:31:13 EDT 2007


Author: anthm
Date: Fri Oct 12 09:31:12 2007
New Revision: 5847

Modified:
   freeswitch/trunk/conf/directory.xml
   freeswitch/trunk/conf/voicemail.conf.xml
   freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c
   freeswitch/trunk/src/mod/languages/mod_spidermonkey_etpan/mod_spidermonkey_etpan.c

Log:
small adjustments

Modified: freeswitch/trunk/conf/directory.xml
==============================================================================
--- freeswitch/trunk/conf/directory.xml	(original)
+++ freeswitch/trunk/conf/directory.xml	Fri Oct 12 09:31:12 2007
@@ -36,6 +36,7 @@
       <param name="password" value="mypass"/>
       <param name="vm-password" value="1234"/><!--if vm-password is omitted password param is used-->
       <!--<param name="vm-mailto" value="me at mydomain.com"/>-->
+      <!--<param name="vm-email-all-messages" value="true"/>-->
       <!-- optionally use this instead if you want to store the hash of user:domain:pass-->
       <!--<param name="a1-hash" value="c6440e5de50b403206989679159de89a"/>-->
     </params>

Modified: freeswitch/trunk/conf/voicemail.conf.xml
==============================================================================
--- freeswitch/trunk/conf/voicemail.conf.xml	(original)
+++ freeswitch/trunk/conf/voicemail.conf.xml	Fri Oct 12 09:31:12 2007
@@ -3,6 +3,7 @@
   </settings>
   <profiles>
     <profile name="demo">
+      <param name="file-extension" value="wav"/>
       <param name="terminator-key" value="#"/>
       <param name="max-login-attempts" value="3"/>
       <param name="digit-timeout" value="10000"/>

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 09:31:12 2007
@@ -71,6 +71,8 @@
     char save_file_key[2];
     char delete_file_key[2];
     char undelete_file_key[2];
+    char email_key[2];
+    char file_ext[10];
     char *tone_spec;
     uint32_t digit_timeout;
     uint32_t max_login_attempts;
@@ -197,7 +199,7 @@
     if (ifd) {
         close(ifd);
     }
-    snprintf(buf, B64BUFFLEN, "/bin/cat %s | /usr/sbin/sendmail -tvf \"%s\" %s", filename, from, to);
+    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);
     }
@@ -394,7 +396,9 @@
         char *save_file_key = "2";
         char *delete_file_key = "7";
         char *undelete_file_key = "8";
+        char *email_key = "4";
         char *tone_spec = "%(1000, 0, 640)";
+        char *file_ext = "wav";
 
         switch_core_db_t *db;
         uint32_t timeout = 10000, max_login_attempts = 3, max_record_len = 300;
@@ -436,6 +440,10 @@
                 delete_file_key = val;
             } else if (!strcasecmp(var, "undelete-file-key") && !switch_strlen_zero(val)) {
                 undelete_file_key = val;
+            } else if (!strcasecmp(var, "email-key") && !switch_strlen_zero(val)) {
+                email_key = val;
+            } else if (!strcasecmp(var, "file-extension")) {
+                file_ext = val;
             } else if (!strcasecmp(var, "tone-spec")) {
                 tone_spec = val;
             } else if (!strcasecmp(var, "digit-timeout")) {
@@ -546,8 +554,9 @@
             *profile->save_file_key = *save_file_key;
             *profile->delete_file_key = *delete_file_key;
             *profile->undelete_file_key = *undelete_file_key;
+            *profile->email_key = *email_key;
             profile->tone_spec = switch_core_strdup(globals.pool, tone_spec);
-            
+            switch_copy_string(profile->file_ext, file_ext, sizeof(profile->file_ext));
             switch_mutex_init(&profile->mutex, SWITCH_MUTEX_NESTED, globals.pool);
             
             switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Added Profile %s\n", profile->name);
@@ -873,6 +882,7 @@
     char in_folder[255];
     char file_path[255];
     char flags[255];
+    char *email;
     int index;
     int want;
     msg_type_t type;
@@ -924,7 +934,7 @@
                  profile->listen_file_key,
                  profile->save_file_key,
                  profile->delete_file_key,
-                 profile->undelete_file_key);
+                 profile->email_key);
 
 
         snprintf(input, sizeof(input), "%s:%d", cbt->type == MSG_NEW ? "new" : "saved", cbt->index);
@@ -936,18 +946,43 @@
         args.input_callback = control_playback;
         args.buf = &fh;
         TRY_CODE(switch_ivr_play_file(session, NULL, cbt->file_path, &args));
-        
+        printf("XXXX wtf[%s]\n", cbt->email);
         if (switch_channel_ready(channel)) {
             status = vm_macro_get(session, VM_LISTEN_FILE_CHECK_MACRO, 
                                   key_buf, input, sizeof(input), 1, profile->terminator_key, &term, profile->digit_timeout);
             
             if (!strcmp(input, profile->listen_file_key)) {
                 goto play_file;
-            } else if (!strcmp(input, profile->delete_file_key)) {
+            } else if (!strcmp(input, profile->delete_file_key) || !strcmp(input, profile->email_key)) {
                 char *sql = switch_mprintf("update voicemail_data set flags='delete' where uuid='%s'", cbt->uuid);
                 vm_execute_sql(profile, sql, profile->mutex);
                 switch_safe_free(sql);
-                TRY_CODE(switch_ivr_phrase_macro(session, VM_ACK_MACRO, "deleted", NULL, NULL));
+                if (!strcmp(input, profile->email_key) && !switch_strlen_zero(cbt->email)) {
+                    switch_event_t *event;
+                    char *from = switch_core_session_sprintf(session, "%s@%s", cbt->user, cbt->domain);
+                    char *headers = switch_core_session_sprintf(session, "From: FreeSWITCH mod_voicemail <%s@%s>\nSubject: Voicemail from %s %s", 
+                                                                cbt->user, cbt->domain, cbt->cid_name, cbt->cid_number);
+                                                                
+                    char *body;
+
+                    
+                    if (switch_event_create(&event, SWITCH_EVENT_MESSAGE) == SWITCH_STATUS_SUCCESS) {
+                        switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Message-Type", "forwarded-voicemail");
+                        switch_event_serialize(event, &body);
+                        switch_event_fire(&event);
+                    } else {
+                        body = switch_mprintf("Voicemail from %s %s", 
+                                              cbt->cid_name, cbt->cid_number);
+                    }
+
+                    //TBD add better formatting to the body
+                    vm_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));
+                } else {
+                    TRY_CODE(switch_ivr_phrase_macro(session, VM_ACK_MACRO, "deleted", NULL, NULL));
+                }
             } else {
                 char *sql = switch_mprintf("update voicemail_data set flags='save' where uuid='%s'", cbt->uuid);
                 vm_execute_sql(profile, sql, profile->mutex);
@@ -1007,7 +1042,7 @@
     int total_new_messages = 0;
     int total_saved_messages = 0;
     int heard_auto_saved = 0, heard_auto_new = 0;
-
+    char *email_vm = NULL;
     channel = switch_core_session_get_channel(session);
     assert(channel != NULL);    
 
@@ -1086,6 +1121,7 @@
                 int cur_message, total_messages;
                 message_count(profile, myid, domain_name, myfolder, &total_new_messages, &total_saved_messages);
                 memset(&cbt, 0, sizeof(cbt));
+                cbt.email = email_vm;
                 switch(play_msg_type) {
                 case MSG_NEW:
                     {
@@ -1167,7 +1203,7 @@
                                           profile->terminator_key, &term, timeout));
                     
                     num = atoi(input);
-                    file_path = switch_mprintf("%s%sgreeting_%d.wav", dir_path, SWITCH_PATH_SEPARATOR, num);
+                    file_path = switch_mprintf("%s%sgreeting_%d.%s", dir_path, SWITCH_PATH_SEPARATOR, num, profile->file_ext);
                     if (num < 1 || num > 3) {
                         status = SWITCH_STATUS_FALSE;
                     } else {
@@ -1195,7 +1231,7 @@
                     if (num < 1 || num > 3) {
                         TRY_CODE(switch_ivr_phrase_macro(session, VM_CHOOSE_GREETING_FAIL_MACRO, NULL, NULL, NULL));
                     } else {
-                        file_path = switch_mprintf("%s%sgreeting_%d.wav", dir_path, SWITCH_PATH_SEPARATOR, num);
+                        file_path = switch_mprintf("%s%sgreeting_%d.%s", dir_path, SWITCH_PATH_SEPARATOR, num, profile->file_ext);
                         TRY_CODE(create_file(session, profile, VM_RECORD_GREETING_MACRO, file_path));
                         sql = switch_mprintf("update voicemail_prefs set greeting_path='%s' where user='%s' and domain='%s'", file_path, myid, domain_name);
                         vm_execute_sql(profile, sql, profile->mutex);
@@ -1204,7 +1240,7 @@
                     }
 
                 } else if (!strcmp(input, profile->record_name_key)) {
-                    file_path = switch_mprintf("%s%srecorded_name.wav", dir_path, SWITCH_PATH_SEPARATOR);
+                    file_path = switch_mprintf("%s%srecorded_name.%s", dir_path, SWITCH_PATH_SEPARATOR, profile->file_ext);
                     TRY_CODE(create_file(session, profile, VM_RECORD_NAME_MACRO, file_path));
                     sql = switch_mprintf("update voicemail_prefs set name_path='%s' where user='%s' and domain='%s'", file_path, myid, domain_name);
                     vm_execute_sql(profile, sql, profile->mutex);
@@ -1321,6 +1357,8 @@
                         thepass = val;
                     } else if (!strcasecmp(var, "vm-password")) {
                         thepass = val;
+                    } else if (!strcasecmp(var, "vm-mailto")) {
+                        email_vm = switch_core_session_strdup(session, val);
                     }
                 }
                 switch_xml_free(x_domain_root);
@@ -1352,6 +1390,7 @@
                 }
                 
                 continue;
+                
             failed:
                 status = switch_ivr_phrase_macro(session, VM_FAIL_AUTH_MACRO, NULL, NULL, NULL);
                 myid = id;
@@ -1378,7 +1417,7 @@
     }
 
 }
-
+    
 
 static switch_status_t voicemail_leave_main(switch_core_session_t *session, char *profile_name, char *domain_name, char *id)
 {
@@ -1395,6 +1434,7 @@
     switch_file_handle_t fh = { 0 };
     switch_input_args_t args = { 0 };
     char *email_vm = NULL;
+    int send_mail = 0;
 
     memset(&cbt, 0, sizeof(cbt));
     if (!(profile = switch_core_hash_find(globals.profile_hash, profile_name))) {
@@ -1428,21 +1468,25 @@
         assert(xtra);
         x_user = x_domain = x_domain_root = NULL;
         if (switch_xml_locate_user(id, domain_name, switch_channel_get_variable(channel, "network_addr"), 
-                                   &x_domain_root, &x_domain, &x_user, xtra) != SWITCH_STATUS_SUCCESS) {
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "can't find user [%s@%s]\n", id, domain_name);
-            ok = 0;
-        }
-
-        if ((x_params = switch_xml_child(x_user, "params"))) {
-            for (x_param = switch_xml_child(x_params, "param"); x_param; x_param = x_param->next) {
-                const char *var = switch_xml_attr_soft(x_param, "name");
-                const char *val = switch_xml_attr_soft(x_param, "value");
-            
-                if (!strcasecmp(var, "vm-mailto")) {
-                    email_vm = switch_core_session_strdup(session, val);
+                                   &x_domain_root, &x_domain, &x_user, xtra) == SWITCH_STATUS_SUCCESS) {
+            if ((x_params = switch_xml_child(x_user, "params"))) {
+                for (x_param = switch_xml_child(x_params, "param"); x_param; x_param = x_param->next) {
+                    const char *var = switch_xml_attr_soft(x_param, "name");
+                    const char *val = switch_xml_attr_soft(x_param, "value");
+                    
+                    if (!strcasecmp(var, "vm-mailto")) {
+                        email_vm = switch_core_session_strdup(session, val);
+                    } else if (!strcasecmp(var, "vm-email-all-messages")) {
+                        send_mail = switch_true(var);
+                    }
                 }
             }
+
+        } else {
+            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "can't find user [%s@%s]\n", id, domain_name);
+            ok = 0;
         }
+        
 
         switch_safe_free(xtra);
         switch_xml_free(x_domain_root);
@@ -1457,7 +1501,7 @@
              domain_name);
     vm_execute_sql_callback(profile, profile->mutex, sql, prefs_callback, &cbt);
     
-    file_path = switch_mprintf("%s%smsg_%s.wav", dir_path, SWITCH_PATH_SEPARATOR, uuid);
+    file_path = switch_mprintf("%s%smsg_%s.%s", dir_path, SWITCH_PATH_SEPARATOR, uuid, profile->file_ext);
 
     memset(&fh, 0, sizeof(fh));
     args.input_callback = control_playback;
@@ -1472,7 +1516,7 @@
         TRY_CODE(switch_ivr_phrase_macro(session, VM_PLAY_GREETING_MACRO, id, NULL, NULL));
     }
 
-    if(switch_channel_ready(channel)) {
+    if(!send_mail && switch_channel_ready(channel)) {
         char *usql;
         status = create_file(session, profile, VM_RECORD_MESSAGE_MACRO, file_path);
         if (status == SWITCH_STATUS_SUCCESS || status == SWITCH_STATUS_BREAK) {
@@ -1489,11 +1533,10 @@
 
  end:
     
-    if (!switch_strlen_zero(email_vm)) {
-        
+    if (send_mail && !switch_strlen_zero(email_vm)) {
         switch_event_t *event;
-        char *from = switch_core_session_sprintf(session, "FreeSWITCH mod_voicemail <%s@%s>", id, domain_name);
-        char *headers = switch_core_session_sprintf(session, "Subject: Voicemail from %s %s", 
+        char *from = switch_core_session_sprintf(session, "%s@%s", id, domain_name);
+        char *headers = switch_core_session_sprintf(session, "From: FreeSWITCH mod_voicemail <%s@%s>\nSubject: Voicemail from %s %s", id, domain_name,
                                                     caller_profile->caller_id_name, caller_profile->caller_id_number);
         char *body;
 
@@ -1510,8 +1553,9 @@
 
         //TBD add better formatting to the body
         vm_email(email_vm, from, headers, body, file_path);
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Sending message to %s", email_vm);
+        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Sending message to %s\n", email_vm);
         switch_safe_free(body);
+        unlink(file_path);
     }
 
     switch_safe_free(file_path);

Modified: freeswitch/trunk/src/mod/languages/mod_spidermonkey_etpan/mod_spidermonkey_etpan.c
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_spidermonkey_etpan/mod_spidermonkey_etpan.c	(original)
+++ freeswitch/trunk/src/mod/languages/mod_spidermonkey_etpan/mod_spidermonkey_etpan.c	Fri Oct 12 09:31:12 2007
@@ -37,20 +37,7 @@
 
 static const char modname[] = "etpan";
 
-#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;
-}
 
 /* etpan Object */
 /*********************************************************************************/
@@ -74,130 +61,7 @@
 	etpan_NAME
 };
 
-static JSBool js_email(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
-{
-	char *to = NULL, *from = NULL, *headers, *body = NULL, *file = NULL;
-	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;
-
-
-	if (argc > 3 &&
-		(from = JS_GetStringBytes(JS_ValueToString(cx, argv[0]))) &&
-		(to = JS_GetStringBytes(JS_ValueToString(cx, argv[1]))) &&
-		(headers = JS_GetStringBytes(JS_ValueToString(cx, argv[2]))) && (body = JS_GetStringBytes(JS_ValueToString(cx, argv[3])))
-		) {
-		if (argc > 4) {
-			file = JS_GetStringBytes(JS_ValueToString(cx, argv[4]));
-		}
-		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 JS_FALSE;
-				}
-
-				snprintf(buf, B64BUFFLEN, "MIME-Version: 1.0\nContent-Type: multipart/mixed; boundary=\"%s\"\n", bound);
-				if (!write_buf(fd, buf)) {
-					return JS_FALSE;
-				}
-			}
-
-			if (!write_buf(fd, headers))
-				return JS_FALSE;
-
-			if (!write_buf(fd, "\n\n"))
-				return JS_FALSE;
-
-			if (file) {
-				snprintf(buf, B64BUFFLEN, "--%s\nContent-Type: text/plain\n\n", bound);
-				if (!write_buf(fd, buf))
-					return JS_FALSE;
-			}
-
-			if (!write_buf(fd, body))
-				return JS_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, (argc > 5) ? JS_GetStringBytes(JS_ValueToString(cx,argv[5])) : switch_cut_path(file));
-				if (!write_buf(fd, buf))
-					return JS_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 JS_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_INFO, "Emailed file [%s] to [%s]\n", filename, to);
-		} else {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Emailed data to [%s]\n", to);
-		}
-		return JS_TRUE;
-	}
-
-
-	return JS_FALSE;
-}
 
 static JSFunctionSpec etpan_methods[] = {
 //  {"myMethod", odbc_my_method, 1},



More information about the Freeswitch-svn mailing list