2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
24 #include "contact-adaptor.h"
25 #include "contact-adaptor-log.h"
28 * Contact adaptor plugin
30 typedef struct contact_adaptor_plugin_s {
31 contact_adaptor_h adaptor; /* Adaptor */
32 char *path; /* Plugin library path */
33 contact_adaptor_plugin_handle_h handle; /* Plugin handle */
34 void *dl_handle; /* Plugin library handle */
35 int ref_counter; /* Plugin reference counter */
36 GMutex ref_counter_mutex; /* Plugin reference counter mutex */
37 contact_adaptor_plugin_listener_h plugin_listener; /* Plugin callback listener */
38 GMutex plugin_listener_mutex; /* Plugin callback listener mutex */
39 } contact_adaptor_plugin_t;
44 typedef struct contact_adaptor_s {
45 GMutex contact_adaptor_mutex; /* Adaptor mutex */
46 int started; /* Started flag */
47 char *plugins_dir; /* Plugins directory path */
48 GList *plugins; /* List of loaded plugins */
49 GMutex plugins_mutex; /* Plugin list mutex */
50 GList *adaptor_listeners; /* List of vservice channel listener (for now not effective) */
51 GMutex adaptor_listeners_mutex; /* Listener list mutex */
57 static contact_adaptor_plugin_h contact_adaptor_create_plugin(const char *plugin_path);
60 * Destroys plugin and deletes all resources associated with it
62 static void contact_adaptor_destroy_plugin(contact_adaptor_plugin_h plugin);
65 * Loads plugins from selected directory
67 static int contact_adaptor_load_plugins_from_directory(contact_adaptor_h adaptor,
68 const char *dir_path);
71 * Checks if plugin is loaded by selected plugin adaptor
73 static int contact_adaptor_has_plugin(contact_adaptor_h adaptor,
74 contact_adaptor_plugin_h plugin);
77 * Increases adaptor's plugin references counter
79 static void contact_adaptor_plugin_ref(contact_adaptor_plugin_h);
82 * Decreases adaptor's plugin references counter
84 static void contact_adaptor_plugin_unref(contact_adaptor_plugin_h);
87 * On message received callback for service adaptor
89 contact_adaptor_service_on_message_received_cb _service_adaptor_on_message_received = NULL;
92 * Callback on message received from plugin
95 contact_adaptor_on_message_received(void *user_data)
97 if (NULL != _service_adaptor_on_message_received) {
98 _service_adaptor_on_message_received(user_data);
102 /* /////////////////////////////////////////////////////////////
103 // Plugin create / destroy / ref. count / get plugin name
104 ///////////////////////////////////////////////////////////// */
109 static contact_adaptor_plugin_h contact_adaptor_create_plugin(const char *plugin_path)
111 contact_adaptor_debug("Create plugin");
113 if (NULL == plugin_path) {
114 contact_adaptor_error("Invalid argument");
118 void *dl_handle = dlopen(plugin_path, RTLD_LAZY);
119 if (NULL == dl_handle) {
120 contact_adaptor_error("Could not load plugin %s: %s", plugin_path, dlerror());
124 contact_adaptor_plugin_handle_h (*get_adaptee_handle)(void) = NULL;
126 get_adaptee_handle = (contact_adaptor_plugin_handle_h (*)(void))(dlsym(dl_handle, "create_plugin_handle"));
127 if (NULL == get_adaptee_handle) {
129 contact_adaptor_error("Could not get function pointer to create_plugin_handle");
134 contact_adaptor_plugin_handle_h handle = get_adaptee_handle();
135 plugin_req_exit_void();
137 if (NULL == handle) {
139 contact_adaptor_error("Could not get adaptee handle");
143 contact_adaptor_plugin_h plugin = (contact_adaptor_plugin_h) calloc(1, sizeof(contact_adaptor_plugin_t));
144 if (NULL == plugin) {
146 contact_adaptor_error("Could not create plugin object");
150 contact_adaptor_plugin_listener_h listener =
151 (contact_adaptor_plugin_listener_h) calloc(1, sizeof(contact_adaptor_plugin_listener_t));
152 if (NULL == listener) {
155 contact_adaptor_error("Could not create listener object");
159 plugin->path = g_strdup(plugin_path);
160 plugin->handle = handle;
161 plugin->dl_handle = dl_handle;
162 plugin->ref_counter = 0;
164 g_mutex_init(&plugin->ref_counter_mutex);
165 g_mutex_init(&plugin->plugin_listener_mutex);
167 listener->_on_message_received = contact_adaptor_on_message_received;
170 plugin->handle->set_listener(listener);
171 plugin_req_exit_void();
173 g_mutex_lock(&plugin->plugin_listener_mutex);
174 plugin->plugin_listener = listener;
175 g_mutex_unlock(&plugin->plugin_listener_mutex);
181 * Destroys plugin and deletes all resources associated with it
183 static void contact_adaptor_destroy_plugin(contact_adaptor_plugin_h plugin)
185 contact_adaptor_debug("Destroy plugin");
187 if (NULL == plugin) {
188 contact_adaptor_error("Invalid argument");
192 if (NULL != plugin->handle) {
193 plugin->handle->destroy_handle(plugin->handle);
195 g_mutex_lock(&plugin->plugin_listener_mutex);
197 plugin->handle->unset_listener();
198 plugin_req_exit_void();
199 g_mutex_unlock(&plugin->plugin_listener_mutex);
201 plugin->handle = NULL;
204 if (NULL != plugin->dl_handle) {
205 dlclose(plugin->dl_handle);
206 plugin->dl_handle = NULL;
216 * Loads plugins from selected directory
218 static int contact_adaptor_load_plugins_from_directory(contact_adaptor_h adaptor,
219 const char *dir_path)
221 contact_adaptor_debug("Load plugins from directory");
223 char *plugin_path = NULL;
225 struct dirent dir_entry, *result = NULL;
227 if ((NULL == adaptor) || (NULL == dir_path)) {
228 contact_adaptor_error("Invalid argument");
229 return CONTACT_ADAPTOR_ERROR_INVALID_ARGUMENT;
232 dir = opendir(dir_path);
234 contact_adaptor_error("Could not open dir path (%s)", dir_path);
235 return CONTACT_ADAPTOR_ERROR_NOT_FOUND;
238 int ret = CONTACT_ADAPTOR_ERROR_NONE;
239 while (0 == (readdir_r(dir, &dir_entry, &result))) {
241 if (NULL == result) {
242 contact_adaptor_error("Could not open directory %s", plugin_path);
246 if (dir_entry.d_type & DT_DIR) {
250 plugin_path = g_strconcat(dir_path, "/", dir_entry.d_name, NULL);
251 contact_adaptor_plugin_h plugin = contact_adaptor_create_plugin(plugin_path);
253 if (NULL != plugin) {
254 contact_adaptor_debug("Loaded plugin: %s", plugin_path);
255 plugin->adaptor = adaptor;
256 contact_adaptor_plugin_ref(plugin);
257 g_mutex_lock(&adaptor->plugins_mutex);
258 adaptor->plugins = g_list_append(adaptor->plugins, plugin);
259 g_mutex_unlock(&adaptor->plugins_mutex);
261 contact_adaptor_error("Could not load plugin %s", plugin_path);
268 contact_adaptor_debug("End load plugins from directory");
274 * Checks if plugin is loaded by selected plugin adaptor
276 static int contact_adaptor_has_plugin(contact_adaptor_h adaptor,
277 contact_adaptor_plugin_h plugin)
279 contact_adaptor_debug("Find plugin in plugin list");
281 if ((NULL == adaptor) || (NULL == plugin)) {
282 contact_adaptor_error("Invalid argument");
288 g_mutex_lock(&adaptor->plugins_mutex);
289 if (NULL != g_list_find(adaptor->plugins, plugin)) {
292 g_mutex_unlock(&adaptor->plugins_mutex);
298 * Increases adaptor's plugin references counter
300 static void contact_adaptor_plugin_ref(contact_adaptor_plugin_h plugin)
302 contact_adaptor_debug("Increase plugin reference count");
304 if (NULL == plugin) {
305 contact_adaptor_error("Invalid argument");
309 g_mutex_lock(&plugin->ref_counter_mutex);
310 plugin->ref_counter = plugin->ref_counter + 1;
311 contact_adaptor_info("ref_counter: %d", plugin->ref_counter);
312 g_mutex_unlock(&plugin->ref_counter_mutex);
316 * Decreases adaptor's plugin references counter
318 static void contact_adaptor_plugin_unref(contact_adaptor_plugin_h plugin)
320 contact_adaptor_debug("Decrease plugin reference count");
322 if (NULL == plugin) {
323 contact_adaptor_error("Invalid argument");
327 int should_destroy = 0;
329 g_mutex_lock(&plugin->ref_counter_mutex);
330 plugin->ref_counter = plugin->ref_counter - 1;
331 contact_adaptor_info("ref_counter: %d", plugin->ref_counter);
332 if (0 >= plugin->ref_counter) {
335 g_mutex_unlock(&plugin->ref_counter_mutex);
337 if (should_destroy) {
338 contact_adaptor_debug("Plugin is being destroyed");
339 contact_adaptor_destroy_plugin(plugin);
343 /* //////////////////////////////////////////////////////
344 // Mandatory: External adaptor management function
345 ////////////////////////////////////////////////////// */
348 * @brief Creates Contact Adaptor.
350 * @param[in] plugin_dir specifies directory path where plugins are stored
351 * @return contact_adaptor_h on success, otherwise NULL value
353 contact_adaptor_h contact_adaptor_create(const char *plugins_dir)
355 contact_adaptor_warning("Create contact adaptor");
357 contact_adaptor_h contact_adaptor = (contact_adaptor_h) malloc(sizeof(contact_adaptor_t));
358 if (NULL == contact_adaptor) {
362 contact_adaptor->started = 0;
363 contact_adaptor->plugins_dir = strdup(plugins_dir);
365 g_mutex_init(&contact_adaptor->contact_adaptor_mutex);
366 g_mutex_init(&contact_adaptor->plugins_mutex);
367 g_mutex_init(&contact_adaptor->adaptor_listeners_mutex);
369 g_mutex_lock(&contact_adaptor->adaptor_listeners_mutex);
370 contact_adaptor->adaptor_listeners = NULL;
371 g_mutex_unlock(&contact_adaptor->adaptor_listeners_mutex);
373 g_mutex_lock(&contact_adaptor->plugins_mutex);
374 contact_adaptor->plugins = NULL;
375 g_mutex_unlock(&contact_adaptor->plugins_mutex);
377 return contact_adaptor;
381 * @brief Destroys contact adaptor. If contact adaptor was started it is stopped first.
383 * @param[in] adaptor specifies contact adaptor handle to be destroyed
386 void contact_adaptor_destroy(contact_adaptor_h adaptor)
388 contact_adaptor_warning("Destroy contact adaptor");
390 if (NULL == adaptor) {
391 contact_adaptor_error("Invalid argument");
395 g_mutex_lock(&adaptor->contact_adaptor_mutex);
396 if (adaptor->started) {
397 contact_adaptor_error("Contact adaptor is running. Forcing stop before destroy");
398 contact_adaptor_stop(adaptor);
401 g_mutex_lock(&adaptor->plugins_mutex);
402 if (NULL != adaptor->plugins) {
403 g_list_free_full(adaptor->plugins, (GDestroyNotify) contact_adaptor_plugin_unref);
404 adaptor->plugins = NULL;
406 g_mutex_unlock(&adaptor->plugins_mutex);
408 g_mutex_lock(&adaptor->adaptor_listeners_mutex);
409 if (NULL != adaptor->adaptor_listeners) {
410 g_list_free(adaptor->adaptor_listeners);
411 adaptor->adaptor_listeners = NULL;
413 g_mutex_unlock(&adaptor->adaptor_listeners_mutex);
415 _service_adaptor_on_message_received = NULL;
417 free(adaptor->plugins_dir);
418 adaptor->plugins_dir = NULL;
420 g_mutex_unlock(&adaptor->contact_adaptor_mutex);
426 * @brief Starts contact adaptor and loads plugins that are found in contact_adaptor_create().
428 * @param[in] adaptor specifies contact adaptor handle
429 * @return 0 on success, otherwise a positive error value
430 * @retval error code defined in contact_error_code_e - CONTACT_ADAPTOR_ERROR_NONE if successful
432 int contact_adaptor_start(contact_adaptor_h adaptor)
434 contact_adaptor_warning("Start contact adaptor");
436 if (NULL == adaptor) {
437 contact_adaptor_error("Invalid argument");
438 return CONTACT_ADAPTOR_ERROR_INVALID_ARGUMENT;
441 g_mutex_lock(&adaptor->contact_adaptor_mutex);
442 int result = CONTACT_ADAPTOR_ERROR_NONE;
443 if (adaptor->started) {
444 contact_adaptor_error("Contact adaptor is already started");
445 result = CONTACT_ADAPTOR_ERROR_START;
447 adaptor->started = 1;
448 result = contact_adaptor_load_plugins_from_directory(adaptor, adaptor->plugins_dir);
449 if (CONTACT_ADAPTOR_ERROR_NONE != result) {
450 adaptor->started = 0;
451 contact_adaptor_error("Could not load plugins from directory");
453 contact_adaptor_debug("Contact adaptor started successfully");
456 g_mutex_unlock(&adaptor->contact_adaptor_mutex);
462 * @brief Stops contact adaptor.
464 * @param[in] adaptor specifies contact adaptor handle
465 * @return 0 on success, otherwise a positive error value
466 * @retval error code defined in contact_error_code_e - CONTACT_ADAPTOR_ERROR_NONE if successful
468 int contact_adaptor_stop(contact_adaptor_h adaptor)
470 contact_adaptor_warning("Stop contact adaptor");
472 if (NULL == adaptor) {
473 contact_adaptor_error("Invalid argument");
474 return CONTACT_ADAPTOR_ERROR_INVALID_ARGUMENT;
477 g_mutex_lock(&adaptor->contact_adaptor_mutex);
478 int result = CONTACT_ADAPTOR_ERROR_NONE;
479 if (!adaptor->started) {
480 result = CONTACT_ADAPTOR_ERROR_START;
482 if (NULL != adaptor->plugins) {
483 g_mutex_lock(&adaptor->plugins_mutex);
484 g_list_free_full(adaptor->plugins, (GDestroyNotify) contact_adaptor_plugin_unref);
485 adaptor->plugins = NULL;
486 g_mutex_unlock(&adaptor->plugins_mutex);
488 adaptor->started = 0;
489 contact_adaptor_debug("Contact adaptor stopped");
492 g_mutex_unlock(&adaptor->contact_adaptor_mutex);
497 * @brief Registers plugin state listener
499 * @param[in] adaptor specifies contact adaptor handle
500 * @param[in] listener specifies contact adaptor listener handle
501 * @return 0 on success, otherwise a positive error value
502 * @retval error code defined in contact_error_code_e - CONTACT_ADAPTOR_ERROR_NONE if successful
504 int contact_adaptor_register_listener(contact_adaptor_h adaptor,
505 contact_adaptor_listener_h listener)
507 contact_adaptor_warning("Register contact adaptor listener");
509 if ((NULL == adaptor) || (NULL == listener)) {
510 contact_adaptor_error("Invalid argument");
511 return CONTACT_ADAPTOR_ERROR_INVALID_ARGUMENT;
514 g_mutex_lock(&adaptor->adaptor_listeners_mutex);
516 adaptor->adaptor_listeners = g_list_append(adaptor->adaptor_listeners, listener);
518 g_mutex_unlock(&adaptor->adaptor_listeners_mutex);
520 _service_adaptor_on_message_received =
521 (contact_adaptor_service_on_message_received_cb) listener->_on_message_received;
523 return CONTACT_ADAPTOR_ERROR_NONE;
527 * @brief Unregisters plugin state listener
529 * @param[in] adaptor specifies contact adaptor handle
530 * @param[in] listener specifies contact adaptor listener handle
531 * @return 0 on success, otherwise a positive error value
532 * @retval error code defined in contact_error_code_e - CONTACT_ADAPTOR_ERROR_NONE if successful
534 int contact_adaptor_unregister_listener(contact_adaptor_h adaptor,
535 contact_adaptor_listener_h listener)
537 contact_adaptor_warning("Deregister contact adaptor listener");
539 if (NULL == adaptor) {
540 contact_adaptor_error("Invalid argument (adaptor)");
541 if (NULL != listener) {
545 return CONTACT_ADAPTOR_ERROR_INVALID_ARGUMENT;
547 if (NULL == listener) {
548 contact_adaptor_error("Invalid argument (listener)");
549 return CONTACT_ADAPTOR_ERROR_INVALID_ARGUMENT;
552 g_mutex_lock(&adaptor->adaptor_listeners_mutex);
554 if (NULL == g_list_find(adaptor->adaptor_listeners, listener)) {
555 g_mutex_unlock(&adaptor->adaptor_listeners_mutex);
556 contact_adaptor_error("Could not find listener");
558 return CONTACT_ADAPTOR_ERROR_NOT_FOUND;
561 adaptor->adaptor_listeners = g_list_remove(adaptor->adaptor_listeners, listener);
564 g_mutex_unlock(&adaptor->adaptor_listeners_mutex);
566 _service_adaptor_on_message_received = NULL;
568 return CONTACT_ADAPTOR_ERROR_NONE;
571 /* //////////////////////////////////////////////////////
572 // Plugin context create / destroy
573 ////////////////////////////////////////////////////// */
576 * @brief Creates plugin context
578 * @param[in] plugin specifies contact adaptor plugin handle
579 * @param[in] duid specifies device unique ID
580 * @param[in] access_token specifies access token issued by Auth Adaptor
581 * @return contact_adaptor_plugin_context_h on success, otherwise NULL value
583 contact_adaptor_plugin_context_h contact_adaptor_create_plugin_context(contact_adaptor_plugin_h plugin,
585 const char *access_token,
586 const char *service_name)
588 contact_adaptor_warning("Create plugin context");
590 if ((NULL == plugin) || (NULL == duid) || (NULL == access_token) || (NULL == service_name)) {
591 contact_adaptor_error("Invalid argument: %s, %s", duid, access_token);
595 if (NULL != plugin->handle) {
596 contact_adaptor_plugin_context_h plugin_context = NULL;
599 plugin->handle->create_context(&plugin_context, duid, access_token);
600 plugin_req_exit_void();
602 plugin_context->plugin_uri = strdup(plugin->handle->plugin_uri);
603 plugin_context->service_name = strdup(service_name);
604 return plugin_context;
606 contact_adaptor_error("Plugin handle is null");
613 * @brief Destroys plugin context.
615 * @param[in] plugin specifies contact adaptor plugin handle
616 * @param[in] context specifies contact adaptor plugin context handle
619 void contact_adaptor_destroy_plugin_context(contact_adaptor_plugin_h plugin,
620 contact_adaptor_plugin_context_h plugin_context)
622 contact_adaptor_warning("Destroy plugin context");
624 if ((NULL == plugin) || (NULL == plugin_context)) {
625 contact_adaptor_error("Invalid argument");
629 if (NULL != plugin->handle) {
630 free(plugin_context->plugin_uri);
631 plugin_context->plugin_uri = NULL;
632 free(plugin_context->service_name);
633 plugin_context->service_name = NULL;
636 plugin->handle->destroy_context(plugin_context);
637 plugin_req_exit_void();
639 contact_adaptor_error("Plugin handle is null");
643 /* //////////////////////////////////////////////////////
644 // Get plugin by plugin name
645 ////////////////////////////////////////////////////// */
648 * @brief Gets plugin with specified unique name
650 * @param[in] adaptor specifies contact adaptor handle
651 * @param[in] plugin_name specifies plugin name to be searched for
652 * @return contact_adaptor_plugin_h on success, otherwise NULL value
654 contact_adaptor_plugin_h contact_adaptor_get_plugin_by_name(contact_adaptor_h adaptor,
655 const char *plugin_name)
657 contact_adaptor_warning("Get plugin by name: %s", plugin_name);
659 if ((NULL == adaptor) || (NULL == plugin_name)) {
660 contact_adaptor_error("Invalid argument");
664 contact_adaptor_plugin_h plugin = NULL;
665 g_mutex_lock(&adaptor->plugins_mutex);
666 int count = g_list_length(adaptor->plugins);
668 for (i = 0; i < count; i++) {
669 contact_adaptor_plugin_h temp_plugin = g_list_nth_data(adaptor->plugins, i);
670 if (NULL != temp_plugin) {
671 if (0 == strcmp(temp_plugin->handle->plugin_uri, plugin_name)) {
672 contact_adaptor_plugin_ref(temp_plugin);
673 plugin = temp_plugin;
674 contact_adaptor_debug("Plugin is found by name");
675 g_mutex_unlock(&adaptor->plugins_mutex);
680 g_mutex_unlock(&adaptor->plugins_mutex);
682 if (NULL == plugin) {
683 contact_adaptor_debug("Plugin is not found by name");
689 /* //////////////////////////////////////////////////////
690 // Plugin load / unload / get plugin list
691 ////////////////////////////////////////////////////// */
694 * @brief Loads plugin from selected path
696 * @param[in] adaptor specifies contact adaptor handle
697 * @param[in] plugin_path specifies plugin's saved path
698 * @return 0 on success, otherwise a positive error value
699 * @retval error code defined in contact_error_code_e - CONTACT_ADAPTOR_ERROR_NONE if successful
701 int contact_adaptor_load_plugin(contact_adaptor_h adaptor,
702 const char *plugin_path)
704 contact_adaptor_warning("Load plugin by plugin path: %s", plugin_path);
706 if ((NULL == adaptor) || (NULL == plugin_path)) {
707 contact_adaptor_error("Invalid argument");
708 return CONTACT_ADAPTOR_ERROR_INVALID_ARGUMENT;
711 if (!adaptor->started) {
712 contact_adaptor_error("Contact adaptor is not started");
713 return CONTACT_ADAPTOR_ERROR_START;
716 contact_adaptor_plugin_h plugin = contact_adaptor_create_plugin(plugin_path);
717 if (NULL == plugin) {
718 contact_adaptor_error("Could not load plugin %s", plugin_path);
719 return CONTACT_ADAPTOR_ERROR_CREATE;
722 plugin->adaptor = adaptor;
723 contact_adaptor_plugin_ref(plugin);
725 g_mutex_lock(&adaptor->plugins_mutex);
726 adaptor->plugins = g_list_append(adaptor->plugins, plugin);
727 g_mutex_unlock(&adaptor->plugins_mutex);
729 return CONTACT_ADAPTOR_ERROR_NONE;
733 * @brief Unloads selected plugin
735 * @param[in] adaptor specifies contact adaptor handle
736 * @param[in] plugin specifies contact adaptor plugin handle
737 * @return 0 on success, otherwise a positive error value
738 * @retval error code defined in contact_error_code_e - CONTACT_ADAPTOR_ERROR_NONE if successful
740 int contact_adaptor_unload_plugin(contact_adaptor_h adaptor,
741 contact_adaptor_plugin_h plugin)
743 contact_adaptor_warning("Unload plugin");
745 if ((NULL == adaptor) || (NULL == plugin)) {
746 contact_adaptor_error("Invalid argument");
747 return CONTACT_ADAPTOR_ERROR_INVALID_ARGUMENT;
750 if (!adaptor->started) {
751 contact_adaptor_error("Contact adaptor is not started");
752 return CONTACT_ADAPTOR_ERROR_START;
755 if (!contact_adaptor_has_plugin(adaptor, plugin)) {
756 contact_adaptor_error("Contact adaptor has no plugin");
757 return CONTACT_ADAPTOR_ERROR_NOT_FOUND;
760 plugin->adaptor = NULL;
762 g_mutex_lock(&adaptor->plugins_mutex);
763 adaptor->plugins = g_list_remove(adaptor->plugins, plugin);
764 g_mutex_unlock(&adaptor->plugins_mutex);
766 contact_adaptor_plugin_unref(plugin);
768 return CONTACT_ADAPTOR_ERROR_NONE;
772 * @brief Get plugin list of contact adaptor handle has
774 * @param[in] adaptor specifies contact adaptor handle
775 * @return GList pointer on success, otherwise NULL value
777 GList *contact_adaptor_get_plugins(contact_adaptor_h adaptor)
779 contact_adaptor_warning("Get plugin list");
781 if (NULL == adaptor) {
782 contact_adaptor_error("Invalid argument");
786 GList *plugins = NULL;
788 g_mutex_lock(&adaptor->plugins_mutex);
789 int plugins_count = g_list_length(adaptor->plugins);
791 for (i = 0; i < plugins_count; i++) {
792 contact_adaptor_plugin_h plugin = g_list_nth_data(adaptor->plugins, i);
793 if (NULL != plugin) {
794 contact_adaptor_plugin_ref(plugin);
795 plugins = g_list_append(plugins, plugin);
798 g_mutex_unlock(&adaptor->plugins_mutex);
804 * @brief Refresh access token was issued from auth-adaptor
806 * @param[in] context specifies Contact Adaptor Plugin Context handle
807 * @param[in] new_access_token specifies New access token
808 * @return contact_adaptor_error_code_h on success, otherwise NULL value
811 contact_error_code_t contact_adaptor_refresh_access_token(contact_adaptor_plugin_context_h context,
812 const char *new_access_token)
814 if ((NULL == context) || (NULL == new_access_token) || (0 >= strlen(new_access_token))) {
815 return CONTACT_ADAPTOR_ERROR_INVALID_ARGUMENT;
817 contact_adaptor_debug("New access token : %s", new_access_token);
819 free(context->access_token);
820 context->access_token = NULL;
821 context->access_token = strdup(new_access_token);
823 return CONTACT_ADAPTOR_ERROR_NONE;
827 contact_error_code_t contact_adaptor_refresh_uid(contact_adaptor_plugin_context_h context,
830 if ((NULL == context) || (NULL == new_uid) || (0 >= strlen(new_uid))) {
831 return CONTACT_ADAPTOR_ERROR_INVALID_ARGUMENT;
833 contact_adaptor_debug("New uid : %s", new_uid);
836 context->duid = NULL;
837 context->duid = strdup(new_uid);
839 return CONTACT_ADAPTOR_ERROR_NONE;
843 /* //////////////////////////////////////////////////////
844 // Create / Destroy error code
845 ////////////////////////////////////////////////////// */
848 * @brief Create error code
850 * @param[in] code specifies error code number
851 * @param[in] msg specifies error message
852 * @return contact_adaptor_error_code_h on success, otherwise NULL value
854 contact_adaptor_error_code_h contact_adaptor_create_error_code(const int64_t code,
861 contact_adaptor_error_code_h error_code = (contact_adaptor_error_code_h) malloc(sizeof(contact_adaptor_error_code_t));
862 if (NULL == error_code) {
866 error_code->code = code;
867 error_code->msg = strdup(msg);
873 * @brief Destroy error code
875 * @param[in] error_code specifies error code handle
878 void contact_adaptor_destroy_error_code(contact_adaptor_error_code_h *error_code)
880 if (NULL == *error_code) {
884 if (NULL != (*error_code)->msg) {
885 free((*error_code)->msg);
886 (*error_code)->msg = NULL;
893 void __contact_adaptor_destroy_char_array(char **arr, unsigned int len)
895 if ((NULL != arr) && (0U < len)) {
896 for (int i = 0; i < len; i++) {
904 void contact_adaptor_destroy_contact_req_s(contact_adaptor_contact_req_h req)
907 if ((req->cts != NULL) && (0U < req->cts_len)) {
908 for (int i = 0; i < req->cts_len; i++) {
909 if (NULL != req->cts[i]) {
910 free(req->cts[i]->tp);
911 free(req->cts[i]->id);
912 free(req->cts[i]->pn);
913 free(req->cts[i]->nm);
914 free(req->cts[i]->cc);
925 void contact_adaptor_destroy_contact_res_s(contact_adaptor_contact_res_h res)
929 } else if ((res->cts == NULL) || (0U == res->cts_len)) {
934 for (int i = 0; i < res->cts_len; i++) {
935 if (NULL != res->cts[i]) {
936 free(res->cts[i]->duid);
937 free(res->cts[i]->id);
938 free(res->cts[i]->msisdn);
939 free(res->cts[i]->ty);
940 free(res->cts[i]->cc);
941 free(res->cts[i]->pn);
942 free(res->cts[i]->nm);
944 if ((NULL != res->cts[i]->evnt) && (0U > res->cts[i]->evnt_len)) {
945 for (int j = 0; j < res->cts[i]->evnt_len; j++) {
946 free(res->cts[i]->evnt[j]);
948 free(res->cts[i]->evnt);
951 __contact_adaptor_destroy_char_array(res->cts[i]->evnt, res->cts[i]->evnt_len);
952 /* free(res->cts[i]->img);*/
954 __contact_adaptor_destroy_char_array(res->cts[i]->adrs, res->cts[i]->adrs_len);
955 __contact_adaptor_destroy_char_array(res->cts[i]->mail, res->cts[i]->mail_len);
957 if ((NULL != res->cts[i]->adrs) && (0U > res->cts[i]->adrs_len)) {
958 for (int j = 0; j < res->cts[i]->adrs_len; j++) {
959 free(res->cts[i]->adrs[j]);
961 free(res->cts[i]->adrs);
963 if ((NULL != res->cts[i]->mail) && (0U > res->cts[i]->mail_len)) {
964 for (int j = 0; j < res->cts[i]->mail_len; j++) {
965 free(res->cts[i]->mail[j]);
967 free(res->cts[i]->mail);
970 free(res->cts[i]->org);
971 free(res->cts[i]->prsc);
972 free(res->cts[i]->status);
981 void contact_adaptor_destroy_profile_req_s(contact_adaptor_profile_req_h req)
990 __contact_adaptor_destroy_char_array(req->evnt, req->evnt_len);
992 __contact_adaptor_destroy_char_array(req->adrs, req->adrs_len);
993 __contact_adaptor_destroy_char_array(req->mail, req->mail_len);
1002 void contact_adaptor_destroy_profile_res_s(contact_adaptor_profile_res_h res)
1017 void contact_adaptor_destroy_file_path_s(contact_adaptor_file_path_h path)
1023 __contact_adaptor_destroy_char_array(path->file_paths, path->file_paths_len);
1029 void contact_adaptor_destroy_privacy_req_s(contact_adaptor_privacy_req_h req)
1035 if ((NULL != req->cts) && (0U < req->cts_len)) {
1036 for (int i = 0; i < req->cts_len; i++) {
1037 free(req->cts[i]->cc);
1038 free(req->cts[i]->pn);
1047 void contact_adaptor_destroy_privacy_res_s(contact_adaptor_privacy_res_h res)
1053 void contact_adaptor_destroy_presence_info_s(contact_adaptor_presence_info_h info)
1064 /* //////////////////////////////////////////////////////
1065 // Contact Adaptor External APIs
1066 ////////////////////////////////////////////////////// */
1069 * @brief Set server information for Contact Plugin
1071 * @param[in] plugin specifies Contact Adaptor Plugin handle
1072 * @param[in] context specifies Contact Adaptor Plugin Context handle
1073 * @param[in] server_info specifies server information for Contact Plugin
1074 * @param[in] request specifies optional parameter
1075 * @param[out] error specifies error code
1076 * @param[out] response specifies optional parameter
1077 * @return 0 on success, otherwise a positive error value
1078 * @retval error code defined in contact_error_code_t - CONTACT_ADAPTOR_ERROR_NONE if Successful
1081 contact_error_code_t contact_adaptor_set_server_info(contact_adaptor_plugin_h plugin,
1082 contact_adaptor_plugin_context_h context,
1083 GHashTable *server_info,
1085 contact_adaptor_error_code_h *error,
1088 if ((NULL == plugin) || (NULL == context)) {
1089 contact_adaptor_error("Invalid argument");
1091 *error = contact_adaptor_create_error_code((int64_t) CONTACT_ADAPTOR_ERROR_INVALID_ARGUMENT,
1092 "Invalid argument (plugin or context)");
1094 return CONTACT_ADAPTOR_ERROR_INVALID_ARGUMENT;
1097 if (NULL == plugin->handle) {
1098 contact_adaptor_error("Plugin handle is null");
1100 *error = contact_adaptor_create_error_code((int64_t) CONTACT_ADAPTOR_ERROR_INVALID_HANDLE,
1101 "Plugin handle is null");
1103 return CONTACT_ADAPTOR_ERROR_INVALID_HANDLE;
1106 contact_error_code_t ret;
1108 ret = plugin->handle->set_server_info(context, server_info, user_data, error, server_data);
1109 plugin_req_exit(ret, plugin, error);
1115 * @brief Resets contact information in Contact server and upload native contact information of device to
1118 * @param[in] plugin specifies contact adaptor plugin handle
1119 * @param[in] context specifies contact adaptor plugin context handle
1120 * @param[in] request specifies contact adaptor contact API request handle
1121 * @param[in] user_data specifies user side arbitrary data
1122 * @param[out] response specifies contact adaptor contact API response handle
1123 * @param[out] error specifies returned error code handle
1124 * @param[out] server_data specifies server side arbitrary data
1125 * @return 0 on success, otherwise a positive error value
1126 * @retval error code defined in contact_error_code_e - CONTACT_ADAPTOR_ERROR_NONE if successful
1128 contact_error_code_t contact_adaptor_new_contact_list(contact_adaptor_plugin_h plugin,
1129 contact_adaptor_plugin_context_h context,
1130 contact_adaptor_contact_req_h request,
1132 contact_adaptor_contact_res_h *response,
1133 contact_adaptor_error_code_h *error,
1136 contact_adaptor_warning("New contact list");
1138 if ((NULL == plugin) || (NULL == context) || (NULL == request)) {
1139 contact_adaptor_error("Invalid argument");
1141 *error = contact_adaptor_create_error_code((int64_t) CONTACT_ADAPTOR_ERROR_INVALID_ARGUMENT,
1142 "Invalid argument (plugin or context or request)");
1144 return CONTACT_ADAPTOR_ERROR_INVALID_ARGUMENT;
1147 if (NULL == plugin->handle) {
1148 contact_adaptor_error("Plugin handle is null");
1150 *error = contact_adaptor_create_error_code((int64_t) CONTACT_ADAPTOR_ERROR_INVALID_HANDLE,
1151 "Plugin handle is null");
1153 return CONTACT_ADAPTOR_ERROR_INVALID_HANDLE;
1156 contact_error_code_t ret;
1158 ret = plugin->handle->new_contact_list(context, request, user_data, response, error, server_data);
1159 plugin_req_exit(ret, plugin, error);
1165 * @brief Synchronized native contact information of device with contact server according to type
1166 * "type" field of each contact
1168 * @param[in] plugin specifies contact adaptor plugin handle
1169 * @param[in] context specifies contact adaptor plugin context handle
1170 * @param[in] request specifies contact adaptor contact API request handle
1171 * @param[in] user_data specifies user side arbitrary data
1172 * @param[out] response specifies contact adaptor contact API response handle
1173 * @param[out] error specifies returned error code handle
1174 * @param[out] server_data specifies server side arbitrary data
1175 * @return 0 on success, otherwise a positive error value
1176 * @retval error code defined in contact_error_code_e - CONTACT_ADAPTOR_ERROR_NONE if successful
1178 contact_error_code_t contact_adaptor_set_contact_list(contact_adaptor_plugin_h plugin,
1179 contact_adaptor_plugin_context_h context,
1180 contact_adaptor_contact_req_h request,
1182 contact_adaptor_contact_res_h *response,
1183 contact_adaptor_error_code_h *error,
1186 contact_adaptor_warning("Set contact list");
1188 if ((NULL == plugin) || (NULL == context) || (NULL == request)) {
1189 contact_adaptor_error("Invalid argument");
1191 *error = contact_adaptor_create_error_code((int64_t) CONTACT_ADAPTOR_ERROR_INVALID_ARGUMENT,
1192 "Invalid argument (plugin or context or request)");
1194 return CONTACT_ADAPTOR_ERROR_INVALID_ARGUMENT;
1197 if (NULL == plugin->handle) {
1198 contact_adaptor_error("Plugin handle is null");
1200 *error = contact_adaptor_create_error_code((int64_t) CONTACT_ADAPTOR_ERROR_INVALID_HANDLE,
1201 "Plugin handle is null");
1203 return CONTACT_ADAPTOR_ERROR_INVALID_HANDLE;
1206 contact_error_code_t ret;
1208 ret = plugin->handle->set_contact_list(context, request, user_data,
1209 response, error, server_data);
1210 plugin_req_exit(ret, plugin, error);
1216 * @brief Gets profile and service registration information of each contact
1218 * @param[in] plugin specifies contact adaptor plugin handle
1219 * @param[in] context specifies contact adaptor plugin context handle
1220 * @param[in] request specifies contact adaptor contact API request handle
1221 * @param[in] user_data specifies user side arbitrary data
1222 * @param[out] response specifies contact adaptor contact API response handle
1223 * @param[out] error specifies returned error code handle
1224 * @param[out] server_data specifies server side arbitrary data
1225 * @return 0 on success, otherwise a positive error value
1226 * @retval error code defined in contact_error_code_e - CONTACT_ADAPTOR_ERROR_NONE if successful
1228 contact_error_code_t contact_adaptor_get_contact_infos_latest(contact_adaptor_plugin_h plugin,
1229 contact_adaptor_plugin_context_h context,
1230 contact_adaptor_contact_req_h request,
1232 contact_adaptor_contact_res_h *response,
1233 contact_adaptor_error_code_h *error,
1236 contact_adaptor_warning("Get contact infos latest");
1238 if ((NULL == plugin) || (NULL == context)) {
1239 contact_adaptor_error("Invalid argument");
1241 *error = contact_adaptor_create_error_code((int64_t) CONTACT_ADAPTOR_ERROR_INVALID_ARGUMENT,
1242 "Invalid argument (plugin or context)");
1244 return CONTACT_ADAPTOR_ERROR_INVALID_ARGUMENT;
1247 if (NULL == plugin->handle) {
1248 contact_adaptor_error("Plugin handle is null");
1250 *error = contact_adaptor_create_error_code((int64_t) CONTACT_ADAPTOR_ERROR_INVALID_HANDLE,
1251 "Plugin handle is null");
1253 return CONTACT_ADAPTOR_ERROR_INVALID_HANDLE;
1256 contact_error_code_t ret;
1258 ret = plugin->handle->get_contact_infos_latest(context, request, user_data,
1259 response, error, server_data);
1260 plugin_req_exit(ret, plugin, error);
1266 * @brief Gets profile and service registration information of contact that have been updated since
1269 * @param[in] plugin specifies contact adaptor plugin handle
1270 * @param[in] context specifies contact adaptor plugin context handle
1271 * @param[in] request specifies contact adaptor contact API request handle
1272 * @param[in] user_data specifies user side arbitrary data
1273 * @param[out] response specifies contact adaptor contact API response handle
1274 * @param[out] error specifies returned error code handle
1275 * @param[out] server_data specifies server side arbitrary data
1276 * @return 0 on success, otherwise a positive error value
1277 * @retval error code defined in contact_error_code_e - CONTACT_ADAPTOR_ERROR_NONE if successful
1279 contact_error_code_t contact_adaptor_get_contact_infos_polling(contact_adaptor_plugin_h plugin,
1280 contact_adaptor_plugin_context_h context,
1281 contact_adaptor_contact_req_h request,
1283 contact_adaptor_contact_res_h *response,
1284 contact_adaptor_error_code_h *error,
1287 contact_adaptor_warning("Get contact infos polling");
1289 if ((NULL == plugin) || (NULL == context) || (NULL == request)) {
1290 contact_adaptor_error("Invalid argument");
1292 *error = contact_adaptor_create_error_code((int64_t) CONTACT_ADAPTOR_ERROR_INVALID_ARGUMENT,
1293 "Invalid argument (plugin or context or request)");
1295 return CONTACT_ADAPTOR_ERROR_INVALID_ARGUMENT;
1298 if (NULL == plugin->handle) {
1299 contact_adaptor_error("Plugin handle is null");
1301 *error = contact_adaptor_create_error_code((int64_t) CONTACT_ADAPTOR_ERROR_INVALID_HANDLE,
1302 "Plugin handle is null");
1304 return CONTACT_ADAPTOR_ERROR_INVALID_HANDLE;
1307 contact_error_code_t ret;
1309 ret = plugin->handle->get_contact_infos_polling(context, request, user_data,
1310 response, error, server_data);
1311 plugin_req_exit(ret, plugin, error);
1317 * @brief Sets or updates device's profile to server
1319 * @param[in] plugin specifies contact adaptor plugin handle
1320 * @param[in] context specifies contact adaptor plugin context handle
1321 * @param[in] request specifies contact adaptor profile API request handle
1322 * @param[in] user_data specifies user side arbitrary data
1323 * @param[out] response specifies contact adaptor profile API response handle
1324 * @param[out] error specifies returned error code handle
1325 * @param[out] server_data specifies server side arbitrary data
1326 * @return 0 on success, otherwise a positive error value
1327 * @retval error code defined in contact_error_code_e - CONTACT_ADAPTOR_ERROR_NONE if successful
1329 contact_error_code_t contact_adaptor_set_me_profile_with_push(contact_adaptor_plugin_h plugin,
1330 contact_adaptor_plugin_context_h context,
1331 contact_adaptor_profile_req_h request,
1333 contact_adaptor_profile_res_h *response,
1334 contact_adaptor_error_code_h *error,
1337 contact_adaptor_warning("Set me profile with push");
1339 if ((NULL == plugin) || (NULL == context) || (NULL == request)) {
1340 contact_adaptor_error("Invalid argument");
1342 *error = contact_adaptor_create_error_code((int64_t) CONTACT_ADAPTOR_ERROR_INVALID_ARGUMENT,
1343 "Invalid argument (plugin or context or request)");
1345 return CONTACT_ADAPTOR_ERROR_INVALID_ARGUMENT;
1348 if (NULL == plugin->handle) {
1349 contact_adaptor_error("Plugin handle is null");
1351 *error = contact_adaptor_create_error_code((int64_t) CONTACT_ADAPTOR_ERROR_INVALID_HANDLE,
1352 "Plugin handle is null");
1354 return CONTACT_ADAPTOR_ERROR_INVALID_HANDLE;
1357 contact_error_code_t ret;
1359 ret = plugin->handle->set_me_profile_with_push(context, request, user_data,
1360 response, error, server_data);
1361 plugin_req_exit(ret, plugin, error);
1367 * @brief Gets the profile information of a contact which is correspondent with country code and phone number
1369 * @param[in] plugin specifies contact adaptor plugin handle
1370 * @param[in] context specifies contact adaptor plugin context handle
1371 * @param[in] request specifies contact adaptor profile API request handle
1372 * @param[in] user_data specifies user side arbitrary data
1373 * @param[out] response specifies contact adaptor profile API response handle
1374 * @param[out] error specifies returned error code handle
1375 * @param[out] server_data specifies server side arbitrary data
1376 * @return 0 on success, otherwise a positive error value
1377 * @retval error code defined in contact_error_code_e - CONTACT_ADAPTOR_ERROR_NONE if successful
1379 contact_error_code_t contact_adaptor_get_profile(contact_adaptor_plugin_h plugin,
1380 contact_adaptor_plugin_context_h context,
1381 contact_adaptor_profile_req_h request,
1383 contact_adaptor_profile_res_h *response,
1384 contact_adaptor_error_code_h *error,
1387 contact_adaptor_warning("Get profile");
1389 if ((NULL == plugin) || (NULL == context) || (NULL == request)) {
1390 contact_adaptor_error("Invalid argument");
1392 *error = contact_adaptor_create_error_code((int64_t) CONTACT_ADAPTOR_ERROR_INVALID_ARGUMENT,
1393 "Invalid argument (plugin or context or request)");
1395 return CONTACT_ADAPTOR_ERROR_INVALID_ARGUMENT;
1398 if (NULL == plugin->handle) {
1399 contact_adaptor_error("Plugin handle is null");
1401 *error = contact_adaptor_create_error_code((int64_t) CONTACT_ADAPTOR_ERROR_INVALID_HANDLE,
1402 "Plugin handle is null");
1404 return CONTACT_ADAPTOR_ERROR_INVALID_HANDLE;
1407 contact_error_code_t ret;
1409 ret = plugin->handle->get_profile(context, request, user_data, response, error, server_data);
1410 plugin_req_exit(ret, plugin, error);
1416 * @brief Uploads profile image meta to file server
1418 * @param[in] plugin specifies contact adaptor plugin handle
1419 * @param[in] context specifies contact adaptor plugin context handle
1420 * @param[in] request specifies contact adaptor profile API image file request handle
1421 * @param[in] user_data specifies user side arbitrary data
1422 * @param[out] response specifies contact adaptor profile API image file response handle
1423 * @param[out] error specifies returned error code handle
1424 * @param[out] server_data specifies server side arbitrary data
1425 * @return 0 on success, otherwise a positive error value
1426 * @retval error code defined in contact_error_code_e - CONTACT_ADAPTOR_ERROR_NONE if successful
1428 contact_error_code_t contact_adaptor_set_me_profile_image_meta_with_push(contact_adaptor_plugin_h plugin,
1429 contact_adaptor_plugin_context_h context,
1430 contact_adaptor_contact_image_h *imgs,
1431 unsigned int imgs_len,
1433 contact_adaptor_error_code_h *error,
1436 contact_adaptor_warning("Set me profile image meta with push");
1438 if ((NULL == plugin) || (NULL == context) || (NULL == imgs) || (0U == imgs_len)) {
1439 contact_adaptor_error("Invalid argument");
1441 *error = contact_adaptor_create_error_code((int64_t) CONTACT_ADAPTOR_ERROR_INVALID_ARGUMENT,
1442 "Invalid argument (plugin or context or request)");
1444 return CONTACT_ADAPTOR_ERROR_INVALID_ARGUMENT;
1447 if (NULL == plugin->handle) {
1448 contact_adaptor_error("Plugin handle is null");
1450 *error = contact_adaptor_create_error_code((int64_t) CONTACT_ADAPTOR_ERROR_INVALID_HANDLE,
1451 "Plugin handle is null");
1453 return CONTACT_ADAPTOR_ERROR_INVALID_HANDLE;
1456 contact_error_code_t ret;
1458 ret = plugin->handle->set_me_profile_image_meta_with_push(context, imgs, imgs_len, user_data,
1459 error, server_data);
1460 plugin_req_exit(ret, plugin, error);
1466 * @brief Deletes profile image meta from profile server
1468 * @param[in] plugin specifies contact adaptor plugin handle
1469 * @param[in] context specifies contact adaptor plugin context handle
1470 * @param[in] request specifies contact adaptor profile API image file request handle
1471 * @param[in] user_data specifies user side arbitrary data
1472 * @param[out] response specifies contact adaptor profile API image file response handle
1473 * @param[out] error specifies returned error code handle
1474 * @param[out] server_data specifies server side arbitrary data
1475 * @return 0 on success, otherwise a positive error value
1476 * @retval error code defined in contact_error_code_e - CONTACT_ADAPTOR_ERROR_NONE if successful
1478 contact_error_code_t contact_adaptor_delete_me_profile_image_meta_with_push(contact_adaptor_plugin_h plugin,
1479 contact_adaptor_plugin_context_h context,
1481 contact_adaptor_error_code_h *error,
1484 contact_adaptor_warning("Delete me profile image meta with push");
1486 if ((NULL == plugin) || (NULL == context)) {
1487 contact_adaptor_error("Invalid argument");
1489 *error = contact_adaptor_create_error_code((int64_t) CONTACT_ADAPTOR_ERROR_INVALID_ARGUMENT,
1490 "Invalid argument (plugin or context or request)");
1492 return CONTACT_ADAPTOR_ERROR_INVALID_ARGUMENT;
1495 if (NULL == plugin->handle) {
1496 contact_adaptor_error("Plugin handle is null");
1498 *error = contact_adaptor_create_error_code((int64_t) CONTACT_ADAPTOR_ERROR_INVALID_HANDLE,
1499 "Plugin handle is null");
1501 return CONTACT_ADAPTOR_ERROR_INVALID_HANDLE;
1504 contact_error_code_t ret;
1506 ret = plugin->handle->delete_me_profile_image_meta_with_push(context, user_data,
1507 error, server_data);
1508 plugin_req_exit(ret, plugin, error);
1514 * @brief Sets the level of privacy
1516 * @param[in] plugin specifies contact adaptor plugin handle
1517 * @param[in] context specifies contact adaptor plugin context handle
1518 * @param[in] request specifies contact adaptor privacy API request handle
1519 * @param[in] user_data specifies user side arbitrary data
1520 * @param[out] response specifies contact adaptor privacy API response handle
1521 * @param[out] error specifies returned error code handle
1522 * @param[out] server_data specifies server side arbitrary data
1523 * @return 0 on success, otherwise a positive error value
1524 * @retval error code defined in contact_error_code_e - CONTACT_ADAPTOR_ERROR_NONE if successful
1526 contact_error_code_t contact_adaptor_set_me_profile_privacy(contact_adaptor_plugin_h plugin,
1527 contact_adaptor_plugin_context_h context,
1528 contact_adaptor_privacy_req_h request,
1530 contact_adaptor_privacy_res_h *response,
1531 contact_adaptor_error_code_h *error,
1534 contact_adaptor_warning("Set me profile privacy");
1536 if ((NULL == plugin) || (NULL == context) || (NULL == request)) {
1537 contact_adaptor_error("Invalid argument");
1539 *error = contact_adaptor_create_error_code((int64_t) CONTACT_ADAPTOR_ERROR_INVALID_ARGUMENT,
1540 "Invalid argument (plugin or context or request)");
1542 return CONTACT_ADAPTOR_ERROR_INVALID_ARGUMENT;
1545 if (NULL == plugin->handle) {
1546 contact_adaptor_error("Plugin handle is null");
1548 *error = contact_adaptor_create_error_code((int64_t) CONTACT_ADAPTOR_ERROR_INVALID_HANDLE,
1549 "Plugin handle is null");
1551 return CONTACT_ADAPTOR_ERROR_INVALID_HANDLE;
1554 contact_error_code_t ret;
1556 ret = plugin->handle->set_me_profile_privacy(context, request, user_data,
1557 response, error, server_data);
1558 plugin_req_exit(ret, plugin, error);
1564 * @brief Gets my profile's privacy level
1566 * @param[in] plugin specifies contact adaptor plugin handle
1567 * @param[in] context specifies contact adaptor plugin context handle
1568 * @param[in] request specifies contact adaptor privacy API request handle
1569 * @param[in] user_data specifies user side arbitrary data
1570 * @param[out] response specifies contact adaptor privacy API response handle
1571 * @param[out] error specifies returned error code handle
1572 * @param[out] server_data specifies server side arbitrary data
1573 * @return 0 on success, otherwise a positive error value
1574 * @retval error code defined in contact_error_code_e - CONTACT_ADAPTOR_ERROR_NONE if successful
1576 contact_error_code_t contact_adaptor_get_me_profile_privacy(contact_adaptor_plugin_h plugin,
1577 contact_adaptor_plugin_context_h context,
1578 contact_adaptor_privacy_req_h request,
1580 contact_adaptor_privacy_res_h *response,
1581 contact_adaptor_error_code_h *error,
1584 contact_adaptor_warning("Get me profile privacy");
1586 if ((NULL == plugin) || (NULL == context)) {
1587 contact_adaptor_error("Invalid argument");
1589 *error = contact_adaptor_create_error_code((int64_t) CONTACT_ADAPTOR_ERROR_INVALID_ARGUMENT,
1590 "Invalid argument (plugin or context or request)");
1592 return CONTACT_ADAPTOR_ERROR_INVALID_ARGUMENT;
1595 if (NULL == plugin->handle) {
1596 contact_adaptor_error("Plugin handle is null");
1598 *error = contact_adaptor_create_error_code((int64_t) CONTACT_ADAPTOR_ERROR_INVALID_HANDLE,
1599 "Plugin handle is null");
1601 return CONTACT_ADAPTOR_ERROR_INVALID_HANDLE;
1604 contact_error_code_t ret;
1606 ret = plugin->handle->get_me_profile_privacy(context, request, user_data,
1607 response, error, server_data);
1608 plugin_req_exit(ret, plugin, error);
1614 * @brief Sets my presence information
1616 * @param[in] plugin specifies contact adaptor plugin handle
1617 * @param[in] context specifies contact adaptor plugin context handle
1618 * @param[in] request specifies contact adaptor presence API request handle
1619 * @param[in] user_data specifies user side arbitrary data
1620 * @param[out] response specifies contact adaptor presence API response handle
1621 * @param[out] error specifies returned error code handle
1622 * @param[out] server_data specifies server side arbitrary data
1623 * @return 0 on success, otherwise a positive error value
1624 * @retval error code defined in contact_error_code_e - CONTACT_ADAPTOR_ERROR_NONE if successful
1626 contact_error_code_t contact_adaptor_set_me_presence_with_push(contact_adaptor_plugin_h plugin,
1627 contact_adaptor_plugin_context_h context,
1628 contact_adaptor_presence_info_h request,
1630 contact_adaptor_presence_info_h *response,
1631 contact_adaptor_error_code_h *error,
1634 contact_adaptor_warning("Set me presence with push");
1636 if ((NULL == plugin) || (NULL == context) || (NULL == request)) {
1637 contact_adaptor_error("Invalid argument");
1639 *error = contact_adaptor_create_error_code((int64_t) CONTACT_ADAPTOR_ERROR_INVALID_ARGUMENT,
1640 "Invalid argument (plugin or context or request)");
1642 return CONTACT_ADAPTOR_ERROR_INVALID_ARGUMENT;
1645 if (NULL == plugin->handle) {
1646 contact_adaptor_error("Plugin handle is null");
1648 *error = contact_adaptor_create_error_code((int64_t) CONTACT_ADAPTOR_ERROR_INVALID_HANDLE,
1649 "Plugin handle is null");
1651 return CONTACT_ADAPTOR_ERROR_INVALID_HANDLE;
1654 contact_error_code_t ret;
1656 ret = plugin->handle->set_me_presence_with_push(context, request, user_data,
1657 response, error, server_data);
1658 plugin_req_exit(ret, plugin, error);
1664 * @brief Sets my presence on/off information
1666 * @param[in] plugin specifies contact adaptor plugin handle
1667 * @param[in] context specifies contact adaptor plugin context handle
1668 * @param[in] request specifies contact adaptor presence API request handle
1669 * @param[in] user_data specifies user side arbitrary data
1670 * @param[out] response specifies contact adaptor presence API response handle
1671 * @param[out] error specifies returned error code handle
1672 * @param[out] server_data specifies server side arbitrary data
1673 * @return 0 on success, otherwise a positive error value
1674 * @retval error code defined in contact_error_code_e - CONTACT_ADAPTOR_ERROR_NONE if successful
1676 contact_error_code_t contact_adaptor_set_me_presence_on_off_with_push(contact_adaptor_plugin_h plugin,
1677 contact_adaptor_plugin_context_h context,
1678 contact_adaptor_presence_info_h request,
1680 contact_adaptor_presence_info_h *response,
1681 contact_adaptor_error_code_h *error,
1684 contact_adaptor_warning("Set me presence on off with push");
1686 if ((NULL == plugin) || (NULL == context) || (NULL == request)) {
1687 contact_adaptor_error("Invalid argument");
1689 *error = contact_adaptor_create_error_code((int64_t) CONTACT_ADAPTOR_ERROR_INVALID_ARGUMENT,
1690 "Invalid argument (plugin or context or request)");
1692 return CONTACT_ADAPTOR_ERROR_INVALID_ARGUMENT;
1695 if (NULL == plugin->handle) {
1696 contact_adaptor_error("Plugin handle is null");
1698 *error = contact_adaptor_create_error_code((int64_t) CONTACT_ADAPTOR_ERROR_INVALID_HANDLE,
1699 "Plugin handle is null");
1701 return CONTACT_ADAPTOR_ERROR_INVALID_HANDLE;
1704 contact_error_code_t ret;
1706 ret = plugin->handle->set_me_presence_on_off_with_push(context, request, user_data,
1707 response, error, server_data);
1708 plugin_req_exit(ret, plugin, error);
1714 contact_error_code_t contact_adaptor_set_me_profile_type(contact_adaptor_plugin_h plugin,
1715 contact_adaptor_plugin_context_h context,
1719 contact_adaptor_error_code_h *error,
1722 contact_adaptor_info("%s", __FUNCTION__);
1724 if ((NULL == plugin) || (NULL == context)) {
1725 contact_adaptor_error("Invalid argument");
1727 *error = contact_adaptor_create_error_code((int64_t) CONTACT_ADAPTOR_ERROR_INVALID_ARGUMENT,
1728 "Invalid argument (plugin or context or request)");
1730 return CONTACT_ADAPTOR_ERROR_INVALID_ARGUMENT;
1733 if (NULL == plugin->handle) {
1734 contact_adaptor_error("Plugin handle is null");
1736 *error = contact_adaptor_create_error_code((int64_t) CONTACT_ADAPTOR_ERROR_INVALID_HANDLE,
1737 "Plugin handle is null");
1739 return CONTACT_ADAPTOR_ERROR_INVALID_HANDLE;
1743 contact_error_code_t ret;
1745 ret = plugin->handle->set_me_profile_type(context, req_type, user_data,
1746 &_url, error, server_data);
1747 plugin_req_exit(ret, plugin, error);
1749 contact_adaptor_debug("url : %s", _url);