diff options
author | Paul Kocialkowski <contact@paulk.fr> | 2014-08-03 23:53:15 +0200 |
---|---|---|
committer | Paul Kocialkowski <contact@paulk.fr> | 2014-08-03 23:53:22 +0200 |
commit | c48926e382b68d0764c88b453711a9b269735537 (patch) | |
tree | 9447ac2df240f6083aba76e0ce9be62373fe2385 /samsung-ipc | |
parent | 5e4cb302a7e9ccf935c3b47063cbffa389cc9c25 (diff) | |
download | external_libsamsung-ipc-c48926e382b68d0764c88b453711a9b269735537.zip external_libsamsung-ipc-c48926e382b68d0764c88b453711a9b269735537.tar.gz external_libsamsung-ipc-c48926e382b68d0764c88b453711a9b269735537.tar.bz2 |
sms: Size function for helpers that return data with non-explicit size
Also, pdu is data, not string
Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
Diffstat (limited to 'samsung-ipc')
-rw-r--r-- | samsung-ipc/sms.c | 59 |
1 files changed, 51 insertions, 8 deletions
diff --git a/samsung-ipc/sms.c b/samsung-ipc/sms.c index f0e2925..beacecc 100644 --- a/samsung-ipc/sms.c +++ b/samsung-ipc/sms.c @@ -23,6 +23,19 @@ #include <samsung-ipc.h> +size_t ipc_sms_send_msg_size_setup(struct ipc_sms_send_msg_request_header *header, + const void *smsc, size_t smsc_size, const void *pdu, size_t pdu_size) +{ + size_t size; + + if (header == NULL || smsc == NULL || smsc_size == 0 || pdu == NULL || pdu_size == 0) + return 0; + + size = sizeof(struct ipc_sms_send_msg_request_header) + sizeof(unsigned char) + smsc_size + pdu_size; + + return size; +} + void *ipc_sms_send_msg_setup(struct ipc_sms_send_msg_request_header *header, const void *smsc, size_t smsc_size, const void *pdu, size_t pdu_size) { @@ -36,9 +49,12 @@ void *ipc_sms_send_msg_setup(struct ipc_sms_send_msg_request_header *header, smsc_length = (unsigned char) smsc_size; - header->length = (unsigned char) (sizeof(smsc_length) + smsc_size + pdu_size); + header->length = (unsigned char) (sizeof(unsigned char) + smsc_size + pdu_size); + + size = ipc_sms_send_msg_size_setup(header, smsc, smsc_size, pdu, pdu_size); + if (size == 0) + return NULL; - size = sizeof(struct ipc_sms_send_msg_request_header) + sizeof(smsc_length) + smsc_size + pdu_size; data = calloc(1, size); p = (unsigned char *) data; @@ -58,10 +74,20 @@ void *ipc_sms_send_msg_setup(struct ipc_sms_send_msg_request_header *header, return data; } -char *ipc_sms_incoming_msg_pdu_extract(const void *data, size_t size) +size_t ipc_sms_incoming_msg_pdu_size_extract(const void *data, size_t size) +{ + struct ipc_sms_incoming_msg_header *header; + + header = (struct ipc_sms_incoming_msg_header *) data; + if (header->length == 0 || header->length > size - sizeof(struct ipc_sms_incoming_msg_header)) + return 0; + + return (size_t) header->length; +} + +void *ipc_sms_incoming_msg_pdu_extract(const void *data, size_t size) { struct ipc_sms_incoming_msg_header *header; - char *string; void *pdu; if (data == NULL || size < sizeof(struct ipc_sms_incoming_msg_header)) @@ -73,9 +99,23 @@ char *ipc_sms_incoming_msg_pdu_extract(const void *data, size_t size) pdu = (void *) ((unsigned char *) data + sizeof(struct ipc_sms_incoming_msg_header)); - string = data2string(pdu, header->length); + return pdu; +} + +size_t ipc_sms_save_msg_size_setup(struct ipc_sms_save_msg_request_header *header, + const void *smsc, size_t smsc_size, const void *pdu, size_t pdu_size) +{ + size_t size; + + if (header == NULL || pdu == NULL || pdu_size == 0) + return 0; + + if (smsc == NULL) + smsc_size = 0; + + size = sizeof(struct ipc_sms_save_msg_request_header) + sizeof(unsigned char) + smsc_size + pdu_size; - return string; + return size; } void *ipc_sms_save_msg_setup(struct ipc_sms_save_msg_request_header *header, @@ -96,9 +136,12 @@ void *ipc_sms_save_msg_setup(struct ipc_sms_save_msg_request_header *header, header->magic = 2; header->index = 12 - 1, - header->length = (unsigned char) (sizeof(smsc_length) + smsc_size + pdu_size); + header->length = (unsigned char) (sizeof(unsigned char) + smsc_size + pdu_size); + + size = ipc_sms_save_msg_size_setup(header, smsc, smsc_size, pdu, pdu_size); + if (size == 0) + return NULL; - size = sizeof(struct ipc_sms_save_msg_request_header) + sizeof(smsc_length) + smsc_size + pdu_size; data = calloc(1, size); p = (unsigned char *) data; |