Sync from SPIN branch
[platform/core/telephony/tel-plugin-dbus_tapi.git] / src / dtapi_phonebook.c
similarity index 60%
rename from src/phonebook.c
rename to src/dtapi_phonebook.c
index e9ea6b5..654d688 100644 (file)
  */
 
 #include <stdio.h>
-#include <string.h>
 #include <stdlib.h>
-#include <errno.h>
+#include <string.h>
+
+#include <glib.h>
 
 #include <tcore.h>
 #include <server.h>
 #include <plugin.h>
-#include <hal.h>
-#include <communicator.h>
-#include <core_object.h>
-#include <queue.h>
-#include <user_request.h>
-#include <util.h>
 #include <co_phonebook.h>
-#include <co_sim.h>
 
 #include "generated-code.h"
-#include "common.h"
-#include "sat_manager.h"
-
-static const char* dbg_dbus_pb_type_name[] = {"PB_TYPE_FDN", "PB_TYPE_ADN", "PB_TYPE_SDN",
-               "PB_TYPE_USIM", "PB_TYPE_AAS", "PB_TYPE_GAS", };
-static const char* dbg_dbus_pb_adf_field_name[] = { "NO VALUE 0", "PB_FIELD_NAME", "PB_FIELD_NUMBER",
-               "PB_FIELD_ANR1", "PB_FIELD_ANR2", "PB_FIELD_ANR3", "PB_FIELD_EMAIL1",
-               "PB_FIELD_EMAIL2", "PB_FIELD_EMAIL3", "PB_FIELD_EMAIL4", "PB_FIELD_SNE",
-               "PB_FIELD_GRP", "PB_FIELD_PBC" };
-static const char* dbg_dbus_pb_ton_name[] = { "PB_TON_UNKNOWN", "PB_TON_INTERNATIONAL",
-               "PB_TON_NATIONAL", "PB_TON_NETWORK_SPECIFIC", "PB_TON_DEDICATED_ACCESS",
-               "PB_TON_ALPHA_NUMERIC", "PB_TON_ABBREVIATED_NUMBER",
-               "PB_TON_RESERVED_FOR_EXT", };
-
-#define DBUS_PBM_GET_COPBM(invocation, co_pbm, server) { \
+#include "dtapi_common.h"
+
+/*
+ * Printable values for debugging/logging
+ */
+static const char *dbg_dbus_pb_type_name[] = {
+       "PB_TYPE_FDN", "PB_TYPE_ADN", "PB_TYPE_SDN",
+       "PB_TYPE_USIM", "PB_TYPE_AAS", "PB_TYPE_GAS"
+};
+
+static const char *dbg_dbus_pb_adf_field_name[] = {
+       "NO VALUE 0", "PB_FIELD_NAME", "PB_FIELD_NUMBER",
+       "PB_FIELD_ANR1", "PB_FIELD_ANR2", "PB_FIELD_ANR3",
+       "PB_FIELD_EMAIL1", "PB_FIELD_EMAIL2", "PB_FIELD_EMAIL3", "PB_FIELD_EMAIL4",
+       "PB_FIELD_SNE", "PB_FIELD_GRP", "PB_FIELD_PBC"
+};
+
+static const char *dbg_dbus_pb_ton_name[] = {
+       "PB_TON_UNKNOWN",
+       "PB_TON_INTERNATIONAL",
+       "PB_TON_NATIONAL",
+       "PB_TON_NETWORK_SPECIFIC",
+       "PB_TON_DEDICATED_ACCESS",
+       "PB_TON_ALPHA_NUMERIC",
+       "PB_TON_ABBREVIATED_NUMBER",
+       "PB_TON_RESERVED_FOR_EXT"
+};
+
+#define DBUS_PBM_GET_CO_PBM(invocation, co_pbm, server) do { \
        co_pbm = __get_pbm_co_by_cp_name(server, GET_CP_NAME(invocation)); \
        if (!co_pbm) { \
                err("[%s] PBM Core object is NULL", GET_CP_NAME(invocation)); \
                FAIL_RESPONSE(invocation, DEFAULT_MSG_REQ_FAILED); \
                return TRUE; \
        } \
-}
+} while (0)
 
 static CoreObject *__get_pbm_co_by_cp_name(Server *server, char *cp_name)
 {
@@ -72,7 +80,8 @@ static CoreObject *__get_pbm_co_by_cp_name(Server *server, char *cp_name)
        return tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_PHONEBOOK);
 }
 
