2 * Copyright (c) 2021 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.
20 #include "vine-constants.h"
22 #include "vine-data-path.h"
23 #include "vine-event-loop.h"
25 #include "vine-private.h"
26 #include "vine-security.h"
27 #include "vine-service.h"
28 #include "vine-session.h"
29 #include "vine-utils.h"
31 API int vine_initialize()
34 CHECK_FEATURE_SUPPORTED;
39 API int vine_deinitialize()
42 CHECK_FEATURE_SUPPORTED;
44 return _vine_deinit();
47 API int vine_get_capabilities(vine_capability_type_e type, int *capabilities)
50 CHECK_FEATURE_SUPPORTED;
52 return _vine_get_capabilities(type, capabilities);
55 API int vine_session_get_event_fd(vine_session_h session, int *fd)
58 CHECK_FEATURE_SUPPORTED;
60 return _vine_session_get_event_fd(session, fd);
63 API int vine_session_process_event(vine_session_h session)
66 CHECK_FEATURE_SUPPORTED;
68 return _vine_session_process_event(session);
71 API int vine_session_create(vine_session_h *session)
74 CHECK_FEATURE_SUPPORTED;
76 return _vine_session_create(session);
79 API int vine_session_destroy(vine_session_h session)
82 CHECK_FEATURE_SUPPORTED;
84 return _vine_session_destroy(session);
87 API int vine_session_set_registered_cb(vine_session_h session,
88 vine_session_registered_cb callback, void *user_data)
91 CHECK_FEATURE_SUPPORTED;
93 return _vine_session_set_registered_cb(session, callback, user_data);
96 API int vine_session_unset_registered_cb(vine_session_h session)
99 CHECK_FEATURE_SUPPORTED;
101 return _vine_session_unset_registered_cb(session);
104 API int vine_session_set_discovered_cb(vine_session_h session,
105 vine_session_discovered_cb callback, void *user_data)
108 CHECK_FEATURE_SUPPORTED;
110 return _vine_session_set_discovered_cb(session, callback, user_data);
113 API int vine_session_unset_discovered_cb(vine_session_h session)
116 CHECK_FEATURE_SUPPORTED;
118 return _vine_session_unset_discovered_cb(session);
121 API int vine_session_set_discovery_method(vine_session_h session, vine_discovery_method_e method)
124 CHECK_FEATURE_SUPPORTED;
126 return _vine_session_set_discovery_method(session, method);
129 API int vine_session_register(vine_session_h session,
130 vine_service_h service, const char *iface_name)
133 CHECK_FEATURE_SUPPORTED;
135 return _vine_session_register(session, service, iface_name);
138 API int vine_session_unregister(vine_session_h session)
141 CHECK_FEATURE_SUPPORTED;
143 return _vine_session_unregister(session);
146 API int vine_session_start_discovery(vine_session_h session,
147 const char *service_type, const char *iface_name)
150 CHECK_FEATURE_SUPPORTED;
152 return _vine_session_start_discovery(session, service_type, iface_name);
155 API int vine_session_stop_discovery(vine_session_h session)
158 CHECK_FEATURE_SUPPORTED;
160 return _vine_session_stop_discovery(session);
163 API int vine_session_set_ip_resolved_cb(vine_session_h session,
164 vine_service_h service, vine_session_ip_resolved_cb callback, void *user_data)
167 CHECK_FEATURE_SUPPORTED;
169 return _vine_session_set_ip_resolved_cb(session, service, callback, user_data);
172 API int vine_session_unset_ip_resolved_cb(vine_session_h session,
173 vine_service_h service)
176 CHECK_FEATURE_SUPPORTED;
178 return _vine_session_unset_ip_resolved_cb(session, service);
181 API int vine_service_create(vine_service_h *service)
184 CHECK_FEATURE_SUPPORTED;
186 return _vine_service_create(service, true);
189 API int vine_service_destroy(vine_service_h service)
192 CHECK_FEATURE_SUPPORTED;
194 return _vine_service_destroy(service);
197 API int vine_service_clone(vine_service_h origin, vine_service_h *cloned)
200 CHECK_FEATURE_SUPPORTED;
202 return _vine_service_clone(origin, cloned);
205 API int vine_service_set_type(vine_service_h service, const char *service_type)
208 CHECK_FEATURE_SUPPORTED;
210 RET_VAL_IF(service == NULL, VINE_ERROR_INVALID_PARAMETER, "service is NULL");
211 RET_VAL_IF(_is_discovered_service(service), VINE_ERROR_INVALID_OPERATION,
212 "cannot set service type for a discovered service");
213 return _vine_service_set_type(service, service_type);
216 API int vine_service_get_type(vine_service_h service, char **service_type)
219 CHECK_FEATURE_SUPPORTED;
221 RET_VAL_IF(service == NULL, VINE_ERROR_INVALID_PARAMETER, "service is NULL");
222 RET_VAL_IF(service_type == NULL, VINE_ERROR_INVALID_PARAMETER,
223 "service_type is NULL");
225 *service_type = (char *)strndup(_vine_service_get_type(service),
226 VINE_MAX_SERVICE_TYPE_LEN);
227 RET_VAL_IF(*service_type == NULL, VINE_ERROR_OUT_OF_MEMORY, "Out of memory");
228 return VINE_ERROR_NONE;
231 API int vine_service_set_name(vine_service_h service, const char *service_name)
234 CHECK_FEATURE_SUPPORTED;
236 RET_VAL_IF(service == NULL, VINE_ERROR_INVALID_PARAMETER, "service is NULL");
237 RET_VAL_IF(_is_discovered_service(service), VINE_ERROR_INVALID_OPERATION,
238 "cannot set service name for a discovered service");
239 return _vine_service_set_name(service, service_name);
242 API int vine_service_get_name(vine_service_h service, char **service_name)
245 CHECK_FEATURE_SUPPORTED;
247 RET_VAL_IF(service == NULL, VINE_ERROR_INVALID_PARAMETER, "service is NULL");
248 RET_VAL_IF(service_name == NULL, VINE_ERROR_INVALID_PARAMETER,
249 "service_name is NULL");
251 *service_name = (char *)strndup(_vine_service_get_name(service),
252 VINE_MAX_SERVICE_TYPE_LEN);
253 RET_VAL_IF(*service_name == NULL, VINE_ERROR_OUT_OF_MEMORY, "Out of memory");
254 return VINE_ERROR_NONE;
257 API int vine_service_add_attribute(vine_service_h service,
258 const char *key, const char *value)
261 CHECK_FEATURE_SUPPORTED;
263 RET_VAL_IF(service == NULL, VINE_ERROR_INVALID_PARAMETER, "service is NULL");
264 RET_VAL_IF(_is_discovered_service(service), VINE_ERROR_INVALID_OPERATION,
265 "cannot add attributes for a discovered service");
266 return _vine_service_add_attribute(service, key, value);
269 API int vine_service_remove_attribute(vine_service_h service, const char *key)
272 CHECK_FEATURE_SUPPORTED;
274 RET_VAL_IF(service == NULL, VINE_ERROR_INVALID_PARAMETER, "service is NULL");
275 RET_VAL_IF(_is_discovered_service(service), VINE_ERROR_INVALID_OPERATION,
276 "cannot add attributes for a discovered service");
277 return _vine_service_remove_attribute(service, key);
280 API int vine_service_foreach_attribute(vine_service_h service,
281 vine_service_attribute_cb callback, void *user_data)
284 CHECK_FEATURE_SUPPORTED;
286 return _vine_service_foreach_attribute(service, callback, user_data);
289 API int vine_service_set_port(vine_service_h service, int port)
292 CHECK_FEATURE_SUPPORTED;
294 RET_VAL_IF(service == NULL, VINE_ERROR_INVALID_PARAMETER, "service is NULL");
295 RET_VAL_IF(_is_discovered_service(service), VINE_ERROR_INVALID_OPERATION,
296 "cannot set port for a discovered service");
297 return _vine_service_set_port(service, port);
300 API int vine_service_get_port(vine_service_h service, int *port)
303 CHECK_FEATURE_SUPPORTED;
305 RET_VAL_IF(service == NULL, VINE_ERROR_INVALID_PARAMETER, "service is NULL");
306 RET_VAL_IF(port == NULL, VINE_ERROR_INVALID_PARAMETER, "port is NULL");
308 *port = _vine_service_get_port(service);
309 return VINE_ERROR_NONE;
312 API int vine_dp_create(vine_session_h session, vine_dp_type_e type, vine_dp_h *dp)
315 CHECK_FEATURE_SUPPORTED;
317 return _vine_dp_create(session, type, dp);
320 API int vine_dp_destroy(vine_dp_h dp)
323 CHECK_FEATURE_SUPPORTED;
325 return _vine_dp_destroy(dp);
328 API int vine_dp_set_iface_name(vine_dp_h dp, const char *iface_name)
331 CHECK_FEATURE_SUPPORTED;
333 return _vine_dp_set_iface_name(dp, iface_name);
336 API int vine_dp_set_address_family(vine_dp_h dp, vine_address_family_e addr_family)
339 CHECK_FEATURE_SUPPORTED;
341 return _vine_dp_set_addr_family(dp, addr_family);
344 API int vine_dp_set_remote_ip(vine_dp_h dp, vine_address_family_e addr_family, const char *ip)
347 CHECK_FEATURE_SUPPORTED;
349 return _vine_dp_set_remote_ip(dp, addr_family, ip);
352 API int vine_dp_set_port(vine_dp_h dp, int port)
355 CHECK_FEATURE_SUPPORTED;
357 return _vine_dp_set_port(dp, port);
360 API int vine_dp_get_port(vine_dp_h dp, int *port)
363 CHECK_FEATURE_SUPPORTED;
365 return _vine_dp_get_port(dp, port);
368 API int vine_dp_set_topic(vine_dp_h dp, const char *topic)
371 CHECK_FEATURE_SUPPORTED;
373 return _vine_dp_set_topic(dp, topic);
376 API int vine_dp_set_max_connections(vine_dp_h dp, int max_conn)
379 CHECK_FEATURE_SUPPORTED;
381 return _vine_dp_set_max_connections(dp, max_conn);
384 API int vine_dp_set_security(vine_dp_h dp, vine_security_h security)
387 CHECK_FEATURE_SUPPORTED;
389 return _vine_dp_set_security(dp, security);
392 API int vine_dp_set_accepted_cb(vine_dp_h dp, vine_dp_accepted_cb callback, void *user_data)
395 CHECK_FEATURE_SUPPORTED;
397 return _vine_dp_set_accepted_cb(dp, callback, user_data);
400 API int vine_dp_unset_accepted_cb(vine_dp_h dp)
403 CHECK_FEATURE_SUPPORTED;
405 return _vine_dp_unset_accepted_cb(dp);
408 API int vine_dp_set_terminated_cb(vine_dp_h dp, vine_dp_terminated_cb callback, void *user_data)
411 CHECK_FEATURE_SUPPORTED;
413 return _vine_dp_set_terminated_cb(dp, callback, user_data);
416 API int vine_dp_unset_terminated_cb(vine_dp_h dp)
419 CHECK_FEATURE_SUPPORTED;
421 return _vine_dp_unset_terminated_cb(dp);
424 API int vine_dp_open(vine_dp_h dp, vine_dp_opened_cb callback, void *user_data)
427 CHECK_FEATURE_SUPPORTED;
429 return _vine_dp_open(dp, callback, user_data);
432 API int vine_dp_close(vine_dp_h dp)
435 CHECK_FEATURE_SUPPORTED;
437 return _vine_dp_close(dp);
440 API int vine_dp_send(vine_dp_h dp, unsigned char *buf, size_t len)
443 CHECK_FEATURE_SUPPORTED;
445 return _vine_dp_send(dp, buf, len);
448 API int vine_dp_recv(vine_dp_h dp,
449 unsigned char *buf, size_t buf_len, size_t *read_len)
452 CHECK_FEATURE_SUPPORTED;
454 return _vine_dp_recv(dp, buf, buf_len, read_len);
457 API int vine_dp_set_received_cb(vine_dp_h dp, vine_dp_received_cb callback, void *user_data)
460 CHECK_FEATURE_SUPPORTED;
462 return _vine_dp_set_received_cb(dp, callback, user_data);
465 API int vine_dp_unset_received_cb(vine_dp_h dp)
468 CHECK_FEATURE_SUPPORTED;
470 return _vine_dp_unset_received_cb(dp);
473 API int vine_security_create(vine_security_h *security)
476 CHECK_FEATURE_SUPPORTED;
478 return _vine_security_create(security);
481 API int vine_security_destroy(vine_security_h security)
484 CHECK_FEATURE_SUPPORTED;
486 return _vine_security_destroy(security);
489 API int vine_security_set_type(vine_security_h security, vine_security_type_e type)
492 CHECK_FEATURE_SUPPORTED;
494 return _vine_security_set_type(security, type);
497 API int vine_security_get_type(vine_security_h security, vine_security_type_e *type)
500 CHECK_FEATURE_SUPPORTED;
502 return _vine_security_get_type(security, type);
505 API int vine_security_set_tls_version(vine_security_h security,
506 vine_security_tls_version_e version)
509 CHECK_FEATURE_SUPPORTED;
511 return _vine_security_set_tls_version(security, version);
514 API int vine_security_get_tls_version(vine_security_h security,
515 vine_security_tls_version_e *version)
518 CHECK_FEATURE_SUPPORTED;
520 return _vine_security_get_tls_version(security, version);
523 API int vine_security_set_verification_flags(vine_security_h security, int flags)
526 CHECK_FEATURE_SUPPORTED;
528 return _vine_security_set_verification_flags(security, flags);
531 API int vine_security_get_verification_flags(vine_security_h security, int*flags)
534 CHECK_FEATURE_SUPPORTED;
536 return _vine_security_get_verification_flags(security, flags);
539 API int vine_security_set_ca_path(vine_security_h security, const char *ca_path)
542 CHECK_FEATURE_SUPPORTED;
544 return _vine_security_set_ca_path(security, ca_path);
547 API int vine_security_get_ca_path(vine_security_h security, char **ca_path)
550 CHECK_FEATURE_SUPPORTED;
552 return _vine_security_get_ca_path(security, ca_path);
555 API int vine_security_set_cert_path(vine_security_h security, const char *cert_path)
558 CHECK_FEATURE_SUPPORTED;
560 return _vine_security_set_cert_path(security, cert_path);
563 API int vine_security_get_cert_path(vine_security_h security, char **cert_path)
566 CHECK_FEATURE_SUPPORTED;
568 return _vine_security_get_cert_path(security, cert_path);
571 API int vine_security_set_private_key(vine_security_h security, const char *key_path)
574 CHECK_FEATURE_SUPPORTED;
576 return _vine_security_set_private_key(security, key_path);
579 API int vine_security_get_private_key(vine_security_h security, char **key_path)
582 CHECK_FEATURE_SUPPORTED;
584 return _vine_security_get_private_key(security, key_path);
587 API int vine_security_set_psk(vine_security_h security, const char *psk)
590 CHECK_FEATURE_SUPPORTED;
592 return _vine_security_set_psk(security, psk);
595 API int vine_security_get_psk(vine_security_h security, char **psk)
598 CHECK_FEATURE_SUPPORTED;
600 return _vine_security_get_psk(security, psk);