1
0
Fork 0

Misc. additions

master
bagyenda 12 years ago
parent e7b5faee07
commit f67330f9e0

@ -1,3 +1,8 @@
2011-09-08 P. A. Bagyenda <bagyenda@dsmagic.com>
* Exposed more functions in lib (get_stripped_param_value)
* Minor changes to mms_msg module
2011-08-29 P. A. Bagyenda <bagyenda@dsmagic.com>
* Added mygw_free func utility for use in gwlist_destroy and such
2011-07-27 P. A. Bagyenda <bagyenda@dsmagic.com>
* Fixed UAProf timestamp bug
2011-05-30 P. A. Bagyenda <bagyenda@dsmagic.com>

@ -308,6 +308,26 @@ static int mk_data_file(int64_t qid, char *loc, char *dir, char out[])
return 0;
}
static Octstr *get_bytea(PGresult *r, int row, int col)
{
size_t dlen = PQgetlength(r, row, col);
char *s = PQgetvalue(r, row, col);
Octstr *out = octstr_create("");
if (s && s[0] == '\\' && s[1] == 'x')
octstr_append_from_hex(out, s + 2);
else if (s && (isprint(s[0]) || isspace(s[0]) || s[0] == '\\')) {
char *x = (void *)PQunescapeBytea((void *)s, &dlen);
octstr_append_data(out, x, dlen);
PQfreemem(x);
} else if (s)
octstr_append_data(out, s, dlen);
return out;
}
static int pgq_free_envelope(MmsEnvelope *e, int removefromqueue)
{
int ret = 0;
@ -423,7 +443,8 @@ static MmsEnvelope *pgq_queue_readenvelope_ex(char *qf, char *mms_queuedir, int
char cmd[4*QFNAMEMAX];
char data_file[4*QFNAMEMAX+1];
Octstr *from = NULL;
Octstr *data;
MmsEnvelope *e = NULL;
struct pgfile_t *pgs;
@ -496,14 +517,18 @@ static MmsEnvelope *pgq_queue_readenvelope_ex(char *qf, char *mms_queuedir, int
* If you use inline binary MMS storage, this will cause a bit of a slowdown.
* But you don't want to store binary MMS inline anyway because that is slow...
*/
if ((s = PQgetvalue(r, 0, PQfnumber(r, "data"))) != NULL &&
s[0] == '@')
data = get_bytea(r, 0, PQfnumber(r,"data"));
s = data ? octstr_get_cstr(data) : NULL;
if (s != NULL && s[0] == '@')
strncpy(data_file, s+1, sizeof data_file);
else
data_file[0] = 0; /* nada */
PQclear(r);
octstr_destroy(data);
sprintf(cmd, "SELECT item,value,id FROM mms_message_headers WHERE qid=%lld FOR UPDATE", qid);
r = PQexec(c, cmd);
@ -1060,8 +1085,8 @@ static MmsMsg *pgq_queue_getdata(MmsEnvelope *e)
if (qfs->data_file[0])
ms = octstr_read_file(qfs->data_file);
else {
size_t dlen, n;
char cmd[512], *data, *x;
size_t n;
char cmd[512];
PGresult *r;
sprintf(cmd, "SELECT data from mms_messages WHERE id = %lld", qfs->qid);
@ -1073,18 +1098,8 @@ static MmsMsg *pgq_queue_getdata(MmsEnvelope *e)
mms_error(0, "pgsql_queue", NULL, "mms_queue_getdata: Failed to load data for queue entry %s in %s",
e->xqfname, qfs->dir);
return NULL;
}
x = PQgetvalue(r, 0, 0);
if (x && (isprint(x[0]) || x[0] == '\\')) {/* data was sent to us escapaed, so un-escape it. */
data = (void *)PQunescapeBytea((void *)x, &dlen);
} else {
dlen = PQgetlength(r, 0, 0); /* get data length before you fetch it. */
data = x;
}
ms = octstr_create_from_data(data, dlen);
if (x != data) PQfreemem(data);
}
ms = get_bytea(r, 0, PQfnumber(r, "data"));
PQclear(r);
}

@ -73,29 +73,33 @@ static void encode_uint(Octstr *os, unsigned int l)
}
#endif
int mms_validate_address(Octstr *s)
int mms_validate_address_real(Octstr *s, enum AddressType_t *atype)
{
int i;
int l;
enum AddressType_t xtype;
if (atype == NULL)
atype = &xtype;
*atype = MMS_UNKNOWN_ADDRESS;
if (s == NULL)
return -1;
i = octstr_search_char(s, '/', 0);
l = octstr_len(s);
if (octstr_search_char(s, '@', 0) > 0)
return 0;
else if (i >= 0)
if (octstr_case_search(s, octstr_imm("PLMN"), 0) + 4 == l ||
octstr_case_search(s, octstr_imm("IPv4"), 0) + 4 == l ||
octstr_case_search(s, octstr_imm("IPv6"), 0) + 4 == l)
return 0;
else
return -1;
else
return -1;
if (octstr_search_char(s, '@', 0) > 0)
*atype = MMS_EMAIL_ADDRESS;
else if (i >= 0) {
if (octstr_case_search(s, octstr_imm("PLMN"), 0) + 4 == l)
*atype = MMS_NUMBER_ADDRESS;
else if (octstr_case_search(s, octstr_imm("IPv4"), 0) + 4 == l)
*atype = MMS_IPV4_ADDRESS;
else if (octstr_case_search(s, octstr_imm("IPv6"), 0) + 4 == l)
*atype = MMS_IPV6_ADDRESS;
}
return (*atype == MMS_UNKNOWN_ADDRESS) ? -1 : 0;
}

@ -24,7 +24,9 @@ typedef struct MmsMsg MmsMsg; /* Opaque type. */
typedef MmsMsg *MmsMsgGetFunc_t(void *p1, void *p2, Octstr *msgref, unsigned long *msize);
extern int mms_validate_address(Octstr *s);
enum AddressType_t {MMS_UNKNOWN_ADDRESS=-1, MMS_EMAIL_ADDRESS, MMS_IPV4_ADDRESS, MMS_IPV6_ADDRESS, MMS_NUMBER_ADDRESS};
extern int mms_validate_address_real(Octstr *s, enum AddressType_t *address_type);
#define mms_validate_address(s) mms_validate_address_real((s), NULL)
/*
* mms_frombinary: Parse MMS binary representation, return a Message or NULL.

@ -2559,3 +2559,8 @@ List *gwlist_create_ex_real(const char *file, const char *func, int line,...)
gwlist_append(l, v);
return l;
}
void mygw_free(void *x)
{
gw_free(x);
}

@ -93,6 +93,9 @@ List *get_value_parameters(Octstr *params);
Octstr *make_value_parameters(List *params);
/* Get parameter from http header value and strip it */
Octstr *get_stripped_param_value(Octstr *value, Octstr *param);
/* Where value is comma-separated, make separate header items. */
void unpack_mimeheaders(MIMEEntity *m);
@ -258,6 +261,9 @@ extern int charset_to_mibenum(char *charset);
Octstr *pack_rfc2047_text(Octstr *in, int charset_mib_enum);
Octstr *parse_rfc2047_text(Octstr *in, int *mibenum);
/* Utility func */
void mygw_free(void *);
#define US_ASCII_MIB_VAL 3
#define UTF8_MIB_VAL 106

Loading…
Cancel
Save