HTTP Module

"Alejandro Guerrieri" <[email protected]>
Newsgroups gmane.comp.mobile.kannel.devel
Message-ID <[email protected]>
Dear List,

I've developed a couple of HTTP modules in the past, to accomodate to
third partie's particular requirements. Most of them are propietary
(their specs are particular to us) but we are talking with a couple of
them about releasing the module so other people can connect to them
using kannel.

Since most HTTP apis are asynchronous (one connection to us when a
message arrives and we establish a connection when we want to send a
message)wWe usually start from the "kannel" http module, change the
parameters and a few other things and we are done.

They work fine and we didn't experience any particular issues with them.

But now, a third party is asking us to use a "synchronous" connection.

I mean: The third party connect to us using an HTTP GET and we should
respond on the reply to _that_ request with a line of text containing
the message we want to send. Then their system sends the message to
the originating number.

I know it's an _horrible_ approach:

It has no queuing, retrying, validation nor failure detection.
We can only respond to messages originating from them.
We cannot know if there were any issues with the sending (since I
don't get a "Sent" response from them).

Anyway, it's what they've got and what they are asking to use, so our
hands are tied there.

The problem is _how_ to implement this in an HTTP module. Since kannel
uses an asynchronous approach, I don't know where to start.

AFAIK, when a message is injected from the HTTP interface, it arrives
at "kannel_receive_sms" and the message is put on the incoming queue
using "bb_smscconn_receive":

ret = bb_smscconn_receive(conn, msg);
if (ret == -1)
  retmsg = octstr_create("Not accepted");
else
  retmsg = octstr_create("Sent.");
}

And then the HTTP interface replies wit "Sent" or "Not accepted":

reply_headers = gwlist_create();
http_header_add(reply_headers, "Content-Type", "text/plain");
debug("smsc.http.kannel", 0, "HTTP[%s]: Sending reply",
octstr_get_cstr(conn->id));
http_send_reply(client, HTTP_ACCEPTED, reply_headers, retmsg);

At the end, cleanup is performed:
octstr_destroy(retmsg);
http_destroy_headers(reply_headers);

Later on, the message is picked on the smsbox, processed and the
response is processed on a separate thread.

The problem is, I'd need to respond _inmediately_ with the response on
the same HTTP connection. In other words, instead of "Sent" I'd need
to respond with the message I'd want to send.

Is that possible? What would be the best approach to do that? AFAIK it
would need to keep the HTTP connection open and waiting for the smsbox
to respond, but how could I do that?

I know I can do this easily from PHP or any scripting language, but
using kannel I can keep my routings (we have a _lot_ of them) on a
single place. Using PHP "glue" would mean we have to replicate all our
"sms-service" group logic outside kannel and I want to avoid that if I
can, since we many different regex-keywords on many short numbers
pointing to many apps and mantaining those settings on two different
places would be an daministrative nightmare.

Any hints about this would be appreciated.

Best regards,

--
Alejandro Guerrieri
Magicom
http://www.magicom-bcn.net/
LinkedIn: http://www.linkedin.com/in/aguerrieri
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.