2 * Copyright (c) 2018 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.
28 #include "autofill_service.h"
29 #include "autofill_private.h"
30 #include "autofill_service_stub.h"
35 #define LOG_TAG "AUTOFILL_SERVICE"
37 static autofill_service_fill_requested_cb g_autofill_service_fill_requested_cb;
38 static void *g_autofill_service_fill_request_data = NULL;
40 static autofill_service_auth_info_requested_cb g_autofill_service_auth_info_requested_cb;
41 static void *g_autofill_service_auth_info_request_data = NULL;
43 static autofill_service_commited_cb g_autofill_service_commited_cb;
44 static void *g_autofill_service_commit_data = NULL;
46 static autofill_service_terminate_received_cb g_autofill_service_terminate_received_cb;
47 static void *g_autofill_service_terminate_received_data = NULL;
49 rpc_port_AutofillSvcPort_autofill_svc_auth_info_cb_h g_auth_info_cb;
50 rpc_port_AutofillSvcPort_autofill_svc_fill_response_cb_h g_fill_response_received_cb;
51 rpc_port_AutofillSvcPort_autofill_svc_send_error_cb_h g_send_error_cb;
56 rpc_port_AutofillSvcPort_autofill_svc_auth_info_cb_h auth_info_cb;
57 rpc_port_AutofillSvcPort_autofill_svc_fill_response_cb_h fill_response_received_cb;
58 rpc_port_AutofillSvcPort_autofill_svc_send_error_cb_h send_error_cb;
61 static GList *__client_list = NULL;
64 bool __autofill_item_cb(rpc_port_autofill_svc_item_h items, void *user_data)
72 autofill_view_info_h vi = (autofill_view_info_h)user_data;
75 autofill_item_create(&ai);
77 rpc_port_autofill_svc_item_get_id(items, &id);
78 autofill_item_set_id(ai, id);
84 rpc_port_autofill_svc_item_get_label(items, &label);
85 autofill_item_set_label(ai, label);
87 LOGD("label : %s", label);
91 rpc_port_autofill_svc_item_get_value(items, &value);
92 autofill_item_set_value(ai, value);
94 LOGD("value : %s", value);
98 rpc_port_autofill_svc_item_get_autofill_hint(items, &autofill_hint);
99 autofill_item_set_autofill_hint(ai, autofill_hint);
100 LOGD("autofill hint : %d", autofill_hint);
102 rpc_port_autofill_svc_item_get_is_sensitive_data(items, &sensitive_data);
103 autofill_item_set_sensitive_data(ai, sensitive_data);
104 LOGD("sensitive data : %d", sensitive_data);
106 autofill_view_info_add_item(vi, ai);
108 autofill_item_destroy(ai);
113 bool __save_item_cb(rpc_port_autofill_svc_save_item_h items, void *user_data)
121 autofill_save_view_info_h vi = (autofill_save_view_info_h)user_data;
123 autofill_save_item_h ai;
124 autofill_save_item_create(&ai);
126 rpc_port_autofill_svc_save_item_get_id(items, &id);
127 autofill_save_item_set_id(ai, id);
133 rpc_port_autofill_svc_save_item_get_label(items, &label);
134 autofill_save_item_set_label(ai, label);
136 LOGD("label : %s", label);
140 rpc_port_autofill_svc_save_item_get_value(items, &value);
141 autofill_save_item_set_value(ai, value);
143 LOGD("value : %s", value);
147 rpc_port_autofill_svc_save_item_get_autofill_hint(items, &autofill_hint);
148 autofill_save_item_set_autofill_hint(ai, autofill_hint);
149 LOGD("autofill hint : %d", autofill_hint);
151 rpc_port_autofill_svc_save_item_get_is_sensitive_data(items, &sensitive_data);
152 autofill_save_item_set_sensitive_data(ai, sensitive_data);
153 LOGD("sensitive data : %d", sensitive_data);
155 autofill_save_view_info_add_item(vi, ai);
157 autofill_save_item_destroy(ai);
162 static void __auth_info_request_cb(rpc_port_stub_AutofillSvcPort_context_h context, int context_id, rpc_port_autofill_svc_view_info_h vi, void *user_data)
166 rpc_port_stub_AutofillSvcPort_context_get_sender(context, &sender);
168 LOGD("sender(%s)", sender);
173 char *view_id = NULL;
174 rpc_port_autofill_svc_view_info_get_app_id(vi, &app_id);
175 rpc_port_autofill_svc_view_info_get_view_id(vi, &view_id);
176 LOGD("app id : %s, view id : %s", app_id, view_id);
178 autofill_view_info_h view_info;
179 autofill_view_info_create(&view_info);
180 autofill_view_info_set_app_id(view_info, app_id);
181 autofill_view_info_set_view_id(view_info, view_id);
183 rpc_port_autofill_svc_view_info_foreach_items(vi, __autofill_item_cb, view_info);
185 if (g_autofill_service_auth_info_requested_cb)
186 g_autofill_service_auth_info_requested_cb(context_id, view_info, g_autofill_service_auth_info_request_data);
188 autofill_view_info_destroy(view_info);
197 static void __autofill_fill_request_cb(rpc_port_stub_AutofillSvcPort_context_h context, int context_id, rpc_port_autofill_svc_view_info_h vi, void *user_data)
200 char *view_id = NULL;
202 rpc_port_autofill_svc_view_info_get_app_id(vi, &app_id);
203 rpc_port_autofill_svc_view_info_get_view_id(vi, &view_id);
205 LOGD("app id : %s, view id : %s", app_id, view_id);
207 autofill_view_info_h view_info;
208 autofill_view_info_create(&view_info);
209 autofill_view_info_set_app_id(view_info, app_id);
210 autofill_view_info_set_view_id(view_info, view_id);
212 rpc_port_autofill_svc_view_info_foreach_items(vi, __autofill_item_cb, view_info);
214 if (g_autofill_service_fill_requested_cb)
215 g_autofill_service_fill_requested_cb(context_id, view_info, g_autofill_service_auth_info_request_data);
217 autofill_view_info_destroy(view_info);
226 static void __autofill_commit_cb(rpc_port_stub_AutofillSvcPort_context_h context, int context_id, rpc_port_autofill_svc_save_view_info_h vi, void *user_data)
229 char *view_id = NULL;
230 char *view_title = NULL;
232 rpc_port_autofill_svc_save_view_info_get_app_id(vi, &app_id);
233 rpc_port_autofill_svc_save_view_info_get_view_id(vi, &view_id);
234 rpc_port_autofill_svc_save_view_info_get_view_title(vi, &view_title);
236 LOGD("app id : %s, view id : %s", app_id, view_id);
238 autofill_save_view_info_h view_info;
239 autofill_save_view_info_create(&view_info);
240 autofill_save_view_info_set_app_id(view_info, app_id);
241 autofill_save_view_info_set_view_id(view_info, view_id);
242 autofill_save_view_info_set_view_title(view_info, view_title);
244 rpc_port_autofill_svc_save_view_info_foreach_items(vi, __save_item_cb, view_info);
246 if (g_autofill_service_commited_cb)
247 g_autofill_service_commited_cb(context_id, view_info, g_autofill_service_commit_data);
249 autofill_save_view_info_destroy(view_info);
264 static void __terminate_received_cb(rpc_port_stub_AutofillSvcPort_context_h context, void *user_data)
268 if (g_autofill_service_terminate_received_cb)
269 g_autofill_service_terminate_received_cb(g_autofill_service_terminate_received_data);
271 ecore_main_loop_quit();
274 static autofill_svc_s *__create_client(const char *app_id,
275 rpc_port_AutofillSvcPort_autofill_svc_auth_info_cb_h auth_info_cb,
276 rpc_port_AutofillSvcPort_autofill_svc_fill_response_cb_h fill_response_received_cb,
277 rpc_port_AutofillSvcPort_autofill_svc_send_error_cb_h send_error_cb)
280 autofill_svc_s *handle;
282 handle = calloc(1, sizeof(autofill_svc_s));
284 LOGE("Out of memory");
288 handle->app_id = strdup(app_id);
289 if (!handle->app_id) {
290 LOGE("Out of memory");
295 rpc_port_AutofillSvcPort_autofill_svc_auth_info_cb_clone(auth_info_cb, &handle->auth_info_cb);
296 if (!handle->auth_info_cb) {
297 LOGE("Out of memory");
298 free(handle->app_id);
303 rpc_port_AutofillSvcPort_autofill_svc_fill_response_cb_clone(fill_response_received_cb, &handle->fill_response_received_cb);
305 if (!handle->fill_response_received_cb) {
306 LOGE("Out of memory");
307 free(handle->app_id);
308 rpc_port_AutofillSvcPort_autofill_svc_auth_info_cb_destroy(handle->auth_info_cb);
313 rpc_port_AutofillSvcPort_autofill_svc_send_error_cb_clone(send_error_cb, &handle->send_error_cb);
314 if (!handle->send_error_cb) {
315 LOGE("Out of memory");
316 free(handle->app_id);
317 rpc_port_AutofillSvcPort_autofill_svc_auth_info_cb_destroy(handle->auth_info_cb);
318 rpc_port_AutofillSvcPort_autofill_svc_fill_response_cb_destroy(handle->fill_response_received_cb);
326 static void __destroy_client(gpointer data)
329 autofill_svc_s *handle = data;
334 if (handle->auth_info_cb) {
335 rpc_port_AutofillSvcPort_autofill_svc_auth_info_cb_destroy(handle->auth_info_cb);
336 handle->auth_info_cb = NULL;
339 if (handle->fill_response_received_cb) {
340 rpc_port_AutofillSvcPort_autofill_svc_fill_response_cb_destroy(handle->fill_response_received_cb);
341 handle->fill_response_received_cb = NULL;
344 if (handle->send_error_cb) {
345 rpc_port_AutofillSvcPort_autofill_svc_send_error_cb_destroy(handle->send_error_cb);
346 handle->send_error_cb = NULL;
349 if (handle->app_id) {
350 free(handle->app_id);
351 handle->app_id = NULL;
357 static int __message_register(rpc_port_stub_AutofillSvcPort_context_h context,
358 rpc_port_AutofillSvcPort_autofill_svc_auth_info_cb_h auth_info_cb,
359 rpc_port_AutofillSvcPort_autofill_svc_fill_response_cb_h fill_response_received_cb,
360 rpc_port_AutofillSvcPort_autofill_svc_send_error_cb_h send_error_cb,
366 rpc_port_stub_AutofillSvcPort_context_get_sender(context, &sender);
370 autofill_svc_s *client;
371 client = __create_client(sender, auth_info_cb, fill_response_received_cb, send_error_cb);
377 rpc_port_AutofillSvcPort_autofill_svc_auth_info_cb_clone(auth_info_cb, &g_auth_info_cb);
378 rpc_port_AutofillSvcPort_autofill_svc_fill_response_cb_clone(fill_response_received_cb, &g_fill_response_received_cb);
379 rpc_port_AutofillSvcPort_autofill_svc_send_error_cb_clone(send_error_cb, &g_send_error_cb);
381 __client_list = g_list_append(__client_list, client);
383 rpc_port_stub_AutofillSvcPort_context_set_tag(context, client);
388 static void __message_unregister(rpc_port_stub_AutofillSvcPort_context_h context, void *user_data)
390 autofill_svc_s *client = NULL;
391 rpc_port_stub_AutofillSvcPort_context_get_tag(context, (void *)&client);
395 rpc_port_stub_AutofillSvcPort_context_set_tag(context, NULL);
396 LOGI("name(%s)", client->app_id);
398 __client_list = g_list_remove(__client_list, client);
399 __destroy_client(client);
403 EXPORT_API int autofill_service_initialize(void)
405 LOGD("autofill service initialize");
409 rpc_port_stub_AutofillSvcPort_callback_s callback = {
413 __message_unregister,
414 __auth_info_request_cb,
415 __autofill_fill_request_cb,
416 __autofill_commit_cb,
417 __terminate_received_cb
420 ret = rpc_port_stub_AutofillSvcPort_register(&callback, NULL);
422 LOGW("Failed to register message");
424 LOGI("Succeeded to register message");
429 EXPORT_API int autofill_service_deinitialize(void)
431 LOGD("autofill service deinitialize");
434 g_list_free_full(__client_list, __destroy_client);
435 __client_list = NULL;
438 rpc_port_stub_AutofillSvcPort_unregister();
440 return AUTOFILL_ERROR_NONE;
443 EXPORT_API int autofill_service_set_auth_info_requested_cb(autofill_service_auth_info_requested_cb callback, void *user_data)
446 LOGW("[ERROR] Invalid parameter");
447 return AUTOFILL_ERROR_INVALID_PARAMETER;
450 g_autofill_service_auth_info_requested_cb = callback;
451 g_autofill_service_auth_info_request_data = user_data;
453 return AUTOFILL_ERROR_NONE;
456 EXPORT_API int autofill_service_unset_auth_info_requested_cb()
458 g_autofill_service_auth_info_requested_cb = NULL;
459 g_autofill_service_auth_info_request_data = NULL;
461 return AUTOFILL_ERROR_NONE;
464 EXPORT_API int autofill_service_send_auth_info(int context_id, autofill_auth_info_h h)
466 bool autofill_data_present = false;
467 bool authentication_needed = false;
469 char *view_id = NULL;
470 char *service_name = NULL;
471 char *service_logo_image_path = NULL;
472 char *service_message = NULL;
473 int ret = AUTOFILL_ERROR_NONE;
476 LOGW("[ERROR] Invalid parameter");
477 return AUTOFILL_ERROR_INVALID_PARAMETER;
480 autofill_auth_info_get_app_id(h, &app_id);
481 autofill_auth_info_get_view_id(h, &view_id);
482 autofill_auth_info_get_autofill_data_present(h, &autofill_data_present);
483 autofill_auth_info_get_authentication_needed(h, &authentication_needed);
484 autofill_auth_info_get_service_name(h, &service_name);
485 autofill_auth_info_get_service_message(h, &service_message);
486 autofill_auth_info_get_service_logo_image_path(h, &service_logo_image_path);
488 LOGD("app_id : %s", app_id);
490 /* create auth info */
491 rpc_port_autofill_svc_auth_info_h auth_info_h;
492 rpc_port_autofill_svc_auth_info_create(&auth_info_h);
493 rpc_port_autofill_svc_auth_info_set_app_id(auth_info_h, app_id);
494 rpc_port_autofill_svc_auth_info_set_view_id(auth_info_h, view_id);
495 rpc_port_autofill_svc_auth_info_set_exist_autofill_data(auth_info_h, autofill_data_present);
496 rpc_port_autofill_svc_auth_info_set_need_authentication(auth_info_h, authentication_needed);
497 rpc_port_autofill_svc_auth_info_set_service_name(auth_info_h, service_name);
498 rpc_port_autofill_svc_auth_info_set_service_message(auth_info_h, service_message);
499 rpc_port_autofill_svc_auth_info_set_service_logo_image_path(auth_info_h, service_logo_image_path);
501 ret = rpc_port_AutofillSvcPort_autofill_svc_auth_info_cb_invoke(g_auth_info_cb, context_id, auth_info_h);
512 if (service_logo_image_path)
513 free(service_logo_image_path);
516 free(service_message);
518 rpc_port_autofill_svc_auth_info_destroy(auth_info_h);
524 EXPORT_API int autofill_service_set_fill_requested_cb(autofill_service_fill_requested_cb callback, void *user_data)
527 LOGW("[ERROR] Invalid parameter");
528 return AUTOFILL_ERROR_INVALID_PARAMETER;
531 g_autofill_service_fill_requested_cb = callback;
532 g_autofill_service_fill_request_data = user_data;
534 return AUTOFILL_ERROR_NONE;
537 EXPORT_API int autofill_service_unset_fill_requested_cb()
539 g_autofill_service_fill_requested_cb = NULL;
540 g_autofill_service_fill_request_data = NULL;
542 return AUTOFILL_ERROR_NONE;
545 bool __fill_response_item_cb(autofill_fill_response_item_h it, void * user_data)
549 char *presentation_text = NULL;
551 rpc_port_autofill_svc_response_group_h res_group_h = (rpc_port_autofill_svc_response_group_h)user_data;
553 rpc_port_autofill_svc_response_item_h ritem_h;
555 autofill_fill_response_item_get_id(it, &id);
556 autofill_fill_response_item_get_value(it, &value);
557 autofill_fill_response_item_get_presentation_text(it, &presentation_text);
559 LOGD("it : %p, id : %s, value : %s, presentation text : %s", it, id, value, presentation_text);
561 rpc_port_autofill_svc_response_item_create(&ritem_h);
562 rpc_port_autofill_svc_response_item_set_id(ritem_h, id);
563 rpc_port_autofill_svc_response_item_set_presentation_text(ritem_h, presentation_text);
564 rpc_port_autofill_svc_response_item_set_value(ritem_h, value);
566 rpc_port_autofill_svc_response_group_add_response_items(res_group_h, ritem_h);
578 if (presentation_text) {
579 free(presentation_text);
580 presentation_text= NULL;
583 rpc_port_autofill_svc_response_item_destroy(ritem_h);
588 EXPORT_API int autofill_service_send_fill_response(int context_id, autofill_fill_response_h h)
590 /* create autofill response */
591 rpc_port_autofill_svc_fill_response_h fill_response_h;
592 int ret = AUTOFILL_ERROR_NONE;
595 autofill_fill_response_group_h it;
598 LOGW("[ERROR] Invalid parameter");
599 return AUTOFILL_ERROR_INVALID_PARAMETER;
602 rpc_port_autofill_svc_fill_response_create(&fill_response_h);
605 rpc_port_autofill_svc_fill_response_set_app_id(fill_response_h, h->app_id);
608 rpc_port_autofill_svc_fill_response_set_view_id(fill_response_h, h->view_id);
610 rpc_port_autofill_svc_response_group_h res_group_h;
612 EINA_LIST_FOREACH(h->autofill_fill_response_group_list, l, it)
615 rpc_port_autofill_svc_response_group_create(&res_group_h);
617 autofill_fill_response_group_foreach_item(it, __fill_response_item_cb, res_group_h);
619 rpc_port_autofill_svc_fill_response_add_response_groups(fill_response_h, res_group_h);
621 rpc_port_autofill_svc_response_group_destroy(res_group_h);
624 ret = rpc_port_AutofillSvcPort_autofill_svc_fill_response_cb_invoke(g_fill_response_received_cb, context_id, fill_response_h);
626 rpc_port_autofill_svc_fill_response_destroy(fill_response_h);
631 EXPORT_API int autofill_service_set_commited_cb(autofill_service_commited_cb callback, void *user_data)
634 LOGW("[ERROR] Invalid parameter");
635 return AUTOFILL_ERROR_INVALID_PARAMETER;
638 g_autofill_service_commited_cb = callback;
639 g_autofill_service_commit_data = user_data;
641 return AUTOFILL_ERROR_NONE;
644 EXPORT_API int autofill_service_unset_commited_cb(void)
646 g_autofill_service_commited_cb = NULL;
647 g_autofill_service_commit_data = NULL;
649 return AUTOFILL_ERROR_NONE;
652 EXPORT_API int autofill_service_set_terminate_received_cb(autofill_service_terminate_received_cb callback, void *user_data)
655 LOGW("[ERROR] Invalid parameter");
656 return AUTOFILL_ERROR_INVALID_PARAMETER;
658 g_autofill_service_terminate_received_cb = callback;
659 g_autofill_service_terminate_received_data = user_data;
661 return AUTOFILL_ERROR_NONE;
664 EXPORT_API int autofill_service_unset_terminate_received_cb(void)
666 g_autofill_service_terminate_received_cb = NULL;
667 g_autofill_service_terminate_received_data = NULL;
669 return AUTOFILL_ERROR_NONE;
672 EXPORT_API int autofill_service_send_error_info(int context_id, autofill_error_info_h h)
675 autofill_error_e error_code;
676 rpc_port_autofill_svc_error_info_h error_info_h = NULL;
679 LOGW("[ERROR] Invalid parameter");
680 return AUTOFILL_ERROR_INVALID_PARAMETER;
683 autofill_error_info_get_app_id(h, &app_id);
684 autofill_error_info_get_error_code(h, &error_code);
686 /* create error info */
687 rpc_port_autofill_svc_error_info_create(&error_info_h);
688 rpc_port_autofill_svc_error_info_set_app_id(error_info_h, app_id);
689 rpc_port_autofill_svc_error_info_set_error_code(error_info_h, error_code);
691 int ret = rpc_port_AutofillSvcPort_autofill_svc_send_error_cb_invoke(g_send_error_cb, context_id, error_info_h);
696 rpc_port_autofill_svc_error_info_destroy(error_info_h);