1
0
Fork 0

added gprs-off command to mmsbox mm1 module

This commit is contained in:
bagyenda 2011-01-12 09:47:14 +00:00
parent fae80063f8
commit 9a7952d200
3 changed files with 34 additions and 2 deletions

View File

@ -1,3 +1,5 @@
2011-01-12 P. A. Bagyenda <bagyenda@dsmagic.com>
* Improved mmsbox mm1 module -- added gprs-off command for better customisation of gprs on/off sequence
2011-01-06 P. A. Bagyenda <bagyenda@dsmagic.com>
* More fixes for strip-prefixes -- now applies to sender address as well
2011-01-05 P. A. Bagyenda <bagyenda@dsmagic.com>

View File

@ -26,6 +26,7 @@ typedef struct {
Octstr *msisdn; /* my msisdn. */
Octstr *proxy; /* form is host:port. */
Octstr *gprs_on; /* Command to start GPRS link. Must not exit. */
Octstr *gprs_off; /* Command to stop GPRS link. */
Octstr *gprs_pid; /* command to call to get PID of GPRS for stopping GPRS link (i.e. pppd). */
Octstr *smsc_on; /* command to start smsc connection */
Octstr *smsc_off; /* commadn to stop smsc connection */
@ -57,6 +58,7 @@ typedef struct {
Octstr *error;
} MM1Request;
static void stop_gprs(Octstr *cmd);
static void handle_notify(MM1Settings *mm1);
static void handle_mm1(MM1Settings *mm1);
static int open_mm1(MmscGrp *mmc, MmsQueueHandlerFuncs *qfs,
@ -68,6 +70,7 @@ static int open_mm1(MmscGrp *mmc, MmsQueueHandlerFuncs *qfs,
Octstr *mmsc_url = NULL;
Octstr *proxy = NULL;
Octstr *gprs_on = NULL;
Octstr *gprs_off = NULL;
Octstr *gprs_pid = NULL;
Octstr *smsc_on = NULL;
Octstr *smsc_off = NULL;
@ -96,6 +99,8 @@ static int open_mm1(MmscGrp *mmc, MmsQueueHandlerFuncs *qfs,
proxy = value;
else if (octstr_str_case_compare(item, "gprs-on") == 0)
gprs_on = value;
else if (octstr_str_case_compare(item, "gprs-off") == 0)
gprs_off = value;
else if (octstr_str_case_compare(item, "gprs-pid") == 0)
gprs_pid = value;
else if (octstr_str_case_compare(item, "port") == 0) {
@ -129,6 +134,7 @@ static int open_mm1(MmscGrp *mmc, MmsQueueHandlerFuncs *qfs,
mm1->mmsc_url = mmsc_url;
mm1->proxy = proxy;
mm1->gprs_on = gprs_on;
mm1->gprs_off = gprs_off;
mm1->gprs_pid = gprs_pid;
mm1->smsc_on = smsc_on;
mm1->smsc_off = smsc_off;
@ -547,7 +553,10 @@ static void handle_mm1(MM1Settings *mm1)
}
if (pid > 0) { /* stop GPRS, restart SMSC connection. */
if (mm1->gprs_off) {
stop_gprs(mm1->gprs_off);
} else if (pid > 0) { /* stop GPRS, restart SMSC connection. */
int xkill, status;
pid_t wpid;
do {
@ -590,6 +599,7 @@ static int close_mm1(void *data)
octstr_destroy(s->msisdn);
octstr_destroy(s->proxy);
octstr_destroy(s->gprs_on);
octstr_destroy(s->gprs_off);
octstr_destroy(s->gprs_pid);
octstr_destroy(s->smsc_on);
octstr_destroy(s->smsc_off);
@ -669,6 +679,25 @@ static Octstr *fetch_content(Octstr *url, Octstr *proxy, Octstr *body, int *hsta
#include <unistd.h>
static void stop_gprs(Octstr *cmd)
{
pid_t pid = fork();
if (pid == 0) {
/* in child */
List *l = octstr_split_words(cmd);
int i, n = gwlist_len(l);
char **args = gw_malloc((n+1) * sizeof *args);
for (i = 0; i < n; i++) {
Octstr *x = gwlist_get(l, i);
args[i] = octstr_get_cstr(x);
printf("arg %d: %s\n", i, args[i]);
}
args[i] = NULL;
printf("Not reached: %d!", execvp(args[0], args));
}
}
#define MAX_GPRS_WAIT 80
#define GPRS_POLL 5
static long start_gprs(Octstr *cmd, Octstr *pid_cmd)

View File

@ -579,7 +579,8 @@ static void mmsbox_start_mmsc_conn(MmscGrp *m, List *errors, List *warnings)
{
if (m->type == CUSTOM_MMSC) {
if (m->fns == NULL ||
m->fns->start_conn(m, qfs, unified_prefix, strip_prefixes, &m->data) != 0) {
m->fns->start_conn(m, qfs, unified_prefix,
m->strip_prefixes ? m->strip_prefixes : strip_prefixes, &m->data) != 0) {
WARNING("MMSBox: Failed to start custom MMSC [%s]", octstr_get_cstr(m->id));
m->started = 0;
} else