X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fimc_common.c;h=816f1b4c1e0ef315f2fd22f697f09d34f52118f8;hb=145b413ff76f9d78c3ebc3f08a5fecbc60ed0d83;hp=a4b51fb90c1b4dc05ef76fada1354873b0fc1745;hpb=f6fa5175e76b859cb2a3d1d2f6de33835a857c8a;p=platform%2Fcore%2Ftelephony%2Ftel-plugin-imc.git diff --git a/src/imc_common.c b/src/imc_common.c index a4b51fb..816f1b4 100644 --- a/src/imc_common.c +++ b/src/imc_common.c @@ -1,7 +1,9 @@ /* * tel-plugin-imc * - * Copyright (c) 2013 Samsung Electronics Co. Ltd. All rights reserved. + * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Ja-young Gu * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,44 +19,15 @@ */ #include -#include #include +#include #include - #include -#include - -#include "imc_common.h" - -void on_send_imc_request(TcorePending *p, - TelReturn send_status, void *user_data) -{ - dbg("Send - [%s]", - (send_status == TEL_RETURN_SUCCESS ? "OK" : "NOK")); -} - -ImcRespCbData *imc_create_resp_cb_data(TcoreObjectResponseCallback cb, - void *cb_data, void *data, guint data_len) -{ - ImcRespCbData *resp_cb_data; - resp_cb_data = tcore_malloc0(sizeof(ImcRespCbData) + data_len); - resp_cb_data->cb = cb; - resp_cb_data->cb_data = cb_data; - if ((data != NULL) && (data_len > 0)) - memcpy(resp_cb_data->data, data, data_len); - return resp_cb_data; -} - -void imc_destroy_resp_cb_data(ImcRespCbData *resp_cb_data) -{ - if (resp_cb_data) - tcore_free(resp_cb_data); -} +#include "imc_common.h" -#if 0 #undef MAX #define MAX(a, b) (((a) > (b)) ? (a) : (b)) @@ -79,39 +52,6 @@ char _util_unpackb(const char *src, int pos, int len); char _util_convert_byte_hexChar(char val); gboolean util_byte_to_hex(const char *byte_pdu, char *hex_pdu, int num_bytes); -void util_hex_dump(char *pad, int size, const void *data) -{ - char buf[255] = {0, }; - char hex[4] = {0, }; - int i; - unsigned char *p; - - if (size <= 0) { - msg("%sno data", pad); - return; - } - - p = (unsigned char *) data; - - snprintf(buf, 255, "%s%04X: ", pad, 0); - for (i = 0; i < size; i++) { - snprintf(hex, 4, "%02X ", p[i]); - strcat(buf, hex); - - if ((i + 1) % 8 == 0) { - if ((i + 1) % 16 == 0) { - msg("%s", buf); - memset(buf, 0, 255); - snprintf(buf, 255, "%s%04X: ", pad, i + 1); - } else { - strcat(buf, " "); - } - } - } - - msg("%s", buf); -} - unsigned char util_hexCharToInt(char c) { if (c >= '0' && c <= '9') @@ -129,14 +69,20 @@ unsigned char util_hexCharToInt(char c) char *util_hex_to_string(const char *src, unsigned int src_len) { char *dest; - int i; + unsigned int i; if (src == NULL) return NULL; dest = g_malloc0(src_len * 2 + 1); + if (dest == NULL) { + err("Memory allocation failed!!"); + return NULL; + } + for (i = 0; i < src_len; i++) { - sprintf(dest + (i * 2), "%02x", (unsigned char)src[i]); + snprintf(dest + (i * 2), (src_len * 2 + 1) - (i * 2), + "%02x", (unsigned char)src[i]); } dest[src_len * 2] = '\0'; @@ -144,7 +90,7 @@ char *util_hex_to_string(const char *src, unsigned int src_len) return dest; } -char* util_hexStringToBytes(char *s) +char *util_hexStringToBytes(char *s) { char *ret; int i; @@ -155,7 +101,11 @@ char* util_hexStringToBytes(char *s) sz = strlen(s); - ret = g_try_malloc0((sz / 2) + 1); + ret = g_malloc0((sz / 2) + 1); + if (ret == NULL) { + err("Memory allocation failed!!"); + return NULL; + } dbg("Convert String to Binary!!"); @@ -184,7 +134,7 @@ char _util_unpackb(const char *src, int pos, int len) src++; len -= 8 - pos; - if (len > 0) result = (result << len) | (*src >> (8 - len)); // if any bits left + if (len > 0) result = (result << len) | (*src >> (8 - len)); /* if any bits left */ } return result; @@ -194,13 +144,12 @@ char _util_convert_byte_hexChar(char val) { char hex_char; - if (val <= 9) { + if (val <= 9) hex_char = (char) (val + '0'); - } else if (val >= 10 && val <= 15) { + else if (val >= 10 && val <= 15) hex_char = (char) (val - 10 + 'A'); - } else { + else hex_char = '0'; - } return (hex_char); } @@ -219,22 +168,3 @@ gboolean util_byte_to_hex(const char *byte_pdu, char *hex_pdu, int num_bytes) return TRUE; } - -char* util_removeQuotes(void *data) -{ - char *tmp = NULL; - int data_len = 0; - - data_len = strlen((const char *) data); - dbg("data_len: %d----%s", data_len, data); - if (data_len <= 0) { - return NULL; - } - - tmp = g_try_malloc0(data_len - 1); - memcpy(tmp, data + 1, data_len - 2); - dbg("tmp: [%s]", tmp); - - return tmp; -} -#endif