diff --git a/mbuni/ChangeLog b/mbuni/ChangeLog index d44f812..3cc394c 100644 --- a/mbuni/ChangeLog +++ b/mbuni/ChangeLog @@ -1,3 +1,5 @@ +2008-09-01 P. A. Bagyenda + * Rolled mmsrelay + mmsproxy into one item (for easier online management) 2008-08-29 P. A. Bagyenda * Changes to doc for config from DLL * Misc. code re-ordering for mmsbox diff --git a/mbuni/extras/pgsql-queue/mms_pgsql_queue.c b/mbuni/extras/pgsql-queue/mms_pgsql_queue.c index 5fe32d8..94600be 100644 --- a/mbuni/extras/pgsql-queue/mms_pgsql_queue.c +++ b/mbuni/extras/pgsql-queue/mms_pgsql_queue.c @@ -27,23 +27,15 @@ static List *free_conns; static int pool_size; static int pgq_init_module(Octstr *conninfo, int max_threads) { - long i, n = 0; + long i, n; gw_assert(conninfo); - i = octstr_search_char(conninfo,':', 0); - if (i>0) { - n = strtoul(octstr_get_cstr(conninfo), NULL, 10); - octstr_delete(conninfo, 0, i+1); - } + + n = max_threads + 1; if (n <= 0) n = DEFAULT_CONNECTIONS; - else if (n <= max_threads * 4) { /* must all each thread up to 2 connections, and then some.*/ - - n = max_threads*4 + 1; - - info(0, "pgsql_queue_init: Forced number of DB connections to %d", (int)n); - } + info(0, "pgsql_queue_init: Number of DB connections set to %d", (int)n); free_conns = gwlist_create(); gwlist_add_producer(free_conns); for (i = 0; imms_init_queue_module(gdir, maxthreads); + qfs->mms_init_queue_module(gdir, (2 + 1)*maxthreads); /* We expect 2 each for each mmsbox thread, + * one each for each bearerbox thread. + */ } else { Octstr *s = _mms_cfg_getx(cfg, grp, octstr_imm("queue-module-init-data")); - if (qfs->mms_init_queue_module(s, maxthreads) != 0) + if (qfs->mms_init_queue_module(s, (2+1)*maxthreads) != 0) panic(0, "failed to initialise queue module, with data: %s", octstr_get_cstr(s)); octstr_destroy(s); diff --git a/mbuni/mmsc/Makefile.am b/mbuni/mmsc/Makefile.am index e6eb9b5..e916bf6 100644 --- a/mbuni/mmsc/Makefile.am +++ b/mbuni/mmsc/Makefile.am @@ -4,10 +4,9 @@ libmmsc = libmmsc.a noinst_LIBRARIES = libmmsc.a libmmsc_a_SOURCES = mmsc_cfg.c mms_detokenize.c mms_resolve.c mms_billing.c mms_detokenize_shell.c mms_resolve_shell.c mms_billing_shell.c -bin_PROGRAMS = mmsrelay mmsproxy mmsfromemail mmssend -mmsrelay_SOURCES = mmsglobalsender.c mmsmobilesender.c mmsrelay.c -mmsrelay_LDADD = $(libmmsc) $(libmms) -mmsproxy_LDADD = $(libmmsc) $(libmms) +bin_PROGRAMS = mmsc mmsfromemail mmssend +mmsc_SOURCES = mmsc.c mmsglobalsender.c mmsmobilesender.c mmsrelay.c mmsproxy.c +mmsc_LDADD = $(libmmsc) $(libmms) mmsfromemail_LDADD = $(libmmsc) $(libmms) mmssend_LDADD = $(libmmsc) $(libmms) diff --git a/mbuni/mmsc/mmsc.c b/mbuni/mmsc/mmsc.c new file mode 100644 index 0000000..e8aad29 --- /dev/null +++ b/mbuni/mmsc/mmsc.c @@ -0,0 +1,98 @@ +/* + * Mbuni - Open Source MMS Gateway + * + * MMSC: Full MMSC startup + * + * Copyright (C) 2003 - 2008, Digital Solutions Ltd. - http://www.dsmagic.com + * + * Paul Bagyenda + * + * This program is free software, distributed under the terms of + * the GNU General Public License, with a few exceptions granted (see LICENSE) + */ + +#include "mmsc.h" +#include "mms_uaprof.h" + +static mCfg *cfg; +MmscSettings *settings; +List *proxyrelays; + + +static void quit_now(int notused) +{ + stop_mmsrelay(); + stop_mmsproxy(); +} + +/* manage the SIGHUP signal */ +static void relog_now(int notused) +{ + warning(0, "SIGHUP received, catching and re-opening logs"); + log_reopen(); + alog_reopen(); +} + +int main(int argc, char *argv[]) +{ + int cfidx; + Octstr *fname; + + long r_thread = 0; + + mms_lib_init(); + + srandom(time(NULL)); + + cfidx = get_and_set_debugs(argc, argv, NULL); + + if (argv[cfidx] == NULL) + fname = octstr_imm("mbuni.conf"); + else + fname = octstr_create(argv[cfidx]); + + cfg = mms_cfg_read(fname); + + if (cfg == NULL) + panic(0, "Couldn't read configuration from '%s'.", octstr_get_cstr(fname)); + + octstr_destroy(fname); + + info(0, "----------------------------------------"); + info(0, " " MM_NAME " MMSC version %s starting", MMSC_VERSION); + + + settings = mms_load_mmsc_settings(cfg,&proxyrelays); + + mms_cfg_destroy(cfg); + + if (!settings) + panic(0, "No global MMSC configuration!"); + + + signal(SIGHUP, relog_now); + signal(SIGTERM, quit_now); + signal(SIGPIPE,SIG_IGN); /* Ignore pipe errors. They kill us sometimes for nothing*/ + + + if ((r_thread = gwthread_create((gwthread_func_t *)mmsrelay, NULL)) < 0) + panic(0, "Failed to start MMSC Relay component!"); + + if (mmsproxy() < 0) + panic(0, "Failed to start MMSC Relay component!"); + + /* We are done. Cleanup. */ + + info(0, "MMSC shutdown commenced."); + + gwthread_join(r_thread); + + sleep(2); /* Wait for them to die. */ + info(0, "Final cleanup..."); + mms_cleanup_mmsc_settings(settings); /* Stop settings stuff and so on. */ + + info(0, "Shutdown complete..."); + mms_lib_shutdown(); + + return 0; +} diff --git a/mbuni/mmsc/mmsrelay.h b/mbuni/mmsc/mmsc.h similarity index 67% rename from mbuni/mmsc/mmsrelay.h rename to mbuni/mmsc/mmsc.h index 12fa72c..3580400 100644 --- a/mbuni/mmsc/mmsrelay.h +++ b/mbuni/mmsc/mmsc.h @@ -1,9 +1,7 @@ -#ifndef __MMSRELAY_INCLUDED__ -#define __MMSRELAY_INCLUDED__ /* * Mbuni - Open Source MMS Gateway * - * MMS Relay, implements message routing + * MMSC: Full MMSC startup * * Copyright (C) 2003 - 2008, Digital Solutions Ltd. - http://www.dsmagic.com * @@ -12,17 +10,21 @@ * This program is free software, distributed under the terms of * the GNU General Public License, with a few exceptions granted (see LICENSE) */ -#include -#include -#include -#include -#include "mms_queue.h" -#include "mms_uaprof.h" +#ifndef __MBUNI_MMSC_INCLUDED__ +#define __MBUNI_MMSC_INCLUDED__ #include "mmsc_cfg.h" -#include "mms_mm7soap.h" + +int mmsproxy(void); +void stop_mmsproxy(void); + +int mmsrelay(void); +int stop_mmsrelay(void); + extern void mbuni_global_queue_runner(int *stopflag); extern void mbuni_mm1_queue_runner(int *stopflag); extern MmscSettings *settings; extern List *proxyrelays; + + #endif diff --git a/mbuni/mmsc/mmsc_cfg.c b/mbuni/mmsc/mmsc_cfg.c index f4fb2cd..a9f0c7a 100644 --- a/mbuni/mmsc/mmsc_cfg.c +++ b/mbuni/mmsc/mmsc_cfg.c @@ -94,10 +94,12 @@ MmscSettings *mms_load_mmsc_settings(mCfg *cfg, List **proxyrelays) if ((m->qfs = _mms_load_module(cfg, grp, "queue-manager-module", "qfuncs", NULL)) == NULL) { m->qfs = &default_qfuncs; /* default queue handler. */ - m->qfs->mms_init_queue_module(qdir, m->maxthreads); + m->qfs->mms_init_queue_module(qdir, (2 + 2 + 2)*m->maxthreads); /* We expect 2 max for each mmsrelay component (= 4) + * + 2 for mmsproxy (on for mm1proxy, one for mm7proxy + */ } else { Octstr *s = _mms_cfg_getx(cfg, grp, octstr_imm("queue-module-init-data")); - if (m->qfs->mms_init_queue_module(s, m->maxthreads) != 0) + if (m->qfs->mms_init_queue_module(s, (2 + 2 + 2)*m->maxthreads) != 0) panic(0, "failed to initialise queue module, with data: %s", octstr_get_cstr(s)); octstr_destroy(s); diff --git a/mbuni/mmsc/mmsglobalsender.c b/mbuni/mmsc/mmsglobalsender.c index c4ac15d..925e3f4 100644 --- a/mbuni/mmsc/mmsglobalsender.c +++ b/mbuni/mmsc/mmsglobalsender.c @@ -11,7 +11,7 @@ * the GNU General Public License, with a few exceptions granted (see LICENSE) */ -#include "mmsrelay.h" +#include "mmsc.h" #define NMAX 256 static char mobile_qdir[NMAX]; diff --git a/mbuni/mmsc/mmsmobilesender.c b/mbuni/mmsc/mmsmobilesender.c index 339f132..6dc53e4 100644 --- a/mbuni/mmsc/mmsmobilesender.c +++ b/mbuni/mmsc/mmsmobilesender.c @@ -11,7 +11,7 @@ * This program is free software, distributed under the terms of * the GNU General Public License, with a few exceptions granted (see LICENSE) */ -#include "mmsrelay.h" +#include "mmsc.h" #include #include diff --git a/mbuni/mmsc/mmsproxy.c b/mbuni/mmsc/mmsproxy.c index 07660ea..1c9b73a 100644 --- a/mbuni/mmsc/mmsproxy.c +++ b/mbuni/mmsc/mmsproxy.c @@ -21,6 +21,7 @@ #include "mms_uaprof.h" #include "mmsc_cfg.h" #include "mms_mm7soap.h" +#include "mmsc.h" #define MAX_MESSAGE_SIZE 100*1024 @@ -28,115 +29,41 @@ typedef struct MmsHTTPClientInfo { HTTPClient *client; Octstr *ua; Octstr *ip; - List *headers; + List *headers; Octstr *url; Octstr *body; - List *cgivars; + List *cgivars; Octstr *profile_url; Octstr *base_client_addr; Octstr *client_addr; MmsVasp *vasp; } MmsHTTPClientInfo; -static mCfg *cfg; -static List *proxyrelays; -static MmscSettings *settings; - +static long mm7_thread = -1; static int rstop = 0; -static void quit_now(int notused) -{ - rstop = 1; - if (settings) { - http_close_port(settings->port); - http_close_port(settings->mm7port); - } -} - -/* manage the SIGHUP signal */ -static void relog_now(int notused) -{ - warning(0, "SIGHUP received, catching and re-opening logs"); - log_reopen(); - alog_reopen(); -} static void free_clientInfo(MmsHTTPClientInfo *h, int freeh); static void fetchmms_proxy(MmsHTTPClientInfo *h); static void sendmms_proxy(MmsHTTPClientInfo *h); static void mm7proxy(void *unused); -int main(int argc, char *argv[]) -{ - int cfidx; - Octstr *fname; +static void mm1proxy(void) +{ MmsHTTPClientInfo h = {NULL}; - long mm7_thread = -1; - - mms_lib_init(); - srandom(time(NULL)); - - cfidx = get_and_set_debugs(argc, argv, NULL); - - if (argv[cfidx] == NULL) - fname = octstr_imm("mmsc.conf"); - else - fname = octstr_create(argv[cfidx]); - - cfg = mms_cfg_read(fname); - - if (cfg == NULL) - panic(0, "Couldn't read configuration from '%s'.", octstr_get_cstr(fname)); - - octstr_destroy(fname); - - info(0, "----------------------------------------"); - info(0, " " MM_NAME " MMSC Proxy version %s starting", MMSC_VERSION); - - - /* Load settings. */ - settings = mms_load_mmsc_settings(cfg, &proxyrelays); - - mms_cfg_destroy(cfg); - - if (!settings) - panic(0, "No global MMSC configuration!"); - - - signal(SIGHUP, relog_now); - signal(SIGTERM, quit_now); - - /* Start cache engine. */ - mms_start_profile_engine(octstr_get_cstr(settings->ua_profile_cache_dir)); - - /* If we have mm7 port, start thread for it. */ - /* Now open port and start dispatching requests. */ - - if (http_open_port(settings->port, 0) < 0) { - error(0, "MMS Proxy: Failed to start http server: %d => %s!", - errno, strerror(errno)); - goto done; - } - - if (settings->mm7port > 0 && - http_open_port(settings->mm7port, 0) >= 0) - mm7_thread = gwthread_create((gwthread_func_t *)mm7proxy, NULL); - else - warning(0, "MMS Proxy: MM7 interface not open, port=%ld", - settings->mm7port); while(rstop == 0 && (h.client = http_accept_request(settings->port, - &h.ip, &h.url, &h.headers, - &h.body, &h.cgivars)) != NULL) + &h.ip, &h.url, &h.headers, + &h.body, &h.cgivars)) != NULL) if (is_allowed_ip(settings->allow_ip, settings->deny_ip, h.ip)) { MmsHTTPClientInfo *hx = gw_malloc(sizeof *hx); - + h.vasp = NULL; h.profile_url = NULL; h.ua = http_header_value(h.headers, octstr_imm("User-Agent")); - + /* Get the profile URL and store it. Has effect of fetching if missing. */ if ((h.profile_url = http_header_value(h.headers, octstr_imm("X-Wap-Profile"))) == NULL) @@ -227,26 +154,56 @@ int main(int argc, char *argv[]) free_clientInfo(&h, 0); } - done: - debug("proxy", 0, "MM1 Shutting down..."); + info(0, "Mmsproxy [mm1]: Shutdown commenced..."); + +} - http_close_all_ports(); - debug("proxy", 0, "Port closed"); +int mmsproxy(void) +{ - mms_stop_profile_engine(); + info(0, " " MM_NAME " MMSC Proxy version %s starting", MMSC_VERSION); + mms_start_profile_engine(octstr_get_cstr(settings->ua_profile_cache_dir)); + + /* If we have mm7 port, start thread for it. */ + /* Now open port and start dispatching requests. */ - mms_cleanup_mmsc_settings(settings); - sleep(2); /* Give them time to shut down. */ + if (http_open_port(settings->port, 0) < 0) { + error(0, "MMS Proxy: Failed to start http server: %d => %s!", + errno, strerror(errno)); + return -1; + } - if (mm7_thread >= 0) + if (settings->mm7port > 0 && + http_open_port(settings->mm7port, 0) >= 0) + mm7_thread = gwthread_create((gwthread_func_t *)mm7proxy, NULL); + else + warning(0, "MMS Proxy: MM7 interface not open, port=%ld", + settings->mm7port); + + mm1proxy(); /* run mm1 proxy in current thread. */ + if (mm7_thread >0) gwthread_join(mm7_thread); - info(0, "mmsproxy: Shutdown complete"); - mms_lib_shutdown(); + + info(0, "Stopping profile engine..."); + mms_stop_profile_engine(); /* Stop profile stuff. */ + + info(0, "Mmsproxy: Shutdown complete."); return 0; } +void stop_mmsproxy(void) +{ + info(0, "Mmsproxy: Shutdown commenced..."); + rstop = 1; + + http_close_port(settings->port); + http_close_port(settings->mm7port); + + info(0, "Mmsproxy: Signalling shutdown complete."); +} + void fetchmms_proxy(MmsHTTPClientInfo *h) { Octstr *dlr_flag = NULL; @@ -1896,8 +1853,7 @@ static void mm7eaif_dispatch(MmsHTTPClientInfo *h) static void mm7proxy(void *unused) { MmsHTTPClientInfo h = {NULL}; - while(rstop == 0 && - (h.client = http_accept_request(settings->mm7port, + while(rstop == 0 && (h.client = http_accept_request(settings->mm7port, &h.ip, &h.url, &h.headers, &h.body, &h.cgivars)) != NULL) if (is_allowed_ip(settings->allow_ip, settings->deny_ip, h.ip)) { diff --git a/mbuni/mmsc/mmsrelay.c b/mbuni/mmsc/mmsrelay.c index 5fe0d14..04e0619 100644 --- a/mbuni/mmsc/mmsrelay.c +++ b/mbuni/mmsc/mmsrelay.c @@ -10,99 +10,40 @@ * This program is free software, distributed under the terms of * the GNU General Public License, with a few exceptions granted (see LICENSE) */ -#include "mmsrelay.h" +#include "mmsc.h" -static mCfg *cfg; -MmscSettings *settings; -List *proxyrelays; +static long qthread = -1; static int rstop = 0; /* Set to 1 to stop relay. */ -static void quit_now(int notused) + +int mmsrelay() { - rstop = 1; -} -/* manage the SIGHUP signal */ -static void relog_now(int notused) -{ - warning(0, "SIGHUP received, catching and re-opening logs"); - log_reopen(); - alog_reopen(); -} - -int main(int argc, char *argv[]) -{ - int cfidx; - Octstr *fname; - - long qthread = 0; - - mms_lib_init(); - - srandom(time(NULL)); - - cfidx = get_and_set_debugs(argc, argv, NULL); - - if (argv[cfidx] == NULL) - fname = octstr_imm("mbuni.conf"); - else - fname = octstr_create(argv[cfidx]); - - cfg = mms_cfg_read(fname); - - if (cfg == NULL) - panic(0, "Couldn't read configuration from '%s'.", octstr_get_cstr(fname)); - - octstr_destroy(fname); - - info(0, "----------------------------------------"); info(0, " " MM_NAME " MMSC Relay version %s starting", MMSC_VERSION); - - settings = mms_load_mmsc_settings(cfg,&proxyrelays); - - mms_cfg_destroy(cfg); - - if (!settings) - panic(0, "No global MMSC configuration!"); - -#if 0 - mms_start_profile_engine(octstr_get_cstr(settings->ua_profile_cache_dir)); -#endif - - signal(SIGHUP, relog_now); - signal(SIGTERM, quit_now); - signal(SIGPIPE,SIG_IGN); /* Ignore pipe errors. They kill us sometimes for nothing*/ - - /* Start global queue runner. */ info(0, "Starting Global Queue Runner..."); qthread = gwthread_create((gwthread_func_t *)mbuni_global_queue_runner, &rstop); - - + /* Start the local queue runner. */ info(0, "Starting Local Queue Runner..."); mbuni_mm1_queue_runner(&rstop); - /* gwthread_cancel(qthread); force it to die if not yet dead. */ - - /* It terminates, so start dying... */ - info(0, "Stopping profile engine..."); - mms_stop_profile_engine(); /* Stop profile stuff. */ - - sleep(2); /* Wait for them to die. */ - info(0, "Final cleanup..."); - mms_cleanup_mmsc_settings(settings); /* Stop settings stuff and so on. */ - - info(0, "Queue runners shutdown, cleanup commenced..."); gwthread_join(qthread); /* Wait for it to die... */ + info(0, "MMSC Relay MM1 queue runner terminates..."); + return 0; + +} - info(0, "Shutdown complete..."); - mms_lib_shutdown(); +int stop_mmsrelay(void) +{ + rstop = 1; + info(0, "Mmsrelay: Queue runners shutdown, cleanup commenced..."); return 0; }; +