<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[Freeswitch-trunk][14685] </title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<div id="header">FreeSWITCH Subversion</div>
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://fisheye.freeswitch.org/changelog/FreeSWITCH?cs=14685">14685</a></dd>
<dt>Author</dt> <dd>gmaruzz</dd>
<dt>Date</dt> <dd>2009-08-30 22:17:25 -0500 (Sun, 30 Aug 2009)</dd>
</dl>
<h3>Log Message</h3>
<pre>celliax: sendsms command</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#freeswitchbranchesgmaruzzmod_celliaxcelliaxh">freeswitch/branches/gmaruzz/mod_celliax/celliax.h</a></li>
<li><a href="#freeswitchbranchesgmaruzzmod_celliaxcelliax_protocolc">freeswitch/branches/gmaruzz/mod_celliax/celliax_protocol.c</a></li>
<li><a href="#freeswitchbranchesgmaruzzmod_celliaxmod_celliaxc">freeswitch/branches/gmaruzz/mod_celliax/mod_celliax.c</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="freeswitchbranchesgmaruzzmod_celliaxcelliaxh"></a>
<div class="modfile"><h4>Modified: freeswitch/branches/gmaruzz/mod_celliax/celliax.h (14684 => 14685)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/branches/gmaruzz/mod_celliax/celliax.h        2009-08-30 23:46:25 UTC (rev 14684)
+++ freeswitch/branches/gmaruzz/mod_celliax/celliax.h        2009-08-31 03:17:25 UTC (rev 14685)
</span><span class="lines">@@ -542,6 +542,7 @@
</span><span class="cx"> int celliax_hangup(private_t * tech_pvt);
</span><span class="cx"> int celliax_serial_call(private_t * tech_pvt, char *dstr);
</span><span class="cx"> int celliax_serial_call_AT(private_t * tech_pvt, char *dstr);
</span><ins>+int celliax_sendsms( private_t * tech_pvt, char * dest, char * text);
</ins><span class="cx">
</span><span class="cx"> #ifdef CELLIAX_ALSA
</span><span class="cx"> int alsa_init(private_t * tech_pvt);
</span></span></pre></div>
<a id="freeswitchbranchesgmaruzzmod_celliaxcelliax_protocolc"></a>
<div class="modfile"><h4>Modified: freeswitch/branches/gmaruzz/mod_celliax/celliax_protocol.c (14684 => 14685)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/branches/gmaruzz/mod_celliax/celliax_protocol.c        2009-08-30 23:46:25 UTC (rev 14684)
+++ freeswitch/branches/gmaruzz/mod_celliax/celliax_protocol.c        2009-08-31 03:17:25 UTC (rev 14685)
</span><span class="lines">@@ -4847,3 +4847,224 @@
</span><span class="cx">         }
</span><span class="cx">         return r;
</span><span class="cx"> }
</span><ins>+
+
+
+
+
+
+int celliax_sendsms( private_t * tech_pvt, char * dest, char * text)
+{
+ //char *idest = data;
+ //char rdest[256];
+ //struct celliax_pvt *p = NULL;
+ //char *device;
+ //char *dest;
+ //char *text;
+ //char *stringp = NULL;
+ //int found = 0;
+ int failed = 0;
+
+ //strncpy(rdest, idest, sizeof(rdest) - 1);
+ DEBUGA_SKYPE("CelliaxSendsms: dest=%s text=%s\n", SKYPIAX_P_LOG, dest, text);
+ DEBUGA_SKYPE("START\n", SKYPIAX_P_LOG);
+ /* we can use celliax_request to get the channel, but celliax_request would look for onowned channels, and probably we can send SMSs while a call is ongoing
+ *
+ */
+
+#if 0
+ stringp = rdest;
+ //device = strsep(&stringp, "/");
+ dest = strsep(&stringp, "|");
+ text = strsep(&stringp, "|");
+
+ if (!device) {
+ ERRORA(
+ "CelliaxSendsms app do not recognize '%s'. Requires a destination with slashes (interfacename/destinationnumber, TEXT)\n", SKYPIAX_P_LOG,
+ idest);
+ return -1;
+ }
+
+ if (!dest) {
+ ERRORA(
+ "CelliaxSendsms app do not recognize '%s'. Requires a destination with slashes (interfacename/destinationnumber, TEXT)\n", SKYPIAX_P_LOG,
+ idest);
+ return -1;
+ }
+
+ if (!text) {
+ ERRORA(
+ "CelliaxSendsms app do not recognize '%s'. Requires a destination with slashes (interfacename/destinationnumber, TEXT)\n", SKYPIAX_P_LOG,
+ idest);
+ return -1;
+ }
+
+ DEBUGA_SKYPE("interfacename:%s, destinationnumber:%s, text:%s\n", SKYPIAX_P_LOG, device, dest,
+ text);
+ /* lock the interfaces' list */
+ LOKKA(&celliax_iflock);
+ /* make a pointer to the first interface in the interfaces list */
+ p = celliax_iflist;
+ /* Search for the requested interface and verify if is unowned */
+ //TODO implement groups a la chan_zap
+ while (tech_pvt) {
+ size_t length = strlen(tech_pvt->name);
+ /* is this the requested interface? */
+ if (strncmp(device, tech_pvt->name, length) == 0) {
+ /* this is the requested interface! */
+ if (option_debug)
+ DEBUGA_SKYPE("FOUND! interfacename:%s, destinationnumber:%s, text:%s, tech_pvt->name=%s\n",
+ SKYPIAX_P_LOG, device, dest, text, tech_pvt->name);
+ found = 1;
+ break;
+
+ }
+ /* not yet found, next please */
+ p = tech_pvt->next;
+ }
+ /* unlock the interfaces' list */
+ UNLOCKA(&celliax_iflock);
+
+ if (!found) {
+ ERRORA( "Interface '%s' requested by CelliaxSendsms NOT FOUND\n", device);
+ return RESULT_FAILURE;
+ }
+
+#endif
+ if (tech_pvt->controldevprotocol != PROTOCOL_AT) {
+ ERRORA(", SKYPIAX_P_LOGCelliaxSendsms supports only AT command cellphones at the moment :-( !\n",
+ SKYPIAX_P_LOG);
+ return RESULT_FAILURE;
+ }
+
+ if (tech_pvt->controldevprotocol == PROTOCOL_AT) {
+ int err = 0;
+ char smscommand[16000];
+ memset(smscommand, '\0', sizeof(smscommand));
+
+ PUSHA_UNLOCKA(&tech_pvt->controldev_lock);
+ LOKKA(tech_pvt->controldev_lock);
+
+ if (tech_pvt->no_ucs2) {
+ sprintf(smscommand, "AT+CMGS=\"%s\"", dest); //TODO: support phones that only accept pdu mode
+ } else {
+ char dest2[1048];
+
+ err = celliax_serial_write_AT_ack(tech_pvt, "AT+CSCS=\"UCS2\"");
+ if (err) {
+ ERRORA
+ ("AT+CSCS=\"UCS2\" (set TE messages to ucs2) do not got OK from the phone\n",
+ SKYPIAX_P_LOG);
+ }
+
+ memset(dest2, '\0', sizeof(dest2));
+ utf_to_ucs2(tech_pvt, dest, strlen(dest), dest2, sizeof(dest2));
+ sprintf(smscommand, "AT+CMGS=\"%s\"", dest2); //TODO: support phones that only accept pdu mode
+ }
+ //TODO: support phones that only accept pdu mode
+ //TODO would be better to lock controldev here
+ err = celliax_serial_write_AT_noack(tech_pvt, smscommand);
+ if (err) {
+ ERRORA("Error sending SMS\n", SKYPIAX_P_LOG);
+ failed = 1;
+ goto uscita;
+ }
+ err = celliax_serial_AT_expect(tech_pvt, "> ", 0, 1); // wait 1.5s for the prompt, no crlf
+#if 1
+ if (err) {
+ DEBUGA_SKYPE
+ ("Error or timeout getting prompt '> ' for sending sms directly to the remote party. BTW, seems that we cannot do that with Motorola c350, so we'll write to cellphone memory, then send from memory\n",
+ SKYPIAX_P_LOG);
+
+ err = celliax_serial_write_AT_ack(tech_pvt, "ATE1"); //motorola (at least c350) do not echo the '>' prompt when in ATE0... go figure!!!!
+ if (err) {
+ ERRORA("Error activating echo from modem\n", SKYPIAX_P_LOG);
+ }
+ tech_pvt->at_cmgw[0] = '\0';
+ sprintf(smscommand, "AT+CMGW=\"%s\"", dest); //TODO: support phones that only accept pdu mode
+ err = celliax_serial_write_AT_noack(tech_pvt, smscommand);
+ if (err) {
+ ERRORA("Error writing SMS destination to the cellphone memory\n", SKYPIAX_P_LOG);
+ failed = 1;
+ goto uscita;
+ }
+ err = celliax_serial_AT_expect(tech_pvt, "> ", 0, 1); // wait 1.5s for the prompt, no crlf
+ if (err) {
+ ERRORA
+ ("Error or timeout getting prompt '> ' for writing sms text in cellphone memory\n",
+ SKYPIAX_P_LOG);
+ failed = 1;
+ goto uscita;
+ }
+ }
+#endif
+
+ //sprintf(text,"ciao 123 belè новости לק ראת ﺎﻠﺠﻤﻋﺓ 人大"); //let's test the beauty of utf
+ memset(smscommand, '\0', sizeof(smscommand));
+ if (tech_pvt->no_ucs2) {
+ sprintf(smscommand, "%s", text);
+ } else {
+ utf_to_ucs2(tech_pvt, text, strlen(text), smscommand, sizeof(smscommand));
+ }
+
+ smscommand[strlen(smscommand)] = 0x1A;
+ DEBUGA_SKYPE("smscommand len is: %d, text is:|||%s|||\n", SKYPIAX_P_LOG,
+ strlen(smscommand), smscommand);
+
+ err = celliax_serial_write_AT_ack_nocr_longtime(tech_pvt, smscommand);
+ //TODO would be better to unlock controldev here
+ if (err) {
+ ERRORA("Error writing SMS text to the cellphone memory\n", SKYPIAX_P_LOG);
+ //return RESULT_FAILURE;
+ failed = 1;
+ goto uscita;
+ }
+ if (tech_pvt->at_cmgw[0]) {
+ sprintf(smscommand, "AT+CMSS=%s", tech_pvt->at_cmgw);
+ err = celliax_serial_write_AT_expect_longtime(tech_pvt, smscommand, "OK");
+ if (err) {
+ ERRORA("Error sending SMS from the cellphone memory\n", SKYPIAX_P_LOG);
+ //return RESULT_FAILURE;
+ failed = 1;
+ goto uscita;
+ }
+
+ err = celliax_serial_write_AT_ack(tech_pvt, "ATE0"); //motorola (at least c350) do not echo the '>' prompt when in ATE0... go figure!!!!
+ if (err) {
+ ERRORA("Error de-activating echo from modem\n", SKYPIAX_P_LOG);
+ }
+ }
+ uscita:
+ usleep(1000);
+
+ if (tech_pvt->at_cmgw[0]) {
+
+ /* let's see what we've sent, just for check TODO: Motorola it's not reliable! Motorola c350 tells that all was sent, but is not true! It just sends how much it fits into one SMS FIXME: need an algorithm to calculate how many ucs2 chars fits into an SMS. It make difference based, probably, on the GSM alphabet translation, or so */
+ sprintf(smscommand, "AT+CMGR=%s", tech_pvt->at_cmgw);
+ err = celliax_serial_write_AT_ack(tech_pvt, smscommand);
+ if (err) {
+ ERRORA("Error reading SMS back from the cellphone memory\n", SKYPIAX_P_LOG);
+ }
+
+ /* let's delete from cellphone memory what we've sent */
+ sprintf(smscommand, "AT+CMGD=%s", tech_pvt->at_cmgw);
+ err = celliax_serial_write_AT_ack(tech_pvt, smscommand);
+ if (err) {
+ ERRORA("Error deleting SMS from the cellphone memory\n", SKYPIAX_P_LOG);
+ }
+
+ tech_pvt->at_cmgw[0] = '\0';
+ }
+ //usleep(500000); //.5 secs
+ UNLOCKA(tech_pvt->controldev_lock);
+ POPPA_UNLOCKA(&tech_pvt->controldev_lock);
+ }
+
+ DEBUGA_SKYPE("FINISH\n", SKYPIAX_P_LOG);
+ if (failed)
+ return -1;
+ else
+ return RESULT_SUCCESS;
+}
+
+
</ins></span></pre></div>
<a id="freeswitchbranchesgmaruzzmod_celliaxmod_celliaxc"></a>
<div class="modfile"><h4>Modified: freeswitch/branches/gmaruzz/mod_celliax/mod_celliax.c (14684 => 14685)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/branches/gmaruzz/mod_celliax/mod_celliax.c        2009-08-30 23:46:25 UTC (rev 14684)
+++ freeswitch/branches/gmaruzz/mod_celliax/mod_celliax.c        2009-08-31 03:17:25 UTC (rev 14685)
</span><span class="lines">@@ -91,6 +91,8 @@
</span><span class="cx"> SWITCH_STANDARD_API(celliax_function);
</span><span class="cx"> #define SKYPIAX_SYNTAX "interface_name skype_API_msg"
</span><span class="cx">
</span><ins>+SWITCH_STANDARD_API(sendsms_function);
+#define SENDSMS_SYNTAX "sendsms interface_name destination_number SMS_text"
</ins><span class="cx"> /* BEGIN: Changes here */
</span><span class="cx"> #define FULL_RELOAD 0
</span><span class="cx"> #define SOFT_RELOAD 1
</span><span class="lines">@@ -1637,8 +1639,9 @@
</span><span class="cx">
</span><span class="cx">         if (running) {
</span><span class="cx">
</span><del>-                SWITCH_ADD_API(commands_api_interface, "sk", "Skypiax console commands", sk_function, SK_SYNTAX);
-                SWITCH_ADD_API(commands_api_interface, "celliax", "Skypiax interface commands", celliax_function, SKYPIAX_SYNTAX);
</del><ins>+                //SWITCH_ADD_API(commands_api_interface, "sk", "Skypiax console commands", sk_function, SK_SYNTAX);
+                //SWITCH_ADD_API(commands_api_interface, "celliax", "Skypiax interface commands", celliax_function, SKYPIAX_SYNTAX);
+                SWITCH_ADD_API(commands_api_interface, "sendsms", "sendsms interface destination_number SMS_text", sendsms_function, SKYPIAX_SYNTAX);
</ins><span class="cx">
</span><span class="cx">                 /* indicate that the module should continue to be loaded */
</span><span class="cx">                 return SWITCH_STATUS_SUCCESS;
</span><span class="lines">@@ -2169,7 +2172,59 @@
</span><span class="cx">
</span><span class="cx">         return SWITCH_STATUS_SUCCESS;
</span><span class="cx"> }
</span><ins>+SWITCH_STANDARD_API(sendsms_function)
+{
+        char *mycmd = NULL, *argv[3] = { 0 };
+        int argc = 0;
+        private_t *tech_pvt = NULL;
</ins><span class="cx">
</span><ins>+        if (!switch_strlen_zero(cmd) && (mycmd = strdup(cmd))) {
+                argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
+        }
+
+        if (!argc) {
+                stream->write_function(stream, "ERROR, usage: %s", SENDSMS_SYNTAX);
+                goto end;
+        }
+
+        if (argc < 3) {
+                stream->write_function(stream, "ERROR, usage: %s", SENDSMS_SYNTAX);
+                goto end;
+        }
+
+        if (argv[0]) {
+                int i;
+                int found = 0;
+
+                for (i = 0; !found && i < SKYPIAX_MAX_INTERFACES; i++) {
+                        /* we've been asked for a normal interface name, or we have not found idle interfaces to serve as the "ANY" interface */
+                        if (strlen(globals.SKYPIAX_INTERFACES[i].name)
+                                && (strncmp(globals.SKYPIAX_INTERFACES[i].name, argv[0], strlen(argv[0])) == 0)) {
+                                tech_pvt = &globals.SKYPIAX_INTERFACES[i];
+                                stream->write_function(stream, "Trying to send your SMS: interface=%s, dest=%s, text=%s\n", argv[0], argv[1], argv[2]);
+                                found = 1;
+                                break;
+                        }
+
+                }
+                if (!found) {
+                        stream->write_function(stream, "ERROR: A Skypiax interface with name='%s' was not found\n", argv[0]);
+                        switch_safe_free(mycmd);
+
+                        return SWITCH_STATUS_SUCCESS;
+                } else {
+                        celliax_sendsms(tech_pvt, (char *) argv[1], (char *) argv[2]);
+                }
+        } else {
+                stream->write_function(stream, "ERROR, usage: %s", SENDSMS_SYNTAX);
+        }
+ end:
+        switch_safe_free(mycmd);
+
+        return SWITCH_STATUS_SUCCESS;
+}
+
+
</ins><span class="cx"> #ifdef NOTDEF
</span><span class="cx"> int celliax_answer(private_t * tech_pvt, char *id, char *value)
</span><span class="cx"> {
</span></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>
</body>
</html>