diff --git a/Makefile b/Makefile index 288f60b..74c7a5c 100644 --- a/Makefile +++ b/Makefile @@ -63,6 +63,7 @@ dist: $(PACKAGE)-$(VERSION)/src/plugins/smscrypt.c \ $(PACKAGE)-$(VERSION)/src/plugins/Makefile \ $(PACKAGE)-$(VERSION)/src/plugins/project.conf \ + $(PACKAGE)-$(VERSION)/tools/pdu.c \ $(PACKAGE)-$(VERSION)/tools/smscrypt.c \ $(PACKAGE)-$(VERSION)/tools/Makefile \ $(PACKAGE)-$(VERSION)/tools/project.conf \ diff --git a/tools/.cvsignore b/tools/.cvsignore index d913fcb..24becb2 100644 --- a/tools/.cvsignore +++ b/tools/.cvsignore @@ -1,2 +1,3 @@ .cvsignore +pdu smscrypt diff --git a/tools/Makefile b/tools/Makefile index d9cec88..9293551 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -1,4 +1,4 @@ -TARGETS = smscrypt +TARGETS = pdu smscrypt PREFIX = /usr/local DESTDIR = BINDIR = $(PREFIX)/bin @@ -15,6 +15,13 @@ INSTALL = install all: $(TARGETS) +pdu_OBJS = pdu.o +pdu_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) -I $(PREFIX)/include $(CFLAGSF) $(CFLAGS) `pkg-config --cflags glib-2.0` +pdu_LDFLAGS = $(LDFLAGSF) $(LDFLAGS) `pkg-config --libs glib-2.0` -lSystem -L $(PREFIX)/lib -Wl,-rpath,$(PREFIX)/lib ../src/command.o ../src/modem.o + +pdu: $(pdu_OBJS) + $(CC) -o pdu $(pdu_OBJS) $(pdu_LDFLAGS) + smscrypt_OBJS = smscrypt.o smscrypt_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) -I $(PREFIX)/include $(CFLAGSF) $(CFLAGS) `pkg-config --cflags glib-2.0` smscrypt_LDFLAGS = $(LDFLAGSF) $(LDFLAGS) -lSystem -L $(PREFIX)/lib -Wl,-rpath,$(PREFIX)/lib @@ -22,11 +29,14 @@ smscrypt_LDFLAGS = $(LDFLAGSF) $(LDFLAGS) -lSystem -L $(PREFIX)/lib -Wl,-rpath,$ smscrypt: $(smscrypt_OBJS) $(CC) -o smscrypt $(smscrypt_OBJS) $(smscrypt_LDFLAGS) +pdu.o: pdu.c ../include/Phone.h ../src/gsm.c + $(CC) $(pdu_CFLAGS) -c pdu.c + smscrypt.o: smscrypt.c ../include/Phone.h ../src/plugins/smscrypt.c $(CC) $(smscrypt_CFLAGS) -c smscrypt.c clean: - $(RM) $(smscrypt_OBJS) + $(RM) $(pdu_OBJS) $(smscrypt_OBJS) distclean: clean $(RM) $(TARGETS) diff --git a/tools/pdu.c b/tools/pdu.c new file mode 100644 index 0000000..2c1f982 --- /dev/null +++ b/tools/pdu.c @@ -0,0 +1,66 @@ +/* $Id$ */ +/* Copyright (c) 2010 Pierre Pronchery */ +/* This file is part of DeforaOS Desktop Phone */ +/* This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ + + + +#include "../src/gsm.c" + + +/* hexdump */ +static void _hexdump(char const * buf, size_t len) +{ + unsigned char const * b = (unsigned char *)buf; + size_t i; + + for(i = 0; i < len; i++) + { + printf(" %02x", b[i]); + if((i % 16) == 7) + fputc(' ', stdout); + else if((i % 16) == 15) + fputc('\n', stdout); + } + fputc('\n', stdout); +} + + +/* main */ +int main(int argc, char * argv[]) +{ + time_t timestamp; + char number[32]; + GSMEncoding encoding; + char * p; + struct tm t; + char buf[32]; + size_t len; + + if(argc != 2) + return 1; + if((p = _cmgr_pdu_parse(argv[1], ×tamp, number, &encoding, &len)) + != NULL) + { + printf("Number: %s\n", number); + gmtime_r(×tamp, &t); + strftime(buf, sizeof(buf), "%d/%m/%Y %H:%M:%S", &t); + printf("Timestamp: %s\n", buf); + printf("Encoding: %u\n", encoding); + _hexdump(p, len); + if(encoding == GSM_ENCODING_UTF8) + printf("Message: %s\n", p); + free(p); + } + return 0; +} diff --git a/tools/project.conf b/tools/project.conf index 821beb2..c08edac 100644 --- a/tools/project.conf +++ b/tools/project.conf @@ -1,9 +1,19 @@ -targets=smscrypt +targets=pdu,smscrypt cppflags_force=-I ../include cflags_force=-W cflags=-Wall -g -O2 dist=Makefile +[pdu] +type=binary +sources=pdu.c +cppflags=-I $(PREFIX)/include +cflags=`pkg-config --cflags glib-2.0` +ldflags=`pkg-config --libs glib-2.0` -lSystem -L $(PREFIX)/lib -Wl,-rpath,$(PREFIX)/lib ../src/command.o ../src/modem.o + +[pdu.c] +depends=../include/Phone.h,../src/gsm.c + [smscrypt] type=binary sources=smscrypt.c