[Freeswitch-svn] [commit] r12837 - freeswitch/trunk/scripts/contrib/jtregunna/mod_fastsms
FreeSWITCH SVN
jtregunna at freeswitch.org
Mon Mar 30 06:23:04 PDT 2009
Author: jtregunna
Date: Mon Mar 30 08:23:03 2009
New Revision: 12837
Log:
Added a module for the fastsms web service to scripts/contrib/jtregunna/mod_fastsms. README file is included with instructions, as well as a sample config file.
Tested on FreeBSD 7.1 with r12817, however should work fine on Linux and Windows as well. Though, due to development limitations, no VCProj is included.
Added:
freeswitch/trunk/scripts/contrib/jtregunna/mod_fastsms/
freeswitch/trunk/scripts/contrib/jtregunna/mod_fastsms/COPYING
freeswitch/trunk/scripts/contrib/jtregunna/mod_fastsms/Makefile
freeswitch/trunk/scripts/contrib/jtregunna/mod_fastsms/README
freeswitch/trunk/scripts/contrib/jtregunna/mod_fastsms/fastsms.conf.xml
freeswitch/trunk/scripts/contrib/jtregunna/mod_fastsms/mod_fastsms.c
Added: freeswitch/trunk/scripts/contrib/jtregunna/mod_fastsms/COPYING
==============================================================================
--- (empty file)
+++ freeswitch/trunk/scripts/contrib/jtregunna/mod_fastsms/COPYING Mon Mar 30 08:23:03 2009
@@ -0,0 +1,20 @@
+Copyright (c) 2006-2008 Hampton Catlin
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file
Added: freeswitch/trunk/scripts/contrib/jtregunna/mod_fastsms/Makefile
==============================================================================
--- (empty file)
+++ freeswitch/trunk/scripts/contrib/jtregunna/mod_fastsms/Makefile Mon Mar 30 08:23:03 2009
@@ -0,0 +1,3 @@
+BASE=../../../..
+WANT_CURL=yes
+include $(BASE)/build/modmake.rules
Added: freeswitch/trunk/scripts/contrib/jtregunna/mod_fastsms/README
==============================================================================
--- (empty file)
+++ freeswitch/trunk/scripts/contrib/jtregunna/mod_fastsms/README Mon Mar 30 08:23:03 2009
@@ -0,0 +1,33 @@
+mod_fastsms
+Copyright (c) 2009, Jeremy Tregunna, All Rights Reserved.
+
+What is it?
+
+mod_fastsms is a FreeSWITCH module that can be used to send Short Message Service (SMS)
+text messages via the FastSMS web service.
+
+Configuration
+
+A template fastsms.conf.xml is included, you will need to edit the auth tag to put in
+the information you get from the FastSMS service.
+
+As far as your dialplan goes, you can add something like this:
+
+<extension name="fastsms">
+ <condition field="destination_number" expression="^1200$">
+ <action application="fastsms" data="15145551212 Limit this bit of text to 160 characters. It's your message."/>
+ </condition>
+</extension>
+
+You can optionally define an originator (who the message appears to come from), in your
+directory, add this line:
+ <variable name="fastsms_originator" value="Mr. Bob's Server"/>
+
+and reloadxml.
+
+That's about it! Just copy the fastsms.conf.xml to your conf/autoload_configs and make
+the changes appropriately, copy this directory to freeswitch/src/mod/applications/mod_fastsms
+edit freeswitch/modules.conf and add a line "applications/mod_fastsms" then rebuild
+FreeSWITCH.
+
+Should you encounter problems, either drop me a line at jeremy.tregunna at me.com.
Added: freeswitch/trunk/scripts/contrib/jtregunna/mod_fastsms/fastsms.conf.xml
==============================================================================
--- (empty file)
+++ freeswitch/trunk/scripts/contrib/jtregunna/mod_fastsms/fastsms.conf.xml Mon Mar 30 08:23:03 2009
@@ -0,0 +1,5 @@
+<configuration name="fastsms.conf" description="fastsms">
+ <settings>
+ <auth companyid="XXX" userid="YYY" password="ZZZ"/>
+ </settings>
+</configuration>
Added: freeswitch/trunk/scripts/contrib/jtregunna/mod_fastsms/mod_fastsms.c
==============================================================================
--- (empty file)
+++ freeswitch/trunk/scripts/contrib/jtregunna/mod_fastsms/mod_fastsms.c Mon Mar 30 08:23:03 2009
@@ -0,0 +1,144 @@
+/*
+ * Interface to the FastSMS message service.
+ * Copyright (c) 2009, Jeremy Tregunna, All Rights Reserved.
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the MIT license. See COPYING for details.
+ */
+#include <switch.h>
+#include <curl/curl.h>
+
+SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_fastsms_shutdown);
+SWITCH_MODULE_RUNTIME_FUNCTION(mod_fastsms_runtime);
+SWITCH_MODULE_LOAD_FUNCTION(mod_fastsms_load);
+SWITCH_MODULE_DEFINITION(mod_fastsms, mod_fastsms_load, mod_fastsms_shutdown, NULL);
+
+static char* companyid;
+static char* userid;
+static char* password;
+static CURL* curl;
+
+static switch_status_t do_config(switch_bool_t reload)
+{
+ switch_xml_t cfg, xml, settings, auth;
+
+ if (!(xml = switch_xml_open_cfg("fastsms.conf", &cfg, NULL))) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Could not open fastsms.conf\n");
+ return SWITCH_STATUS_FALSE;
+ }
+
+ if ((settings = switch_xml_child(cfg, "settings"))) {
+ auth = switch_xml_child(settings, "auth");
+ companyid = (char*)switch_xml_attr_soft(auth, "companyid");
+ userid = (char*)switch_xml_attr_soft(auth, "userid");
+ password = (char*)switch_xml_attr_soft(auth, "password");
+ }
+
+ if (xml)
+ switch_xml_free(xml);
+
+ return SWITCH_STATUS_SUCCESS;
+}
+
+static switch_status_t fastsms_send_msg(switch_core_session_t* session, const char* msisdn, const char* text, const char* originator)
+{
+ char* params;
+ int error;
+ long response = 0;
+
+ if (originator) {
+ asprintf(¶ms, "CompanyId=%s&UserId=%s&Password=%s&Msisdn=%s&MessageText=%s&OasText=%s", companyid,
+ userid, password, msisdn, text, originator);
+ } else {
+ asprintf(¶ms, "CompanyId=%s&UserId=%s&Password=%s&Msisdn=%s&MessageText=%s", companyid, userid,
+ password, msisdn, text);
+ }
+
+ curl_easy_setopt(curl, CURLOPT_URL, "https://secure.bayhamsystems.com/mfi/sendMessage");
+ curl_easy_setopt(curl, CURLOPT_POSTFIELDS, params);
+ curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
+ if ((error = curl_easy_perform(curl)) != CURLE_OK)
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "FastSMS Error: %s\n", curl_easy_strerror(error));
+ curl_easy_getinfo(curl, CURLINFO_HTTP_CODE, &response);
+ free(params);
+
+ switch (response) {
+ case 200:
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "SMS message sent.\n");
+ return SWITCH_STATUS_SUCCESS;
+ break;
+ case 403:
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error: Forbidden.\n");
+ break;
+ default:
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "FastSMS Error: Response code %ld\n", response);
+ break;
+ }
+
+ return SWITCH_STATUS_FALSE;
+}
+
+#define FASTSMS_DESC "FastSMS SMS Message Service"
+#define FASTSMS_USAGE "<number> <text message>"
+
+SWITCH_STANDARD_APP(fastsms_function)
+{
+ switch_channel_t* channel = switch_core_session_get_channel(session);
+ char* msisdn = NULL;
+ char* text = NULL;
+ const char* originator = switch_channel_get_variable(channel, "fastsms_originator");
+
+ if (!switch_strlen_zero(data)) {
+ msisdn = switch_core_session_strdup(session, data);
+ text = strchr(msisdn, ' ');
+ if (text)
+ *text++ = '\0';
+ fastsms_send_msg(session, msisdn, text, originator);
+ }
+}
+
+SWITCH_STANDARD_API(fastsms_api_function)
+{
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Reloading FastSMS configuration file.\n");
+ do_config(SWITCH_TRUE);
+ return SWITCH_STATUS_SUCCESS;
+}
+
+SWITCH_MODULE_LOAD_FUNCTION(mod_fastsms_load)
+{
+ switch_status_t status;
+ switch_application_interface_t *app_interface;
+ switch_api_interface_t *api_interface;
+
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "FastSMS module loaded.\n");
+
+ if ((status = do_config(SWITCH_FALSE)) != SWITCH_STATUS_SUCCESS) {
+ return status;
+ }
+
+ *module_interface = switch_loadable_module_create_module_interface(pool, modname);
+ curl = curl_easy_init();
+
+ SWITCH_ADD_API(api_interface, "fastsms_api", "fastsms_api", fastsms_api_function, "syntax");
+ SWITCH_ADD_APP(app_interface, "fastsms", "fastsms", FASTSMS_DESC, fastsms_function, FASTSMS_USAGE, SAF_NONE);
+
+ /* indicate that the module should continue to be loaded */
+ return SWITCH_STATUS_SUCCESS;
+}
+
+SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_fastsms_shutdown)
+{
+ curl_easy_cleanup(curl);
+ return SWITCH_STATUS_SUCCESS;
+}
+
+/* For Emacs:
+ * Local Variables:
+ * mode:c
+ * indent-tabs-mode:t
+ * tab-width:4
+ * c-basic-offset:4
+ * End:
+ * For VIM:
+ * vim:set softtabstop=4 shiftwidth=4 tabstop=4
+ */
More information about the Freeswitch-svn
mailing list