/* * Mbuni - Open Source MMS Gateway * * Misc. functions * * 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) */ #ifndef __MMS_UTIL__INCLUDED__ #define __MMS_UTIL__INCLUDED__ #include "gwlib/gwlib.h" #include "gwlib/mime.h" #include "config.h" #include "mms_strings.h" #include "mms_msg.h" #include "mms_mm7soap.h" #include "mms_cfg.h" #include "mms_mmbox.h" /* Send errors */ #define MMS_SEND_OK 0 #define MMS_SEND_ERROR_TRANSIENT -1 #define MMS_SEND_ERROR_FATAL -2 #define SEND_ERROR_STR(e) ((e) == MMS_SEND_OK ? "Sent" : (e) == MMS_SEND_ERROR_TRANSIENT ? "Retry later" : "Failed") /* Useful headers. */ #define XMSISDN_HEADER "X-WAP-Network-Client-MSISDN" #define XIP_HEADER "X-WAP-Network-Client-IP" #define MM_NAME "Mbuni" #define EAIF_VERSION "3.0" /* used by mmbox and queue code -- directory stuff. */ #define _TT "0123456789abcdefghijklmnopqrstuvwxyz" #define _TTSIZE (-1 + sizeof _TT) /* Global variables and shared code used by all modules. */ #define MMSC_VERSION VERSION #define MMS_NAME PACKAGE /* Message location flags: Used to distinguish fetch-urls */ enum mms_loc_t {MMS_LOC_MMBOX = 1, MMS_LOC_MQUEUE=2}; extern int mms_load_core_settings(mCfgGrp *cgrp); extern Octstr *mms_maketransid(char *qf, Octstr *mmscname); extern Octstr *mms_getqf_fromtransid(Octstr *transid); extern Octstr *mms_isodate(time_t t); void mms_lib_init(void); void mms_lib_shutdown(void); /* get content type while stripping params. If any param is null, fails. */ int get_content_type(List *hdrs, Octstr **type, Octstr **params); /* Takes a header value, returns the value proper and any parameters... */ int split_header_value(Octstr *value, Octstr **base_value, Octstr **params); /* Returns a list of parameters as http_headers given the semi-comma delimited string.*/ List *get_value_parameters(Octstr *params); Octstr *make_value_parameters(List *params); /* Where value is comma-separated, make separate header items. */ void unpack_mimeheaders(MIMEEntity *m); /* Where element has base64 encoding, decode. */ void unbase64_mimeparts(MIMEEntity *m); /* Where element contains binary data, encode it base64. */ void base64_mimeparts(MIMEEntity *m); /* Send this message to email recipient: Returns 0 on success 1 or 2 on profile error * (negate to get right one), -ve on some other error */ int mms_sendtoemail(Octstr *from, Octstr *to, Octstr *subject, Octstr *msgid, MmsMsg *msg, int dlr, Octstr **error, char *sendmail_cmd, Octstr *myhostname, int trans_msg, int trans_smil, char *txt, char *html, int append_hostname); /* log to access log. */ void mms_log(char *logmsg, Octstr *from, List *to, int msize, Octstr *msgid, Octstr *acct, Octstr *viaproxy, char *interface, Octstr *ua, Octstr *mmboxloc); void mms_log2(char *logmsg, Octstr *from, Octstr *to, int msize, Octstr *msgid, Octstr *acct, Octstr *viaproxy, char *interface, Octstr *ua, Octstr *mmboxloc); /* * lockfile: tries to lock a file, returns 0 if success, errno (which could be +ve) otherwise. * we use flock() */ int mm_lockfile(int fd, char *fname, int shouldblock); /* Returns true if the character is printable or space */ int _mms_gw_isprint(int c); /* Special form of cfg_get which returns zero-length string when there is nothing. */ Octstr *_mms_cfg_getx(mCfgGrp *grp, Octstr *item); /* Get envelope data from message headers. */ void mms_collect_envdata_from_msgheaders(List *mh, List **xto, Octstr **subject, Octstr **otransid, time_t *expiryt, time_t *deliveryt, long default_msgexpiry); /* Simple hash function */ unsigned long _mshash(char *s); /* Tell us whether address is a phone number. */ int isphonenum(Octstr *s); /* Fixup an address: Add type, etc. */ void _mms_fixup_address(Octstr *address); /* Check that host is one of hosts in semi-colon separated list in host_list */ int is_allowed_host(Octstr *host, Octstr *host_list); /* escape (backlash) special shell characters. */ void escape_shell_chars(Octstr *str); /* Parse CGI variables out of a HTTP POST request. * This function understands both standard POST and enctype multipart/form-data * For the latter it puts the content type of each of the variables found into * cgivars_ctypes (as HTTPCGIVars where name is the field name and value is the content type) * cgivars argument is the cgivars as passed to us by http_accept_request. For GET * HTTP requests this is returned unchanged, otherwise it is augmented with the * variables found. */ int parse_cgivars(List *request_headers, Octstr *request_body, List **cgivars, List **cgivar_ctypes); /* Helper function: The gwlib func adds an additional MIME-Version header which is not ideal! */ List *_x_mime_entity_headers(MIMEEntity *m); /* get content-ID header, fix: WAP decoder may leave " at beginning */ Octstr *_x_get_content_id(List *headers); /* Remove the boundary element from a list of headers. */ void strip_boundary_element(List *headers, char *s); #define MAXQTRIES 100 #define BACKOFF_FACTOR 5*60 /* In seconds */ #define QUEUERUN_INTERVAL 1*60 /* 1 minutes. */ #define DEFAULT_EXPIRE 3600*24*7 /* One week */ #endif