• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright (C) 2007-2008 The Android Open Source Project
2 **
3 ** This software is licensed under the terms of the GNU General Public
4 ** License version 2, as published by the Free Software Foundation, and
5 ** may be copied, distributed, and modified under those terms.
6 **
7 ** This program is distributed in the hope that it will be useful,
8 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
9 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10 ** GNU General Public License for more details.
11 */
12 #ifndef _android_sms_h
13 #define _android_sms_h
14 
15 #include <time.h>
16 
17 /** MESSAGE TEXT
18  **/
19 /* convert a quoted message text into a utf8 string. Note: you can use 'str' as the destination buffer
20  * with the current implementation. always return the number of utf8 bytes corresponding to the original
21  * message string, even if utf8 is NULL and utf8len is 0
22  */
23 extern int  sms_utf8_from_message_str( const char*  str, int  strlen, unsigned char*  utf8, int  utf8len );
24 
25 /* the equivalent in the opposite direction
26  */
27 extern int  sms_utf8_to_message_str( const unsigned char*  utf8, int  utf8len, char*  str, int  strlen );
28 
29 /** TIMESTAMPS
30  **/
31 
32 /* An SMS timestamp structure */
33 typedef struct {
34     unsigned char  data[7];
35 } SmsTimeStampRec, *SmsTimeStamp;
36 
37 extern void  sms_timestamp_now( SmsTimeStamp  stamp );
38 extern int   sms_timestamp_to_tm( SmsTimeStamp  stamp, struct tm*  tm );
39 
40 /** SMS ADDRESSES
41  **/
42 
43 #define  SMS_ADDRESS_MAX_SIZE  16
44 
45 typedef struct {
46     unsigned char  len;
47     unsigned char  toa;
48     unsigned char  data[ SMS_ADDRESS_MAX_SIZE ];
49 } SmsAddressRec, *SmsAddress;
50 
51 extern int  sms_address_from_str( SmsAddress  address, const char*  src, int  srclen );
52 extern int  sms_address_to_str( SmsAddress  address, char*  src, int  srclen );
53 
54 extern int  sms_address_from_bytes( SmsAddress  address, const unsigned char*  buf, int  buflen );
55 extern int  sms_address_to_bytes  ( SmsAddress  address, unsigned char*  buf, int  bufsize );
56 extern int  sms_address_from_hex  ( SmsAddress  address, const char*  hex, int  hexlen );
57 extern int  sms_address_to_hex    ( SmsAddress  address, char*   hex, int  hexsize );
58 
59 /** SMS PROTOCOL DATA UNITS
60  **/
61 
62 typedef struct SmsPDURec*   SmsPDU;
63 
64 extern SmsPDU*  smspdu_create_deliver_utf8( const unsigned char*   utf8,
65                                             int                    utf8len,
66                                             const SmsAddressRec*   sender_address,
67                                             const SmsTimeStampRec* timestamp );
68 
69 extern void     smspdu_free_list( SmsPDU*  pdus );
70 
71 extern SmsPDU   smspdu_create_from_hex( const char*  hex, int  hexlen );
72 
73 extern int      smspdu_to_hex( SmsPDU  pdu, char*  hex, int  hexsize );
74 
75 /* free a given SMS PDU */
76 extern void     smspdu_free( SmsPDU  pdu );
77 
78 typedef enum {
79     SMS_PDU_INVALID = 0,
80     SMS_PDU_DELIVER,
81     SMS_PDU_SUBMIT,
82     SMS_PDU_STATUS_REPORT
83 } SmsPduType;
84 
85 extern SmsPduType    smspdu_get_type( SmsPDU  pdu );
86 
87 /* retrieve the sender address of a SMS-DELIVER pdu, returns -1 otherwise */
88 extern int  smspdu_get_sender_address( SmsPDU  pdu, SmsAddress  address );
89 
90 /* retrieve the service center timestamp of a SMS-DELIVER pdu, return -1 otherwise */
91 extern int  smspdu_get_sc_timestamp( SmsPDU  pdu, SmsTimeStamp  timestamp );
92 
93 /* retrieve the receiver address of a SMS-SUBMIT pdu, return -1 otherwise */
94 extern int  smspdu_get_receiver_address( SmsPDU  pdu, SmsAddress  address );
95 
96 extern int  smspdu_get_ref      ( SmsPDU  pdu );
97 extern int  smspdu_get_max_index( SmsPDU  pdu );
98 extern int  smspdu_get_cur_index( SmsPDU  pdu );
99 
100 /* get the message embedded in a SMS PDU as a utf8 byte array, returns the length of the message in bytes */
101 /* or -1 in case of error */
102 extern int  smspdu_get_text_message( SmsPDU  pdu, unsigned char*  utf8, int  utf8len );
103 
104 /** SMS SUBMIT RECEIVER
105  ** collects one or more SMS-SUBMIT PDUs to generate a single message to deliver
106  **/
107 
108 typedef struct SmsReceiverRec  *SmsReceiver;
109 
110 extern SmsReceiver   sms_receiver_create( void );
111 extern void          sms_receiver_destroy( SmsReceiver  rec );
112 
113 extern int           sms_receiver_add_submit_pdu( SmsReceiver  rec, SmsPDU       submit_pdu );
114 extern int           sms_receiver_get_text_message( SmsReceiver  rec, int  index, unsigned char*  utf8, int  utf8len );
115 extern SmsPDU*       sms_receiver_create_deliver( SmsReceiver  rec, int  index, const SmsAddressRec*  from );
116 
117 #endif /* _android_sms_h */
118