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 */ 23extern 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 */ 27extern 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 */ 33typedef struct { 34 unsigned char data[7]; 35} SmsTimeStampRec, *SmsTimeStamp; 36 37extern void sms_timestamp_now( SmsTimeStamp stamp ); 38extern int sms_timestamp_to_tm( SmsTimeStamp stamp, struct tm* tm ); 39 40/** SMS ADDRESSES 41 **/ 42 43#define SMS_ADDRESS_MAX_SIZE 16 44 45typedef struct { 46 unsigned char len; 47 unsigned char toa; 48 unsigned char data[ SMS_ADDRESS_MAX_SIZE ]; 49} SmsAddressRec, *SmsAddress; 50 51extern int sms_address_from_str( SmsAddress address, const char* src, int srclen ); 52extern int sms_address_to_str( SmsAddress address, char* src, int srclen ); 53 54extern int sms_address_from_bytes( SmsAddress address, const unsigned char* buf, int buflen ); 55extern int sms_address_to_bytes ( SmsAddress address, unsigned char* buf, int bufsize ); 56extern int sms_address_from_hex ( SmsAddress address, const char* hex, int hexlen ); 57extern int sms_address_to_hex ( SmsAddress address, char* hex, int hexsize ); 58 59/** SMS PROTOCOL DATA UNITS 60 **/ 61 62typedef struct SmsPDURec* SmsPDU; 63 64extern SmsPDU* smspdu_create_deliver_utf8( const unsigned char* utf8, 65 int utf8len, 66 const SmsAddressRec* sender_address, 67 const SmsTimeStampRec* timestamp ); 68 69extern void smspdu_free_list( SmsPDU* pdus ); 70 71extern SmsPDU smspdu_create_from_hex( const char* hex, int hexlen ); 72 73extern int smspdu_to_hex( SmsPDU pdu, char* hex, int hexsize ); 74 75/* free a given SMS PDU */ 76extern void smspdu_free( SmsPDU pdu ); 77 78typedef enum { 79 SMS_PDU_INVALID = 0, 80 SMS_PDU_DELIVER, 81 SMS_PDU_SUBMIT, 82 SMS_PDU_STATUS_REPORT 83} SmsPduType; 84 85extern SmsPduType smspdu_get_type( SmsPDU pdu ); 86 87/* retrieve the sender address of a SMS-DELIVER pdu, returns -1 otherwise */ 88extern int smspdu_get_sender_address( SmsPDU pdu, SmsAddress address ); 89 90/* retrieve the service center timestamp of a SMS-DELIVER pdu, return -1 otherwise */ 91extern int smspdu_get_sc_timestamp( SmsPDU pdu, SmsTimeStamp timestamp ); 92 93/* retrieve the receiver address of a SMS-SUBMIT pdu, return -1 otherwise */ 94extern int smspdu_get_receiver_address( SmsPDU pdu, SmsAddress address ); 95 96extern int smspdu_get_ref ( SmsPDU pdu ); 97extern int smspdu_get_max_index( SmsPDU pdu ); 98extern 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 */ 102extern 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 108typedef struct SmsReceiverRec *SmsReceiver; 109 110extern SmsReceiver sms_receiver_create( void ); 111extern void sms_receiver_destroy( SmsReceiver rec ); 112 113extern int sms_receiver_add_submit_pdu( SmsReceiver rec, SmsPDU submit_pdu ); 114extern int sms_receiver_get_text_message( SmsReceiver rec, int index, unsigned char* utf8, int utf8len ); 115extern SmsPDU* sms_receiver_create_deliver( SmsReceiver rec, int index, const SmsAddressRec* from ); 116 117#endif /* _android_sms_h */ 118