Modified: freeswitch/branches/gmaruzz/mod_celliax/celliax_protocol.c (14684 => 14685)
--- 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)
@@ -4847,3 +4847,224 @@
}
return r;
}
+
+
+
+
+
+
+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;
+}
+
+
Modified: freeswitch/branches/gmaruzz/mod_celliax/mod_celliax.c (14684 => 14685)
--- 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)
@@ -91,6 +91,8 @@
SWITCH_STANDARD_API(celliax_function);
#define SKYPIAX_SYNTAX "interface_name skype_API_msg"
+SWITCH_STANDARD_API(sendsms_function);
+#define SENDSMS_SYNTAX "sendsms interface_name destination_number SMS_text"
/* BEGIN: Changes here */
#define FULL_RELOAD 0
#define SOFT_RELOAD 1
@@ -1637,8 +1639,9 @@
if (running) {
- 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, "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);
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
@@ -2169,7 +2172,59 @@
return SWITCH_STATUS_SUCCESS;
}
+SWITCH_STANDARD_API(sendsms_function)
+{
+ char *mycmd = NULL, *argv[3] = { 0 };
+ int argc = 0;
+ private_t *tech_pvt = NULL;
+ 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;
+}
+
+
#ifdef NOTDEF
int celliax_answer(private_t * tech_pvt, char *id, char *value)
{