From a04e6effed0b81ec7495df2a1448484645b20cc5 Mon Sep 17 00:00:00 2001 From: laforge Date: Fri, 12 Jan 2007 23:57:33 +0000 Subject: - use talloc (of samba project) to debug memory allocations and simplify code - introduce new ucmd_alloc() function - add DTMF support to gsmd, libgsmd and gsmd-util - fix crash of libgsmd when events don't have handlers registered - implement call progress for TI modem - split modem init string in separate commands to fit our parser git-svn-id: http://svn.openmoko.org/trunk/src/target/gsm@544 99fdad57-331a-0410-800a-d7fa5415bdb3 --- src/gsmd/unsolicited.c | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) (limited to 'src/gsmd/unsolicited.c') diff --git a/src/gsmd/unsolicited.c b/src/gsmd/unsolicited.c index 57a4e59..0c12f32 100644 --- a/src/gsmd/unsolicited.c +++ b/src/gsmd/unsolicited.c @@ -11,10 +11,11 @@ #include #include #include +#include struct gsmd_ucmd *usock_build_event(u_int8_t type, u_int8_t subtype, u_int8_t len) { - struct gsmd_ucmd *ucmd = malloc(sizeof(*ucmd)+len); + struct gsmd_ucmd *ucmd = ucmd_alloc(len); if (!ucmd) return NULL; @@ -29,11 +30,10 @@ struct gsmd_ucmd *usock_build_event(u_int8_t type, u_int8_t subtype, u_int8_t le static struct gsmd_ucmd *ucmd_copy(const struct gsmd_ucmd *orig) { - int size = sizeof(*orig) + orig->hdr.len; - struct gsmd_ucmd *copy = malloc(size); + struct gsmd_ucmd *copy = ucmd_alloc(orig->hdr.len); if (copy) - memcpy(copy, orig, size); + memcpy(copy, orig, orig->hdr.len); return copy; } @@ -47,17 +47,25 @@ int usock_evt_send(struct gsmd *gsmd, struct gsmd_ucmd *ucmd, u_int32_t evt) llist_for_each_entry(gu, &gsmd->users, list) { if (gu->subscriptions & (1 << evt)) { - struct gsmd_ucmd *cpy = ucmd_copy(ucmd); - usock_cmd_enqueue(ucmd, gu); - num_sent++; - ucmd = cpy; - if (!ucmd) { - fprintf(stderr, "can't allocate memory for copy of ucmd\n"); - return num_sent; + if (num_sent == 0) + usock_cmd_enqueue(ucmd, gu); + else { + struct gsmd_ucmd *cpy = ucmd_copy(ucmd); + if (!cpy) { + fprintf(stderr, + "can't allocate memory for " + "copy of ucmd\n"); + return num_sent; + } + usock_cmd_enqueue(cpy, gu); } + num_sent++; } } + if (num_sent == 0) + talloc_free(ucmd); + return num_sent; } @@ -101,7 +109,7 @@ static int cring_parse(char *buf, int len, const char *param, struct gsmd *gsmd) aux->u.call.type = GSMD_CALL_FAX; } else if (!strncmp(param, "GPRS ", 5)) { /* FIXME: change event type to GPRS */ - free(ucmd); + talloc_free(ucmd); return 0; } /* FIXME: parse all the ALT* profiles, Chapter 6.11 */ @@ -322,7 +330,8 @@ int unsolicited_parse(struct gsmd *g, char *buf, int len, const char *param) rc = vpl->unsolicit[i].parse(buf, len, colon, g); if (rc < 0) gsmd_log(GSMD_ERROR, "error %d during parse of " - "unsolicied response `%s'\n", rc, buf); + "vendor unsolicied response `%s'\n", + rc, buf); return rc; } } -- cgit v1.2.3