-static gboolean on_phonebook_get_init_status(TelephonyPhonebook *phonebook, GDBusMethodInvocation *invocation, gpointer user_data)
+static gboolean on_phonebook_get_init_status(TelephonyPhonebook *phonebook,
+       GDBusMethodInvocation *invocation, gpointer user_data)
 {
        struct custom_data *ctx = user_data;
        gboolean pb_status = FALSE;
@@ -83,11 +92,27 @@ static gboolean on_phonebook_get_init_status(TelephonyPhonebook *phonebook, GDBu
        if (!check_access_control(p_cynara, invocation, AC_PHONEBOOK, "r"))
                return TRUE;
 
-       DBUS_PBM_GET_COPBM(invocation, co_pb, ctx->server);
-
+       DBUS_PBM_GET_CO_PBM(invocation, co_pb, ctx->server);
        pb_status = tcore_phonebook_get_status(co_pb);
-       list = tcore_phonebook_get_support_list(co_pb);
+       if (pb_status == FALSE) {
+               /*
+                *Phonebook is NOT initialized
+                */
+               dbg("pb_init is not completed yet.");
 
+               telephony_phonebook_complete_get_init_status(phonebook,
+                       invocation, pb_status,
+                       FALSE, /* FDN */
+                       FALSE, /* ADN */
+                       FALSE, /* SDN */
+                       FALSE, /* USIM */
+                       FALSE, /* AAS */
+                       FALSE); /* GAS */
+
+               return TRUE;
+       }
+
+       list = tcore_phonebook_get_support_list(co_pb);
        if (!list) {
                err("Supported phonebook list is NULL");
                FAIL_RESPONSE(invocation, DEFAULT_MSG_REQ_FAILED);
@@ -95,28 +120,28 @@ static gboolean on_phonebook_get_init_status(TelephonyPhonebook *phonebook, GDBu
        }
 
        dbg("[%s] fdn[%d],adn[%d],sdn[%d],usim[%d],aas[%d],gas[%d]",
-               GET_CP_NAME(invocation), list->b_fdn, list->b_adn, list->b_sdn, list->b_usim, list->b_aas, list->b_gas);
-
-       telephony_phonebook_complete_get_init_status(phonebook, invocation,
-                       pb_status,
-                       list->b_fdn,
-                       list->b_adn,
-                       list->b_sdn,
-                       list->b_usim,
-                       list->b_aas,
-                       list->b_gas);
-
+               GET_CP_NAME(invocation),
+               list->b_fdn, list->b_adn, list->b_sdn,
+               list->b_usim, list->b_aas, list->b_gas);
+
+       telephony_phonebook_complete_get_init_status(phonebook,
+               invocation, pb_status,
+               list->b_fdn,
+               list->b_adn,
+               list->b_sdn,
+               list->b_usim,
+               list->b_aas,
+               list->b_gas);
        g_free(list);
 
        return TRUE;
 }
 
-static gboolean on_phonebook_get_count(TelephonyPhonebook *phonebook, GDBusMethodInvocation *invocation, gint arg_req_type, gpointer user_data)
+static gboolean on_phonebook_get_count(TelephonyPhonebook *phonebook,
+       GDBusMethodInvocation *invocation, gint req_type, gpointer user_data)
 {
        struct custom_data *ctx = user_data;
-       UserRequest *ur = NULL;
-       TReturn ret;
-       struct treq_phonebook_get_count pb_count;
+       struct treq_phonebook_get_count req;
        CoreObject *co_pb = NULL;
        gboolean pb_status = FALSE;
        cynara *p_cynara = (ctx) ? ctx->p_cynara : NULL;
@@ -124,36 +149,36 @@ static gboolean on_phonebook_get_count(TelephonyPhonebook *phonebook, GDBusMetho
        if (!check_access_control(p_cynara, invocation, AC_PHONEBOOK, "r"))
                return TRUE;
 
-       DBUS_PBM_GET_COPBM(invocation, co_pb, ctx->server);
-
+       DBUS_PBM_GET_CO_PBM(invocation, co_pb, ctx->server);
        pb_status = tcore_phonebook_get_status(co_pb);
        if (pb_status == FALSE) {
                dbg("pb_init is not completed yet.");
-               telephony_phonebook_complete_get_count(phonebook, invocation, PB_ACCESS_CONDITION_NOT_SATISFIED, 0, 0, 0);
+
+               telephony_phonebook_complete_get_count(phonebook,
+                       invocation, PB_ACCESS_CONDITION_NOT_SATISFIED, 0, 0, 0);
+
                return TRUE;
        }
 
-       ur = MAKE_UR(ctx, phonebook, invocation);
-       memset(&pb_count, 0, sizeof(struct treq_phonebook_get_count));
+       memset(&req, 0x0, sizeof(struct treq_phonebook_get_count));
+
+       req.phonebook_type = req_type;
+       dbg("[%s] req phonebook_type[%d][%s]", GET_CP_NAME(invocation),
+               req.phonebook_type, dbg_dbus_pb_type_name[req.phonebook_type]);
+
+       /* Dispatch request */
+       dtapi_dispatch_request(ctx, phonebook, invocation,
+               TREQ_PHONEBOOK_GETCOUNT,
+               &req, sizeof(struct treq_phonebook_get_count));
 
-       pb_count.phonebook_type = arg_req_type;
-       dbg("[%s] req phonebook_type[%d][%s]", GET_CP_NAME(invocation), pb_count.phonebook_type, dbg_dbus_pb_type_name[pb_count.phonebook_type]);
-       tcore_user_request_set_data(ur, sizeof(struct treq_phonebook_get_count), &pb_count);
-       tcore_user_request_set_command(ur, TREQ_PHONEBOOK_GETCOUNT);
-       ret = tcore_communicator_dispatch_request(ctx->comm, ur);
-       if (ret != TCORE_RETURN_SUCCESS) {
-               FAIL_RESPONSE(invocation, DEFAULT_MSG_REQ_FAILED);
-               tcore_user_request_unref(ur);
-       }
        return TRUE;
 }
 
-static gboolean on_phonebook_get_info(TelephonyPhonebook *phonebook, GDBusMethodInvocation *invocation, gint arg_req_type, gpointer user_data)
+static gboolean on_phonebook_get_info(TelephonyPhonebook *phonebook,
+       GDBusMethodInvocation *invocation, gint req_type, gpointer user_data)
 {
        struct custom_data *ctx = user_data;
-       UserRequest *ur = NULL;
-       TReturn ret;
-       struct treq_phonebook_get_info pb_info;
+       struct treq_phonebook_get_info req;
        CoreObject *co_pb = NULL;
        gboolean pb_status = FALSE;
        cynara *p_cynara = (ctx) ? ctx->p_cynara : NULL;
@@ -161,37 +186,37 @@ static gboolean on_phonebook_get_info(TelephonyPhonebook *phonebook, GDBusMethod
        if (!check_access_control(p_cynara, invocation, AC_PHONEBOOK, "r"))
                return TRUE;
 
-       DBUS_PBM_GET_COPBM(invocation, co_pb, ctx->server);
-
+       DBUS_PBM_GET_CO_PBM(invocation, co_pb, ctx->server);
        pb_status = tcore_phonebook_get_status(co_pb);
        if (pb_status == FALSE) {
                dbg("pb_init is not completed yet.");
-               telephony_phonebook_complete_get_info(phonebook, invocation, PB_ACCESS_CONDITION_NOT_SATISFIED, 0, 0, 0, 0, 0, 0);
+
+               telephony_phonebook_complete_get_info(phonebook, invocation,
+                       PB_ACCESS_CONDITION_NOT_SATISFIED, 0, 0, 0, 0, 0, 0);
+
                return TRUE;
        }
 
-       ur = MAKE_UR(ctx, phonebook, invocation);
-       memset(&pb_info, 0, sizeof(struct treq_phonebook_get_info));
+       memset(&req, 0x0, sizeof(struct treq_phonebook_get_info));
 
-       pb_info.phonebook_type = arg_req_type;
-       dbg("[%s] req phonebook_type[%d][%s]", GET_CP_NAME(invocation), pb_info.phonebook_type, dbg_dbus_pb_type_name[pb_info.phonebook_type]);
-       tcore_user_request_set_data(ur, sizeof(struct treq_phonebook_get_info), &pb_info);
-       tcore_user_request_set_command(ur, TREQ_PHONEBOOK_GETMETAINFO);
-       ret = tcore_communicator_dispatch_request(ctx->comm, ur);
-       if (ret != TCORE_RETURN_SUCCESS) {
-               FAIL_RESPONSE(invocation, DEFAULT_MSG_REQ_FAILED);
-               dbg("[ error ] tcore_communicator_dispatch_request() : (0x%x)", ret);
-               tcore_user_request_unref(ur);
-       }
+       req.phonebook_type = req_type;
+
+       dbg("[%s] req phonebook_type[%d][%s]", GET_CP_NAME(invocation),
+               req.phonebook_type,
+               dbg_dbus_pb_type_name[req.phonebook_type]);
+
+       /* Dispatch request */
+       dtapi_dispatch_request(ctx, phonebook, invocation,
+               TREQ_PHONEBOOK_GETMETAINFO,
+               &req, sizeof(struct treq_phonebook_get_info));
 
        return TRUE;
 }
 
-static gboolean on_phonebook_get_usim_info(TelephonyPhonebook *phonebook, GDBusMethodInvocation *invocation, gpointer user_data)
+static gboolean on_phonebook_get_usim_info(TelephonyPhonebook *phonebook,
+       GDBusMethodInvocation *invocation, gpointer user_data)
 {
        struct custom_data *ctx = user_data;
-       UserRequest *ur = NULL;
-       TReturn ret;
        CoreObject *co_pb = NULL;
        gboolean pb_status = FALSE;
        cynara *p_cynara = (ctx) ? ctx->p_cynara : NULL;
@@ -199,39 +224,39 @@ static gboolean on_phonebook_get_usim_info(TelephonyPhonebook *phonebook, GDBusM
        if (!check_access_control(p_cynara, invocation, AC_PHONEBOOK, "r"))
                return TRUE;
 
-       DBUS_PBM_GET_COPBM(invocation, co_pb, ctx->server);
+       DBUS_PBM_GET_CO_PBM(invocation, co_pb, ctx->server);
 
        pb_status = tcore_phonebook_get_status(co_pb);
-
        if (pb_status == FALSE) {
                GVariant *gv = NULL;
                GVariantBuilder b;
+
                dbg("pb_init is not completed yet.");
+
                g_variant_builder_init(&b, G_VARIANT_TYPE("aa{sv}"));
                gv = g_variant_builder_end(&b);
-               telephony_phonebook_complete_get_usim_meta_info(phonebook, invocation, PB_ACCESS_CONDITION_NOT_SATISFIED, gv);
+
+               telephony_phonebook_complete_get_usim_meta_info(phonebook, invocation,
+                       PB_ACCESS_CONDITION_NOT_SATISFIED, gv);
+
                return TRUE;
        }
 
-       ur = MAKE_UR(ctx, phonebook, invocation);
-       tcore_user_request_set_data(ur, 0, NULL);
-       tcore_user_request_set_command(ur, TREQ_PHONEBOOK_GETUSIMINFO);
-       ret = tcore_communicator_dispatch_request(ctx->comm, ur);
-       if (ret != TCORE_RETURN_SUCCESS) {
-               FAIL_RESPONSE(invocation, DEFAULT_MSG_REQ_FAILED);
-               dbg("[ error ] tcore_communicator_dispatch_request() : (0x%x)", ret);
-               tcore_user_request_unref(ur);
-       }
+       /* Dispatch request */
+       dtapi_dispatch_request(ctx, phonebook, invocation,
+               TREQ_PHONEBOOK_GETUSIMINFO,
+               NULL, 0);
+
        return TRUE;
 }
 
-static gboolean on_phonebook_read_record(TelephonyPhonebook *phonebook, GDBusMethodInvocation *invocation,
-               gint arg_req_type, gint arg_index, gpointer user_data)
+static gboolean on_phonebook_read_record(TelephonyPhonebook *phonebook,
+       GDBusMethodInvocation *invocation,
+       gint req_type, gint index,
+       gpointer user_data)
 {
        struct custom_data *ctx = user_data;
-       UserRequest *ur = NULL;
-       TReturn ret;
-       struct treq_phonebook_read_record pb_read;
+       struct treq_phonebook_read_record req;
        CoreObject *co_pb = NULL;
        gboolean pb_status = FALSE;
        cynara *p_cynara = (ctx) ? ctx->p_cynara : NULL;
@@ -239,48 +264,51 @@ static gboolean on_phonebook_read_record(TelephonyPhonebook *phonebook, GDBusMet
        if (!check_access_control(p_cynara, invocation, AC_PHONEBOOK, "r"))
                return TRUE;
 
-       DBUS_PBM_GET_COPBM(invocation, co_pb, ctx->server);
+       DBUS_PBM_GET_CO_PBM(invocation, co_pb, ctx->server);
        pb_status = tcore_phonebook_get_status(co_pb);
-
        if (pb_status == FALSE) {
                dbg("pb_init is not completed yet.");
-               telephony_phonebook_complete_read_record(phonebook, invocation, PB_ACCESS_CONDITION_NOT_SATISFIED,
-                               0, 0, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 0, NULL, NULL, NULL, NULL, 0);
+
+               telephony_phonebook_complete_read_record(phonebook, invocation,
+                       PB_ACCESS_CONDITION_NOT_SATISFIED,
+                       0, 0, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 0, NULL,
+                       0, NULL, 0, NULL, NULL, NULL, NULL, 0);
+
                return TRUE;
        }
 
-       ur = MAKE_UR(ctx, phonebook, invocation);
-       memset(&pb_read, 0, sizeof(struct treq_phonebook_read_record));
+       memset(&req, 0x0, sizeof(struct treq_phonebook_read_record));
 
-       pb_read.index = (unsigned short)arg_index;
-       pb_read.phonebook_type = arg_req_type;
-       dbg("[%s] req phonebook_type[%d][%s] index[%d]",
-               GET_CP_NAME(invocation), pb_read.phonebook_type, dbg_dbus_pb_type_name[pb_read.phonebook_type], pb_read.index);
+       req.index = (unsigned short)index;
+       req.phonebook_type = req_type;
+
+       dbg("[%s] req phonebook_type[%d][%s] index[%d]", GET_CP_NAME(invocation),
+               req.phonebook_type,
+               dbg_dbus_pb_type_name[req.phonebook_type], req.index);
+
+       /* Dispatch request */
+       dtapi_dispatch_request(ctx, phonebook, invocation,
+               TREQ_PHONEBOOK_READRECORD,
+               &req, sizeof(struct treq_phonebook_read_record));
 
-       tcore_user_request_set_data(ur, sizeof(struct treq_phonebook_read_record), &pb_read);
-       tcore_user_request_set_command(ur, TREQ_PHONEBOOK_READRECORD);
-       ret = tcore_communicator_dispatch_request(ctx->comm, ur);
-       if (ret != TCORE_RETURN_SUCCESS) {
-               FAIL_RESPONSE(invocation, DEFAULT_MSG_REQ_FAILED);
-               dbg("[ error ] tcore_communicator_dispatch_request() : (0x%x)", ret);
-               tcore_user_request_unref(ur);
-       }
        return TRUE;
 }
 
-static gboolean on_phonebook_update_record(TelephonyPhonebook *phonebook, GDBusMethodInvocation *invocation,
-               gint arg_type, gint arg_index, const gchar *arg_name, gint arg_dcs,
-               const gchar *arg_number, gint arg_ton,
-               const gchar *arg_sne, gint arg_sne_dcs,
-               const gchar *arg_number2, gint arg_number2_ton,
-               const gchar *arg_number3, gint arg_number3_ton, const gchar *arg_number4, gint arg_number4_ton,
-               const gchar *arg_email1, const gchar *arg_email2, const gchar *arg_email3, const gchar *arg_email4,
-               gint arg_group_index, gpointer user_data)
+static gboolean on_phonebook_update_record(TelephonyPhonebook *phonebook,
+       GDBusMethodInvocation *invocation,
+       gint type, gint index,
+       const gchar *name, gint dcs,
+       const gchar *number, gint ton,
+       const gchar *sne, gint sne_dcs,
+       const gchar *number2, gint number2_ton,
+       const gchar *number3, gint number3_ton,
+       const gchar *number4, gint number4_ton,
+       const gchar *email1, const gchar *email2,
+       const gchar *email3, const gchar *email4,
+       gint group_index, gpointer user_data)
 {
        struct custom_data *ctx = user_data;
-       UserRequest *ur = NULL;
-       TReturn ret;
-       struct treq_phonebook_update_record pb_update;
+       struct treq_phonebook_update_record req;
        CoreObject *co_pb = NULL;
        gboolean pb_status = FALSE;
        int temp_len = 0;
@@ -289,95 +317,110 @@ static gboolean on_phonebook_update_record(TelephonyPhonebook *phonebook, GDBusM
        if (!check_access_control(p_cynara, invocation, AC_PHONEBOOK, "x"))
                return TRUE;
 
-       DBUS_PBM_GET_COPBM(invocation, co_pb, ctx->server);
-
+       DBUS_PBM_GET_CO_PBM(invocation, co_pb, ctx->server);
        pb_status = tcore_phonebook_get_status(co_pb);
-
        if (pb_status == FALSE) {
                dbg("pb_init is not completed yet.");
-               telephony_phonebook_complete_update_record(phonebook, invocation, PB_ACCESS_CONDITION_NOT_SATISFIED);
+
+               telephony_phonebook_complete_update_record(phonebook, invocation,
+                       PB_ACCESS_CONDITION_NOT_SATISFIED);
+
                return TRUE;
        }
 
-       memset(&pb_update, 0, sizeof(struct treq_phonebook_update_record));
+       memset(&req, 0x0, sizeof(struct treq_phonebook_update_record));
 
        dbg("[%s] pb_type[%d] index[%d] name[%s] number[%s] email[%s]",
-               GET_CP_NAME(invocation), arg_type, arg_index, arg_name, arg_number, arg_email1);
+               GET_CP_NAME(invocation), type, index,
+               name, number, email1);
 
-       pb_update.index = (unsigned short)arg_index;
-       pb_update.phonebook_type = arg_type;
+       req.index = (unsigned short)index;
+       req.phonebook_type = type;
 
-       if (arg_name != NULL && strlen(arg_name)) {
-               pb_update.dcs = PB_TEXT_ASCII;
-               pb_update.name_len = strlen(arg_name);
-               if (pb_update.name_len > PHONEBOOK_NAME_BYTE_MAX)
-                       pb_update.name_len = PHONEBOOK_NAME_BYTE_MAX;
-               memcpy(pb_update.name, arg_name, pb_update.name_len);
+       if (name != NULL && strlen(name)) {
+               req.dcs = PB_TEXT_ASCII;
+               req.name_len = strlen(name);
+
+               if (req.name_len > PHONEBOOK_NAME_BYTE_MAX)
+                       req.name_len = PHONEBOOK_NAME_BYTE_MAX;
+
+               memcpy(req.name, name, req.name_len);
        }
-       if (arg_sne != NULL && strlen(arg_sne)) {
-               pb_update.sne_dcs = PB_TEXT_ASCII;
-               pb_update.sne_len = strlen(arg_sne);
-               if (pb_update.sne_len > PHONEBOOK_NAME_BYTE_MAX)
-                       pb_update.sne_len = PHONEBOOK_NAME_BYTE_MAX;
-               memcpy(pb_update.sne, arg_sne, pb_update.sne_len);
+
+       if (sne != NULL && strlen(sne)) {
+               req.sne_dcs = PB_TEXT_ASCII;
+               req.sne_len = strlen(sne);
+
+               if (req.sne_len > PHONEBOOK_NAME_BYTE_MAX)
+                       req.sne_len = PHONEBOOK_NAME_BYTE_MAX;
+
+               memcpy(req.sne, sne, req.sne_len);
        }
-       if (arg_number != NULL && (temp_len = strlen(arg_number))) {
-               pb_update.ton = arg_ton;
+
+       if (number != NULL && (temp_len = strlen(number))) {
+               req.ton = ton;
+
                if (temp_len > PHONEBOOK_NUMBER_BYTE_MAX)
                        temp_len = PHONEBOOK_NUMBER_BYTE_MAX;
-               memcpy(pb_update.number, arg_number, temp_len);
+
+               memcpy(req.number, number, temp_len);
        }
-       if (arg_number2 != NULL && (temp_len = strlen(arg_number2))) {
-               pb_update.anr1_ton = arg_number2_ton;
+
+       if (number2 != NULL && (temp_len = strlen(number2))) {
+               req.anr1_ton = number2_ton;
+
                if (temp_len > PHONEBOOK_NUMBER_BYTE_MAX)
                        temp_len = PHONEBOOK_NUMBER_BYTE_MAX;
-               memcpy(pb_update.anr1, arg_number2, temp_len);
+
+               memcpy(req.anr1, number2, temp_len);
        }
 
-       if (arg_number3 != NULL && (temp_len = strlen(arg_number3))) {
-               pb_update.anr2_ton = arg_number3_ton;
+       if (number3 != NULL && (temp_len = strlen(number3))) {
+               req.anr2_ton = number3_ton;
+
                if (temp_len > PHONEBOOK_NUMBER_BYTE_MAX)
                        temp_len = PHONEBOOK_NUMBER_BYTE_MAX;
-               memcpy(pb_update.anr2, arg_number3, temp_len);
+
+               memcpy(req.anr2, number3, temp_len);
        }
 
-       if (arg_number4 != NULL && (temp_len = strlen(arg_number4))) {
-               pb_update.anr3_ton = arg_number4_ton;
+       if (number4 != NULL && (temp_len = strlen(number4))) {
+               req.anr3_ton = number4_ton;
+
                if (temp_len > PHONEBOOK_NUMBER_BYTE_MAX)
                        temp_len = PHONEBOOK_NUMBER_BYTE_MAX;
-               memcpy(pb_update.anr3, arg_number4, temp_len);
-       }
 
-       if (arg_email1 != NULL && strlen(arg_email1)) {
-               pb_update.email1_len = strlen(arg_email1);
-               if (pb_update.email1_len > PHONEBOOK_EMAIL_BYTE_MAX)
-                       pb_update.email1_len = PHONEBOOK_EMAIL_BYTE_MAX;
-               memcpy(pb_update.email1, arg_email1, pb_update.email1_len);
+               memcpy(req.anr3, number4, temp_len);
        }
-       /* Additional e-mail fields (email 2,3,4) cannot be used to CP*/
 
-       pb_update.group_index = (unsigned short)arg_group_index;
+       if (email1 != NULL && strlen(email1)) {
+               req.email1_len = strlen(email1);
 
-       ur = MAKE_UR(ctx, phonebook, invocation);
-       tcore_user_request_set_data(ur, sizeof(struct treq_phonebook_update_record), &pb_update);
-       tcore_user_request_set_command(ur, TREQ_PHONEBOOK_UPDATERECORD);
-       ret = tcore_communicator_dispatch_request(ctx->comm, ur);
-       if (ret != TCORE_RETURN_SUCCESS) {
-               FAIL_RESPONSE(invocation, DEFAULT_MSG_REQ_FAILED);
-               dbg("[ error ] tcore_communicator_dispatch_request() : (0x%x)", ret);
-               tcore_user_request_unref(ur);
+               if (req.email1_len > PHONEBOOK_EMAIL_BYTE_MAX)
+                       req.email1_len = PHONEBOOK_EMAIL_BYTE_MAX;
+
+               memcpy(req.email1, email1, req.email1_len);
        }
 
+       /* Additional e-mail fields (email 2,3,4) cannot be used to CP */
+
+       req.group_index = (unsigned short)group_index;
+
+       /* Dispatch request */
+       dtapi_dispatch_request(ctx, phonebook, invocation,
+               TREQ_PHONEBOOK_UPDATERECORD,
+               &req, sizeof(struct treq_phonebook_update_record));
+
        return TRUE;
 }
 
-static gboolean on_phonebook_delete_record(TelephonyPhonebook *phonebook, GDBusMethodInvocation *invocation,
-               gint arg_type, gint arg_index, gpointer user_data)
+static gboolean on_phonebook_delete_record(TelephonyPhonebook *phonebook,
+       GDBusMethodInvocation *invocation,
+       gint type, gint index,
+       gpointer user_data)
 {
        struct custom_data *ctx = user_data;
-       UserRequest *ur = NULL;
-       TReturn ret;
-       struct treq_phonebook_delete_record pb_delete;
+       struct treq_phonebook_delete_record req;
        CoreObject *co_pb = NULL;
        gboolean pb_status = FALSE;
        cynara *p_cynara = (ctx) ? ctx->p_cynara : NULL;
@@ -385,37 +428,36 @@ static gboolean on_phonebook_delete_record(TelephonyPhonebook *phonebook, GDBusM
        if (!check_access_control(p_cynara, invocation, AC_PHONEBOOK, "x"))
                return TRUE;
 
-       DBUS_PBM_GET_COPBM(invocation, co_pb, ctx->server);
-
+       DBUS_PBM_GET_CO_PBM(invocation, co_pb, ctx->server);
        pb_status = tcore_phonebook_get_status(co_pb);
-
        if (pb_status == FALSE) {
                dbg("pb_init is not completed yet.");
-               telephony_phonebook_complete_delete_record(phonebook, invocation, PB_ACCESS_CONDITION_NOT_SATISFIED);
+
+               telephony_phonebook_complete_delete_record(phonebook, invocation,
+                       PB_ACCESS_CONDITION_NOT_SATISFIED);
+
                return TRUE;
        }
 
-       ur = MAKE_UR(ctx, phonebook, invocation);
-       memset(&pb_delete, 0, sizeof(struct treq_phonebook_delete_record));
+       memset(&req, 0x0, sizeof(struct treq_phonebook_delete_record));
 
-       pb_delete.index = (unsigned short)arg_index;
-       pb_delete.phonebook_type = arg_type;
-       dbg("[%s] req phonebook_type[%d][%s] index[%d]",
-               GET_CP_NAME(invocation), pb_delete.phonebook_type, dbg_dbus_pb_type_name[pb_delete.phonebook_type], pb_delete.index);
+       req.index = (unsigned short)index;
+       req.phonebook_type = type;
 
-       tcore_user_request_set_data(ur, sizeof(struct treq_phonebook_delete_record), &pb_delete);
-       tcore_user_request_set_command(ur, TREQ_PHONEBOOK_DELETERECORD);
-       ret = tcore_communicator_dispatch_request(ctx->comm, ur);
-       if (ret != TCORE_RETURN_SUCCESS) {
-               FAIL_RESPONSE(invocation, DEFAULT_MSG_REQ_FAILED);
-               dbg("[ error ] tcore_communicator_dispatch_request() : (0x%x)", ret);
-               tcore_user_request_unref(ur);
-       }
+       dbg("[%s] req phonebook_type[%d][%s] index[%d]", GET_CP_NAME(invocation),
+               req.phonebook_type,
+               dbg_dbus_pb_type_name[req.phonebook_type], req.index);
+
+       /* Dispatch request */
+       dtapi_dispatch_request(ctx, phonebook, invocation,
+               TREQ_PHONEBOOK_DELETERECORD,
+               &req, sizeof(struct treq_phonebook_delete_record));
 
        return TRUE;
 }
 
-gboolean dbus_plugin_setup_phonebook_interface(TelephonyObjectSkeleton *object, struct custom_data *ctx)
+gboolean dbus_plugin_setup_phonebook_interface(TelephonyObjectSkeleton *object,
+       struct custom_data *ctx)
 {
        TelephonyPhonebook *phonebook;
 
@@ -425,6 +467,9 @@ gboolean dbus_plugin_setup_phonebook_interface(TelephonyObjectSkeleton *object,
 
        dbg("phonebook = %p", phonebook);
 
+       /*
+        * Register signal handlers for Phonebook interface
+        */
        g_signal_connect(phonebook,
                "handle-get-init-status",
                G_CALLBACK(on_phonebook_get_init_status), ctx);
@@ -456,9 +501,9 @@ gboolean dbus_plugin_setup_phonebook_interface(TelephonyObjectSkeleton *object,
        return TRUE;
 }
 
-gboolean dbus_plugin_phonebook_response(struct custom_data *ctx, UserRequest *ur,
-               struct dbus_request_info *dbus_info, enum tcore_response_command command,
-               unsigned int data_len, const void *data)
+gboolean dbus_plugin_phonebook_response(struct custom_data *ctx,
+       UserRequest *ur, struct dbus_request_info *dbus_info,
+       enum tcore_response_command command, unsigned int data_len, const void *data)
 {
        const struct tresp_phonebook_get_count *resp_pbcnt = data;
        const struct tresp_phonebook_get_info *resp_entry = data;
@@ -473,9 +518,10 @@ gboolean dbus_plugin_phonebook_response(struct custom_data *ctx, UserRequest *ur
                dbg("[%s] GETCOUNT (type[%d][%s] used[%d]total[%d])",
                        cpname, resp_pbcnt->type, dbg_dbus_pb_type_name[resp_pbcnt->type],
                        resp_pbcnt->used_count, resp_pbcnt->total_count);
+
                telephony_phonebook_complete_get_count(dbus_info->interface_object, dbus_info->invocation,
                        resp_pbcnt->result, resp_pbcnt->type, resp_pbcnt->used_count, resp_pbcnt->total_count);
-               break;
+       break;
 
        case TRESP_PHONEBOOK_GETMETAINFO:
                dbg("[%s] GETMETAINFO (type[%d][%s])",
@@ -483,18 +529,20 @@ gboolean dbus_plugin_phonebook_response(struct custom_data *ctx, UserRequest *ur
                dbg("index(min[%d]max[%d]), num_max[%d] text(max[%d]used[%d])",
                        resp_entry->index_min, resp_entry->index_max, resp_entry->number_length_max,
                        resp_entry->text_length_max, resp_entry->used_count);
+
                telephony_phonebook_complete_get_info(dbus_info->interface_object, dbus_info->invocation,
                        resp_entry->result, resp_entry->type, resp_entry->index_min, resp_entry->index_max,
                        resp_entry->number_length_max, resp_entry->text_length_max, resp_entry->used_count);
-               break;
+       break;
 
        case TRESP_PHONEBOOK_GETUSIMINFO: {
                GVariant *gv = NULL;
                GVariantBuilder b;
                int i;
+
                dbg("[%s] GETUSIMINFO", cpname);
-               g_variant_builder_init(&b, G_VARIANT_TYPE("aa{sv}"));
 
+               g_variant_builder_init(&b, G_VARIANT_TYPE("aa{sv}"));
                for (i = 0; i < resp_capa->field_count; i++) {
                        g_variant_builder_open(&b, G_VARIANT_TYPE("a{sv}"));
                        dbg("type[%d][%s] index_max[%d] text_max[%d] used_count[%d]",
@@ -513,8 +561,8 @@ gboolean dbus_plugin_phonebook_response(struct custom_data *ctx, UserRequest *ur
 
                telephony_phonebook_complete_get_usim_meta_info(dbus_info->interface_object,
                        dbus_info->invocation, resp_capa->result, gv);
-               }
-               break;
+       }
+       break;
 
        case TRESP_PHONEBOOK_READRECORD: {
                unsigned char dest_pb_name[PHONEBOOK_NAME_BYTE_MAX + 1];
@@ -544,7 +592,9 @@ gboolean dbus_plugin_phonebook_response(struct custom_data *ctx, UserRequest *ur
                                memcpy(dest_pb_sne, resp_pbread->sne, resp_pbread->sne_len);
                        }
 
-                       if (strlen((const char*)resp_pbread->anr1) != 0 || strlen((const char*)resp_pbread->anr2) != 0 || strlen((const char*)resp_pbread->anr3) != 0) {
+                       if (strlen((const char*)resp_pbread->anr1) != 0
+                                       || strlen((const char*)resp_pbread->anr2) != 0
+                                       || strlen((const char*)resp_pbread->anr3) != 0) {
                                dbg("anr1:([%s],ton[%d][%s])", resp_pbread->anr1,
                                        resp_pbread->anr1_ton, dbg_dbus_pb_ton_name[resp_pbread->anr1_ton]);
                                dbg("anr2:([%s],ton[%d][%s])", resp_pbread->anr2,
@@ -552,10 +602,12 @@ gboolean dbus_plugin_phonebook_response(struct custom_data *ctx, UserRequest *ur
                                dbg("anr3:([%s],ton[%d][%s])", resp_pbread->anr3,
                                        resp_pbread->anr3_ton, dbg_dbus_pb_ton_name[resp_pbread->anr3_ton]);
                        }
+
                        if (resp_pbread->email1_len > 0) {
                                dbg("email1:[%s] len:[%d]", resp_pbread->email1, resp_pbread->email1_len);
                                memcpy(dest_pb_email1, resp_pbread->email1, resp_pbread->email1_len);
                        }
+
                        /* Additional e-mail fields (email 2,3,4) cannot be used to CP*/
                }
 
@@ -589,32 +641,34 @@ gboolean dbus_plugin_phonebook_response(struct custom_data *ctx, UserRequest *ur
                        (const gchar *)resp_pbread->email3,
                        (const gchar *)resp_pbread->email4,
                        resp_pbread->group_index);
-               }
-               break;
+       }
+       break;
 
        case TRESP_PHONEBOOK_UPDATERECORD:
                dbg("[%s] UPDATERECORD (result[%d])", cpname, resp_pbupdate->result);
+
                telephony_phonebook_complete_update_record(dbus_info->interface_object,
                        dbus_info->invocation, resp_pbupdate->result);
-               break;
+       break;
 
        case TRESP_PHONEBOOK_DELETERECORD:
                dbg("[%s] DELETERECORD (result[%d])", cpname, resp_pbdelete->result);
+
                telephony_phonebook_complete_delete_record(dbus_info->interface_object,
                        dbus_info->invocation, resp_pbdelete->result);
-               break;
+       break;
 
        default:
-               dbg("not handled cmd[0x%x]", command);
-               break;
+               err("Unhandled/Unknown Response: [0x%x]", command);
+       break;
        }
 
        return TRUE;
 }
 
-gboolean dbus_plugin_phonebook_notification(struct custom_data *ctx, CoreObject *source,
-               TelephonyObjectSkeleton *object, enum tcore_notification_command command,
-               unsigned int data_len, const void *data)
+gboolean dbus_plugin_phonebook_notification(struct custom_data *ctx,
+       CoreObject *source, TelephonyObjectSkeleton *object,
+       enum tcore_notification_command command, unsigned int data_len, const void *data)
 {
        TelephonyPhonebook *phonebook;
        const char *cp_name;
@@ -644,25 +698,26 @@ gboolean dbus_plugin_phonebook_notification(struct custom_data *ctx, CoreObject
                        n_pb_status->support_list.b_usim,
                        n_pb_status->support_list.b_aas,
                        n_pb_status->support_list.b_gas);
-               }
-               break;
+       }
+       break;
 
        case TNOTI_PHONEBOOK_CONTACT_CHANGE: {
                const struct tnoti_phonebook_contact_change *n_pb_contact_change = data;
 
                dbg("phonebook_type [%d] index [%d] operation [%d]",
-                       n_pb_contact_change->phonebook_type, n_pb_contact_change->index, n_pb_contact_change->operation);
+                       n_pb_contact_change->phonebook_type,
+                       n_pb_contact_change->index, n_pb_contact_change->operation);
 
                telephony_phonebook_emit_contact_change(phonebook,
                        n_pb_contact_change->phonebook_type,
                        n_pb_contact_change->index,
                        n_pb_contact_change->operation);
-               }
-               break;
+       }
+       break;
 
        default:
-               dbg("not handled cmd[0x%x]", command);
-               break;
+               err("Unhandled/Unknown Notification: [0x%x]", command);
+       break;
        }
 
        return TRUE;