/* * Mbuni - Open Source MMS Gateway * * MMS send: Inject message into queue for delivery. * * Copyright (C) 2003 - 2005, 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 #include #include #include "mms_queue.h" #include "mms_uaprof.h" #include "mms_util.h" #include "mms_mmbox.h" static Octstr *data; static Octstr *from; static List *to; static MmsMsg *m; static int savetommbox; Octstr *mmbox; static MmsBoxSettings *settings; static int find_own(int i, int argc, char *argv[]) { if (argv[i][1] == 'f') if (i + 1 < argc) { from = octstr_create(argv[i+1]); return 1; } else return -1; else if (argv[i][1] == 'b') { savetommbox = 1; return 0; } else if (argv[i][1] == 't') if (i + 1 < argc) { int j, m; List *l = octstr_split(octstr_create(argv[i+1]), octstr_imm(":")); for (j = 0, m = list_len(l); j < m; j++) list_append(to, list_get(l, j)); list_destroy(l, NULL); return 1; } else return -1; else if (argv[i][1] == 'm') if (i + 1 < argc) { int ch; data = octstr_read_file(argv[i+1]); /* try and detect if we are looking at plain text (mime-encoded) or binary encoded message. */ ch = octstr_get_char(data, 0); if (isprint(ch)) { MIMEEntity *mime = mime_octstr_to_entity(data); MmsMsg *mm = NULL; if (mime && (mm = mms_frommime(mime)) != NULL) { octstr_destroy(data); data = mms_tobinary(mm); } if (mime) mime_entity_destroy(mime); if (mm) mms_destroy(mm); } return 1; } else return -1; else return -1; } static Cfg *cfg; static List *proxyrelays; int main(int argc, char *argv[]) { Octstr *fname, *s; int cfidx; CfgGroup *grp; Octstr *log, *alog; long loglevel; int msize; if (argc < 2) return -1; mms_lib_init(); to = list_create(); srandom(time(NULL)); cfidx = get_and_set_debugs(argc, argv, find_own); if (argv[cfidx] == NULL) fname = octstr_imm("mmsc.conf"); else fname = octstr_create(argv[cfidx]); cfg = cfg_create(fname); if (cfg_read(cfg) == -1) panic(0, "Couldn't read configuration from '%s'.", octstr_get_cstr(fname)); octstr_destroy(fname); info(0, "----------------------------------------"); info(0, " MMSC Message sender runner version %s starting", MMSC_VERSION); grp = cfg_get_single_group(cfg, octstr_imm("core")); log = cfg_get(grp, octstr_imm("log-file")); if (log != NULL) { if (cfg_get_integer(&loglevel, grp, octstr_imm("log-level")) == -1) loglevel = 0; log_open(octstr_get_cstr(log), loglevel, GW_NON_EXCL); octstr_destroy(log); } /* Get access log and open it. */ alog = cfg_get(grp, octstr_imm("access-log")); if (alog) { alog_open(octstr_get_cstr(alog), 1, 1); octstr_destroy(alog); } /* Load proxy relays. */ proxyrelays = mms_proxy_relays(cfg); /* Load settings. */ settings = mms_load_mmsbox_settings(cfg); if (!settings) panic(0, "No global MMSC configuration!"); if (from == NULL || to == NULL) { error(0, "Sender and recipient addresses required!\n"); exit(-1); } mms_start_profile_engine(octstr_get_cstr(settings->ua_profile_cache_dir)); if (data) { m = mms_frombinary(data, from ? from : octstr_imm("anon@anon")); if (m) mms_msgdump(m,1); msize = octstr_len(data); } else msize = 0; if (!m) panic(0, "No Message supplied, or failed to decode binary data!"); s = mms_queue_add(from, to, NULL, NULL, NULL, NULL, time(NULL), time(NULL) + settings->default_msgexpiry, m, NULL, 0, octstr_get_cstr(settings->global_queuedir)); if (savetommbox) mmbox = mms_mmbox_addmsg(octstr_get_cstr(settings->mmbox_rootdir), octstr_get_cstr(from), m, NULL, octstr_imm("Sent")); mms_log("Received", from, to, msize, s, NULL, NULL, "mmssend",NULL,NULL); printf("Queued: %s, mmbox=%s\n", octstr_get_cstr(s), mmbox ? octstr_get_cstr(mmbox) : ""); octstr_destroy(s); return 0; }