1
0
Fork 0
mbuni/mbuni/mmsc/mmssend.c

177 lines
4.5 KiB
C
Raw Normal View History

2005-03-23 05:55:16 +00:00
/*
* 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 <bagyenda@dsmagic.com>
*
* This program is free software, distributed under the terms of
* the GNU General Public License, with a few exceptions granted (see LICENSE)
*/
2005-03-10 08:01:02 +00:00
#include <stdio.h>
#include <unistd.h>
2005-03-21 16:11:51 +00:00
#include <ctype.h>
2005-03-10 08:01:02 +00:00
#include "mms_queue.h"
#include "mms_uaprof.h"
#include "mms_util.h"
#include "mms_mmbox.h"
2005-03-10 08:01:02 +00:00
static Octstr *data;
static Octstr *from;
static List *to;
static MmsMsg *m;
static int savetommbox;
Octstr *mmbox;
2005-03-10 08:01:02 +00:00
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')
2005-03-10 08:01:02 +00:00
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;
2005-03-10 08:01:02 +00:00
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);
2005-03-21 16:11:51 +00:00
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);
}
2005-03-10 08:01:02 +00:00
return 1;
} else
return -1;
2005-03-10 08:01:02 +00:00
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)
2005-03-21 16:11:51 +00:00
mms_msgdump(m,1);
2005-03-10 08:01:02 +00:00
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),
2005-03-21 16:11:51 +00:00
octstr_get_cstr(from), m, NULL, octstr_imm("Sent"));
2005-03-10 08:01:02 +00:00
2005-03-21 16:11:51 +00:00
mms_log("Received", from, to, msize, s, NULL, NULL, "mmssend",NULL,NULL);
2005-03-10 08:01:02 +00:00
printf("Queued: %s, mmbox=%s\n",
octstr_get_cstr(s), mmbox ? octstr_get_cstr(mmbox) : "");
2005-03-10 08:01:02 +00:00
octstr_destroy(s);
return 0;
}