1
0
Fork 0

Misc. additions

This commit is contained in:
bagyenda 2011-09-08 10:47:58 +00:00
parent e7b5faee07
commit f67330f9e0
6 changed files with 70 additions and 33 deletions

View File

@ -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> 2011-07-27 P. A. Bagyenda <bagyenda@dsmagic.com>
* Fixed UAProf timestamp bug * Fixed UAProf timestamp bug
2011-05-30 P. A. Bagyenda <bagyenda@dsmagic.com> 2011-05-30 P. A. Bagyenda <bagyenda@dsmagic.com>

View File

@ -308,6 +308,26 @@ static int mk_data_file(int64_t qid, char *loc, char *dir, char out[])
return 0; 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) static int pgq_free_envelope(MmsEnvelope *e, int removefromqueue)
{ {
int ret = 0; int ret = 0;
@ -423,6 +443,7 @@ static MmsEnvelope *pgq_queue_readenvelope_ex(char *qf, char *mms_queuedir, int
char cmd[4*QFNAMEMAX]; char cmd[4*QFNAMEMAX];
char data_file[4*QFNAMEMAX+1]; char data_file[4*QFNAMEMAX+1];
Octstr *from = NULL; Octstr *from = NULL;
Octstr *data;
MmsEnvelope *e = NULL; MmsEnvelope *e = NULL;
struct pgfile_t *pgs; struct pgfile_t *pgs;
@ -496,13 +517,17 @@ 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. * 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... * 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); strncpy(data_file, s+1, sizeof data_file);
else else
data_file[0] = 0; /* nada */ data_file[0] = 0; /* nada */
PQclear(r); PQclear(r);
octstr_destroy(data);
sprintf(cmd, "SELECT item,value,id FROM mms_message_headers WHERE qid=%lld FOR UPDATE", qid); sprintf(cmd, "SELECT item,value,id FROM mms_message_headers WHERE qid=%lld FOR UPDATE", qid);
r = PQexec(c, cmd); r = PQexec(c, cmd);
@ -1060,8 +1085,8 @@ static MmsMsg *pgq_queue_getdata(MmsEnvelope *e)
if (qfs->data_file[0]) if (qfs->data_file[0])
ms = octstr_read_file(qfs->data_file); ms = octstr_read_file(qfs->data_file);
else { else {
size_t dlen, n; size_t n;
char cmd[512], *data, *x; char cmd[512];
PGresult *r; PGresult *r;
sprintf(cmd, "SELECT data from mms_messages WHERE id = %lld", qfs->qid); sprintf(cmd, "SELECT data from mms_messages WHERE id = %lld", qfs->qid);
@ -1074,17 +1099,7 @@ static MmsMsg *pgq_queue_getdata(MmsEnvelope *e)
e->xqfname, qfs->dir); e->xqfname, qfs->dir);
return NULL; return NULL;
} }
ms = get_bytea(r, 0, PQfnumber(r, "data"));
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);
PQclear(r); PQclear(r);
} }

View File

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

View File

@ -24,7 +24,9 @@ typedef struct MmsMsg MmsMsg; /* Opaque type. */
typedef MmsMsg *MmsMsgGetFunc_t(void *p1, void *p2, Octstr *msgref, unsigned long *msize); 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. * mms_frombinary: Parse MMS binary representation, return a Message or NULL.

View File

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

View File

@ -93,6 +93,9 @@ List *get_value_parameters(Octstr *params);
Octstr *make_value_parameters(List *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. */ /* Where value is comma-separated, make separate header items. */
void unpack_mimeheaders(MIMEEntity *m); 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 *pack_rfc2047_text(Octstr *in, int charset_mib_enum);
Octstr *parse_rfc2047_text(Octstr *in, int *mibenum); Octstr *parse_rfc2047_text(Octstr *in, int *mibenum);
/* Utility func */
void mygw_free(void *);
#define US_ASCII_MIB_VAL 3 #define US_ASCII_MIB_VAL 3
#define UTF8_MIB_VAL 106 #define UTF8_MIB_VAL 106