New caller ID code that actually parses
This commit is contained in:
parent
3d2b860ca8
commit
fc336c1103
@ -3,7 +3,7 @@
|
|||||||
* (C)2005, Dan Ponte
|
* (C)2005, Dan Ponte
|
||||||
* BSDL w/ advert.
|
* BSDL w/ advert.
|
||||||
*/
|
*/
|
||||||
/* $Amigan: phoned/include/phoned.h,v 1.22 2005/06/20 03:05:11 dcp1990 Exp $ */
|
/* $Amigan: phoned/include/phoned.h,v 1.23 2005/06/21 01:13:25 dcp1990 Exp $ */
|
||||||
#include <pcre.h> /* fugly, I know... */
|
#include <pcre.h> /* fugly, I know... */
|
||||||
#define VERSION "0.1"
|
#define VERSION "0.1"
|
||||||
#define LOGFILE "-"
|
#define LOGFILE "-"
|
||||||
@ -186,6 +186,8 @@ void log_out_user(char *loginna, login_t **toppt);
|
|||||||
void free_login(login_t *t, short traverse);
|
void free_login(login_t *t, short traverse);
|
||||||
void flush_logins(void);
|
void flush_logins(void);
|
||||||
short db_check_crend(char *loginna, char *pass);
|
short db_check_crend(char *loginna, char *pass);
|
||||||
|
cid_t *decode_sdmf(unsigned char *s);
|
||||||
|
cid_t *decode_mdmf(unsigned char *s);
|
||||||
/* old stuff...
|
/* old stuff...
|
||||||
void modem_pickup(void);
|
void modem_pickup(void);
|
||||||
void modem_hangup(void);
|
void modem_hangup(void);
|
||||||
|
168
phoned/cid.c
168
phoned/cid.c
@ -27,7 +27,7 @@
|
|||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
/* $Amigan: phoned/phoned/cid.c,v 1.6 2005/06/19 01:24:16 dcp1990 Exp $ */
|
/* $Amigan: phoned/phoned/cid.c,v 1.7 2005/06/21 01:13:26 dcp1990 Exp $ */
|
||||||
/* system includes */
|
/* system includes */
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
@ -36,7 +36,9 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "phoned.h"
|
#include <phoned.h>
|
||||||
|
#define BOGUS(pnt, cl, st, orig) if(pnt + cl > orig + st) { \
|
||||||
|
lprintf(error, "Packet length of %d is bogus (len is %d!)", cl, st); break; }
|
||||||
int free_cid(cid_t* ctf)
|
int free_cid(cid_t* ctf)
|
||||||
{
|
{
|
||||||
free(ctf->name);
|
free(ctf->name);
|
||||||
@ -44,33 +46,155 @@ int free_cid(cid_t* ctf)
|
|||||||
free(ctf);
|
free(ctf);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
cid_t *decode_sdmf(s)
|
||||||
|
unsigned char *s;
|
||||||
|
{
|
||||||
|
unsigned char *p;
|
||||||
|
unsigned char dtbuf[2];
|
||||||
|
int i = 0, ld;
|
||||||
|
cid_t *c;
|
||||||
|
if(*s != 0x04) return NULL; /* 0x04 is SDMF, anything else is garbage */
|
||||||
|
c = malloc(sizeof(cid_t));
|
||||||
|
memset(c, 0x0, sizeof(cid_t));
|
||||||
|
c->name = strdup("NO NAME");
|
||||||
|
p = s;
|
||||||
|
p++;
|
||||||
|
ld = *p++;
|
||||||
|
i = strlen(p);
|
||||||
|
dtbuf[2] = 0x0;
|
||||||
|
*dtbuf = *p++;
|
||||||
|
dtbuf[1] = *p++;
|
||||||
|
c->month = ((*dtbuf - '0') * 10) + (dtbuf[1] - '0');
|
||||||
|
*dtbuf = *p++;
|
||||||
|
dtbuf[1] = *p++;
|
||||||
|
c->day = ((*dtbuf - '0') * 10) + (dtbuf[1] - '0');
|
||||||
|
*dtbuf = *p++;
|
||||||
|
dtbuf[1] = *p++;
|
||||||
|
c->hour = ((*dtbuf - '0') * 10) + (dtbuf[1] - '0');
|
||||||
|
*dtbuf = *p++;
|
||||||
|
dtbuf[1] = *p++;
|
||||||
|
c->minute = ((*dtbuf - '0') * 10) + (dtbuf[1] - '0');
|
||||||
|
c->number = malloc(strlen(p) * sizeof(unsigned char));
|
||||||
|
snprintf(c->number, strlen(p), "%s", p);
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
cid_t *decode_mdmf(s)
|
||||||
|
unsigned char *s;
|
||||||
|
{
|
||||||
|
unsigned char *p;
|
||||||
|
unsigned char dtbuf[2];
|
||||||
|
int i = 0, j = 0, ld, cpl, checksum;
|
||||||
|
cid_t *c;
|
||||||
|
if(*s != 0x80) return NULL; /* 0x04 is SDMF, anything else is garbage */
|
||||||
|
c = malloc(sizeof(cid_t));
|
||||||
|
memset(c, 0x0, sizeof(cid_t));
|
||||||
|
p = s;
|
||||||
|
p++;
|
||||||
|
ld = *p++;
|
||||||
|
i = strlen(p);
|
||||||
|
lprintf(info, "p == 0x%x", *p);
|
||||||
|
for(; p <= s + i; /* look below */) {
|
||||||
|
switch(*p++) { /* data type */
|
||||||
|
case 0x01: /* date and time */
|
||||||
|
cpl = *p++;
|
||||||
|
BOGUS(p, cpl, i, s);
|
||||||
|
if(cpl != 8) lprintf(warn, "decode_mdmf: Warning: date length != 8 (%d really)", cpl);
|
||||||
|
*dtbuf = *p++;
|
||||||
|
dtbuf[1] = *p++;
|
||||||
|
dtbuf[2] = '\0';
|
||||||
|
c->month = ((*dtbuf - '0') * 10) + (dtbuf[1] - '0');
|
||||||
|
*dtbuf = *p++;
|
||||||
|
dtbuf[1] = *p++;
|
||||||
|
c->day = ((*dtbuf - '0') * 10) + (dtbuf[1] - '0');
|
||||||
|
*dtbuf = *p++;
|
||||||
|
dtbuf[1] = *p++;
|
||||||
|
c->hour = ((*dtbuf - '0') * 10) + (dtbuf[1] - '0');
|
||||||
|
*dtbuf = *p++;
|
||||||
|
dtbuf[1] = *p++;
|
||||||
|
c->minute = ((*dtbuf - '0') * 10) + (dtbuf[1] - '0');
|
||||||
|
break;
|
||||||
|
case 0x02: /* number */
|
||||||
|
cpl = *p++;
|
||||||
|
BOGUS(p, cpl, i, s);
|
||||||
|
if(cpl != 10) lprintf(info, "decode_mdmf: Info: number length != 10 (%d really)", cpl);
|
||||||
|
c->number = malloc(cpl * sizeof(unsigned char));
|
||||||
|
memset(c->number, 0, cpl * sizeof(unsigned char));
|
||||||
|
for(j = 0; j < cpl && *p != 0; j++) {
|
||||||
|
c->number[j] = *p++;
|
||||||
|
}
|
||||||
|
c->number[j] = '\0';
|
||||||
|
break;
|
||||||
|
case 0x04: /* number not available */
|
||||||
|
cpl = *p++;
|
||||||
|
BOGUS(p, cpl, i, s);
|
||||||
|
if(cpl < 0x01) {
|
||||||
|
lprintf(warn, "decode_mdmf: Warning: type 0x04 (no number) len < 1 (%d really)", cpl);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
*dtbuf = *p++;
|
||||||
|
if(c->number != NULL)
|
||||||
|
c->number = strdup(*dtbuf == 'O' ? "UNAVAILABLE" : (*dtbuf == 'P' ? "PRIVATE" : "UNKNOWN")); /* ternary city, baby */
|
||||||
|
if(cpl > 0x01) p += cpl - 1;
|
||||||
|
break;
|
||||||
|
case 0x07: /* name */
|
||||||
|
cpl = *p++;
|
||||||
|
BOGUS(p, cpl, i, s);
|
||||||
|
c->name = malloc(cpl * sizeof(unsigned char));
|
||||||
|
memset(c->name, 0, cpl * sizeof(unsigned char));
|
||||||
|
for(j = 0; j < cpl && p != 0; j++) {
|
||||||
|
c->name[j] = *p++;
|
||||||
|
}
|
||||||
|
c->name[j] = '\0';
|
||||||
|
if(strcmp(c->name, "O") == 0) {
|
||||||
|
free(c->name);
|
||||||
|
c->name = strdup("UNAVAILABLE");
|
||||||
|
} else if(strcmp(c->name, "P") == 0) {
|
||||||
|
free(c->name);
|
||||||
|
c->name = strdup("PRIVATE");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 0x08: /* name not available */
|
||||||
|
cpl = *p++;
|
||||||
|
BOGUS(p, cpl, i, s);
|
||||||
|
if(cpl < 0x01) {
|
||||||
|
lprintf(warn, "decode_mdmf: Warning: type 0x08 (no name) len < 1 (%d really)", cpl);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
*dtbuf = *p++;
|
||||||
|
if(c->name != NULL)
|
||||||
|
c->name = strdup(*dtbuf == 'O' ? "UNAVAILABLE" : (*dtbuf == 'P' ? "PRIVATE" : "UNKNOWN")); /* ternary city, baby */
|
||||||
|
if(cpl > 0x01) p += cpl - 1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
p++;
|
||||||
|
if(s + i - 1 == p) { /* checksum */
|
||||||
|
checksum = *p++;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lprintf(info, "Finished mdmf (%d/%d %d:%d %s -- %s)", c->month, c->day, c->hour, c->minute, c->name, c->number);
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
cid_t* parse_cid(char* cidstring)
|
cid_t* parse_cid(char* cidstring)
|
||||||
{
|
{
|
||||||
char *p, *datep;
|
unsigned char *p;
|
||||||
unsigned int len = 0, i;
|
unsigned int len = 0;
|
||||||
char finalbuf[1024], msg[512];
|
unsigned char finalbuf[1024];
|
||||||
char printbuf[2048];
|
|
||||||
unsigned char cch;
|
unsigned char cch;
|
||||||
char cbyte, cbyte2;
|
unsigned char cbyte, cbyte2;
|
||||||
char bytebuf[10];
|
unsigned char bytebuf[10];
|
||||||
char date[7];
|
|
||||||
char cidtime[7];
|
|
||||||
char name[128];
|
|
||||||
char phone[128];
|
|
||||||
int cur = 0, sz, fbcou = 0;
|
int cur = 0, sz, fbcou = 0;
|
||||||
short int finl = 0;
|
short int finl = 0;
|
||||||
char *ct;
|
|
||||||
cid_t* c;
|
cid_t* c;
|
||||||
c = malloc(sizeof(cid_t));
|
|
||||||
memset(msg, 0, sizeof msg);
|
|
||||||
memset(bytebuf, 0, sizeof bytebuf);
|
memset(bytebuf, 0, sizeof bytebuf);
|
||||||
memset(date, 0, sizeof date);
|
|
||||||
memset(finalbuf, 0, sizeof(finalbuf));
|
memset(finalbuf, 0, sizeof(finalbuf));
|
||||||
memset(printbuf, 0, sizeof(printbuf) * sizeof(char));
|
|
||||||
if(cidstring[strlen(cidstring)] == '\n')
|
if(cidstring[strlen(cidstring)] == '\n')
|
||||||
cidstring[strlen(cidstring)] = 0;
|
cidstring[strlen(cidstring)] = 0;
|
||||||
sz = strlen(cidstring);
|
sz = strlen(cidstring);
|
||||||
finl = (sz / 2) - 2;
|
finl = sz / 2;
|
||||||
strcpy(bytebuf, "0x");
|
strcpy(bytebuf, "0x");
|
||||||
for(cur = 0; cur <= sz; cur++) {
|
for(cur = 0; cur <= sz; cur++) {
|
||||||
cbyte = cidstring[cur++];
|
cbyte = cidstring[cur++];
|
||||||
@ -89,6 +213,13 @@ cid_t* parse_cid(char* cidstring)
|
|||||||
sz = fbcou;
|
sz = fbcou;
|
||||||
p = finalbuf;
|
p = finalbuf;
|
||||||
len = sz;
|
len = sz;
|
||||||
|
if(*finalbuf == 0x80) {
|
||||||
|
/* MDMF */
|
||||||
|
c = decode_mdmf(finalbuf);
|
||||||
|
} else if(*finalbuf == 0x04) {
|
||||||
|
c = decode_sdmf(finalbuf);
|
||||||
|
} else c = NULL;
|
||||||
|
#if 0
|
||||||
while(len && !(*p >= 0x30 && *p <= 0x39)) {
|
while(len && !(*p >= 0x30 && *p <= 0x39)) {
|
||||||
p++;
|
p++;
|
||||||
len--;
|
len--;
|
||||||
@ -165,6 +296,7 @@ cid_t* parse_cid(char* cidstring)
|
|||||||
c->month = strtol(date, NULL, 10);
|
c->month = strtol(date, NULL, 10);
|
||||||
c->day = strtol(date + 3, NULL, 10);
|
c->day = strtol(date + 3, NULL, 10);
|
||||||
date[2] = '/';
|
date[2] = '/';
|
||||||
|
#endif
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
void cid_handle(c)
|
void cid_handle(c)
|
||||||
|
@ -166,6 +166,7 @@ void modem_hread(char* cbuf)
|
|||||||
if(buffer[0] == '8' && buffer[1] == '0')
|
if(buffer[0] == '8' && buffer[1] == '0')
|
||||||
doing_cid = 1;
|
doing_cid = 1;
|
||||||
if(cbuf[0] == '\n') {
|
if(cbuf[0] == '\n') {
|
||||||
|
/* lprintf(debug, "Modem said %s", buffer); */
|
||||||
if(doing_cid) {
|
if(doing_cid) {
|
||||||
cid_t *rc;
|
cid_t *rc;
|
||||||
rc = parse_cid(buffer);
|
rc = parse_cid(buffer);
|
||||||
|
@ -2,7 +2,7 @@ main {
|
|||||||
modemdev "/dev/cuaa2";
|
modemdev "/dev/cuaa2";
|
||||||
loglevel all;
|
loglevel all;
|
||||||
database "./phoned.db";
|
database "./phoned.db";
|
||||||
socket "/tmp/phoned1.sock";
|
socket "/tmp/phoned.sock";
|
||||||
};
|
};
|
||||||
filters {
|
filters {
|
||||||
filter test1 {
|
filter test1 {
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
/* $Amigan: phoned/phoned/remote.c,v 1.9 2005/06/20 01:51:28 dcp1990 Exp $ */
|
/* $Amigan: phoned/phoned/remote.c,v 1.10 2005/06/21 01:13:26 dcp1990 Exp $ */
|
||||||
/* system includes */
|
/* system includes */
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -263,10 +263,24 @@ char *parse_command(cmd, cont, s)
|
|||||||
cid_t* rc;
|
cid_t* rc;
|
||||||
rc = parse_cid("802701083132323130383234070F5354414E444953482048454154494E020A343031333937333337325C\n");
|
rc = parse_cid("802701083132323130383234070F5354414E444953482048454154494E020A343031333937333337325C\n");
|
||||||
lprintf(info, "nam=%s;month=%d\n", rc->name, rc->month);
|
lprintf(info, "nam=%s;month=%d\n", rc->name, rc->month);
|
||||||
cid_notify(rc);
|
|
||||||
cid_log(rc);
|
cid_log(rc);
|
||||||
|
cid_notify(rc);
|
||||||
|
free(rc);
|
||||||
*cont = 0;
|
*cont = 0;
|
||||||
RNF("500 OK: Parser tested.\n");
|
RNF("500 OK: Parser tested.\n");
|
||||||
|
} else if(CHK("tmop")) {
|
||||||
|
if(argvect[1] != NULL) {
|
||||||
|
cid_t *rc;
|
||||||
|
rc = parse_cid(argvect[1]);
|
||||||
|
if(rc != NULL) {
|
||||||
|
cid_log(rc);
|
||||||
|
cid_notify(rc);
|
||||||
|
free(rc);
|
||||||
|
}
|
||||||
|
RNF("500 OK: Tested.\n");
|
||||||
|
} else {
|
||||||
|
RNF("513 ERROR: Needs argument\n");
|
||||||
|
}
|
||||||
} else if(CHK("gmm")) {
|
} else if(CHK("gmm")) {
|
||||||
stmod(argvect[1] != NULL ? argvect[1] : "AT\r\n");
|
stmod(argvect[1] != NULL ? argvect[1] : "AT\r\n");
|
||||||
*cont = 0;
|
*cont = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user