[asterisk-addons-commits] mnicholson: branch mnicholson/chan-mobile-refactor r773 - /team/mnicholson/ch...
SVN commits to the Asterisk addons project
asterisk-addons-commits at lists.digium.com
Wed Feb 11 15:43:59 CST 2009
Author: mnicholson
Date: Wed Feb 11 15:43:58 2009
New Revision: 773
URL: http://svn.digium.com/svn-view/asterisk-addons?view=rev&rev=773
Log:
implemented hfp_parse_clip() and used it to simplify caller id parsing for the
headset profile
Modified:
team/mnicholson/chan-mobile-refactor/channels/chan_mobile.c
Modified: team/mnicholson/chan-mobile-refactor/channels/chan_mobile.c
URL: http://svn.digium.com/svn-view/asterisk-addons/team/mnicholson/chan-mobile-refactor/channels/chan_mobile.c?view=diff&rev=773&r1=772&r2=773
==============================================================================
--- team/mnicholson/chan-mobile-refactor/channels/chan_mobile.c (original)
+++ team/mnicholson/chan-mobile-refactor/channels/chan_mobile.c Wed Feb 11 15:43:58 2009
@@ -355,6 +355,7 @@
static int hfp_init_sms(struct hfp_pvt *pvt);
static int hfp_wait(struct hfp_pvt *pvt);
static int hfp_parse_ciev(struct hfp_pvt *pvt, char *buf, int *value);
+static char *hfp_parse_clip(struct hfp_pvt *pvt, char *buf);
static int hfp_brsf2int(struct hfp_hf *hf);
static struct hfp_ag *hfp_int2brsf(int brsf, struct hfp_ag *ag);
@@ -1617,6 +1618,52 @@
pvt->cind_state[i] = *value;
return pvt->cind_index[i];
+}
+
+/*
+ * \brief Parse a CLIP event.
+ * \param pvt an hfp_pvt struct
+ * \param buf the buffer to parse (null terminated)
+ * @note buf will be modified when the CID string is parsed
+ * \return NULL on error (parse error) or a pointer to the caller id
+ * inforamtion in buf
+ * success
+ */
+static char *hfp_parse_clip(struct hfp_pvt *pvt, char *buf) {
+ int i, state;
+ char *clip;
+ size_t s;
+
+ /* parse clip info in the following format:
+ * +CLIP: "123456789",128,...
+ */
+ state = 0;
+ s = strlen(buf);
+ for (i = 0; i < s && state != 3; i++) {
+ switch (state) {
+ case 0: /* search for start of the number (") */
+ if (buf[i] == '"') {
+ state++;
+ }
+ break;
+ case 1: /* mark the number */
+ clip = &buf[i];
+ state++;
+ break;
+ case 2: /* search for the end of the number (") */
+ if (buf[i] == '"') {
+ buf[i] = '\0';
+ state++;
+ }
+ break;
+ }
+ }
+
+ if (state != 3) {
+ return NULL;
+ }
+
+ return clip;
}
/*
@@ -2195,7 +2242,7 @@
struct hfp_pvt *hfp = pvt->hfp;
struct ast_channel *chn;
char buf[256];
- char cid_num[AST_MAX_EXTENSION], *pcids, *pcide;
+ char cid_num[AST_MAX_EXTENSION], *clip;
int t, i, smsi;
int group, group2;
int callp = 0, callsetupp;
@@ -2398,12 +2445,9 @@
break;
case MBL_STATE_RING:
cid_num[0] = 0x00;
- if ((pcids = strstr(buf, "+CLIP:"))) {
- if ((pcids = strchr(pcids, '"'))) {
- if ((pcide = strchr(pcids+1, '"'))) {
- strncpy(cid_num, pcids+1, pcide - pcids - 1);
- cid_num[pcide - pcids - 1] = 0x00;
- }
+ if (at_msg == AT_CLIP) {
+ if ((clip = hfp_parse_clip(hfp, buf))) {
+ ast_copy_string(cid_num, clip, sizeof(cid_num));
}
chn = mbl_new(AST_STATE_RING, pvt, cid_num);
if (chn) {
More information about the asterisk-addons-commits
mailing list