Removed Glib connected functions from API
[platform/core/security/vasum.git] / client / vasum-client.h
1 /*
2  *  Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *  Contact: Mateusz Malicki <m.malicki2@samsung.com>
5  *
6  *  Licensed under the Apache License, Version 2.0 (the "License");
7  *  you may not use this file except in compliance with the License.
8  *  You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *  Unless required by applicable law or agreed to in writing, software
13  *  distributed under the License is distributed on an "AS IS" BASIS,
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License
17  */
18
19
20 /**
21  * @file
22  * @author  Mateusz Malicki (m.malicki2@samsung.com)
23  * @brief   This file contains the public API for Vasum Client
24  *
25  * @par Example usage:
26  * @code
27 #include <stdio.h>
28 #include "client/vasum-client.h"
29
30 int main(int argc, char** argv)
31 {
32     VsmStatus status;
33     VsmClient client;
34     VsmArrayString values = NULL;
35     int ret = 0;
36
37     client = vsm_client_create(); // create client handle
38     if (NULL == client) {
39         // error!
40         ret = 1;
41         goto finish;
42     }
43
44     status = vsm_connect(client); // connect to dbus
45     if (VSMCLIENT_SUCCESS != status) {
46         // error!
47         ret = 1;
48         goto finish;
49     }
50
51     status = vsm_get_zone_ids(client, &values);
52     if (VSMCLIENT_SUCCESS != status) {
53         // error!
54         ret = 1;
55         goto finish;
56     }
57
58     // print array
59     for (VsmArrayString iValues = values; *iValues; iValues++) {
60         printf("%s\n", *iValues);
61     }
62
63 finish:
64     vsm_array_string_free(values); // free memory
65     vsm_client_free(client); // destroy client handle
66     return ret;
67 }
68  @endcode
69  */
70
71 #ifndef VASUM_CLIENT_H
72 #define VASUM_CLIENT_H
73
74 #include <stdint.h>
75 #include <sys/stat.h>
76 #include <netinet/ip.h>
77 #include <linux/if_link.h>
78
79 #ifdef __cplusplus
80 extern "C"
81 {
82 #endif
83
84 /**
85  * vasum-server's client pointer.
86  */
87 typedef void* VsmClient;
88
89 /**
90  * NULL-terminated string type.
91  *
92  * @sa vsm_array_string_free
93  */
94 typedef char* VsmString;
95
96 /**
97  * NULL-terminated array of strings type.
98  *
99  * @sa vsm_string_free
100  */
101 typedef VsmString* VsmArrayString;
102
103 /**
104  * Completion status of communication function.
105  */
106 typedef enum {
107     VSMCLIENT_CUSTOM_ERROR,     /**< User specified error */
108     VSMCLIENT_IO_ERROR,         /**< Input/Output error */
109     VSMCLIENT_OPERATION_FAILED, /**< Operation failed */
110     VSMCLIENT_INVALID_ARGUMENT, /**< Invalid argument */
111     VSMCLIENT_OTHER_ERROR,      /**< Other error */
112     VSMCLIENT_SUCCESS           /**< Success */
113 } VsmStatus;
114
115 /**
116  * Subscription id
117  */
118 typedef unsigned int VsmSubscriptionId;
119
120 /**
121  * States of zone
122  */
123 typedef enum {
124     STOPPED,
125     STARTING,
126     RUNNING,
127     STOPPING,
128     ABORTING,
129     FREEZING,
130     FROZEN,
131     THAWED,
132     LOCKED,
133     MAX_STATE,
134     ACTIVATING = 128
135 } VsmZoneState;
136
137 /**
138  * Zone information structure
139  */
140 typedef struct {
141     char* id;
142     int terminal;
143     VsmZoneState state;
144     char *rootfs_path;
145 } VsmZoneStructure;
146
147 /**
148  * Zone information
149  */
150 typedef VsmZoneStructure* VsmZone;
151
152 /**
153  * Netowrk device type
154  */
155 typedef enum {
156     VSMNETDEV_VETH,
157     VSMNETDEV_PHYS,
158     VSMNETDEV_MACVLAN
159 } VsmNetdevType;
160
161 /**
162  * Network device information structure
163  */
164 typedef struct {
165     char* name;
166     VsmNetdevType type;
167 } VsmNetdevStructure;
168
169 /**
170  * Network device information
171  */
172 typedef VsmNetdevStructure* VsmNetdev;
173
174 /**
175  * File type
176  */
177 typedef enum {
178     VSMFILE_DIRECTORY,
179     VSMFILE_FIFO,
180     VSMFILE_REGULAR
181 } VsmFileType;
182
183 #ifndef __VASUM_WRAPPER_SOURCE__
184
185 /**
186  * Create a new vasum-server's client.
187  *
188  * @return Created client pointer or NULL on failure.
189  */
190 VsmClient vsm_client_create();
191
192 /**
193  * Release client resources.
194  *
195  * @param[in] client vasum-server's client
196  */
197 void vsm_client_free(VsmClient client);
198
199 /**
200  * Get status code of last vasum-server communication.
201  *
202  * @param[in] client vasum-server's client
203  * @return status of this function call
204  */
205 VsmStatus vsm_get_status(VsmClient client);
206
207 /**
208  * Get status message of the last vasum-server communication.
209  *
210  * @param[in] client vasum-server's client
211  * @return last status message from vasum-server communication
212  */
213 const char* vsm_get_status_message(VsmClient client);
214
215 /**
216  * Connect client to the vasum-server.
217  *
218  * @param[in] client vasum-server's client
219  * @return status of this function call
220  */
221 VsmStatus vsm_connect(VsmClient client);
222
223 /**
224  * Connect client to the vasum-server via custom address.
225  *
226  * @param[in] client vasum-server's client
227  * @param[in] address dbus address
228  * @return status of this function call
229  */
230 VsmStatus vsm_connect_custom(VsmClient client, const char* address);
231
232 /**
233  * Release VsmArrayString.
234  *
235  * @param[in] astring VsmArrayString
236  */
237 void vsm_array_string_free(VsmArrayString astring);
238
239 /**
240  * Release VsmString.
241  *
242  * @param string VsmString
243  */
244 void vsm_string_free(VsmString string);
245
246 /**
247  * Release VsmZone
248  *
249  * @param zone VsmZone
250  */
251 void vsm_zone_free(VsmZone zone);
252
253 /**
254  * Release VsmNetdev
255  *
256  * @param netdev VsmNetdev
257  */
258 void vsm_netdev_free(VsmNetdev netdev);
259
260 /**
261  * @name Host API
262  *
263  * Functions using org.tizen.vasum.host.manager D-Bus interface.
264  *
265  * @{
266  */
267
268 /**
269  * Zone's D-Bus state change callback function signature.
270  *
271  * @param[in] zoneId affected zone id
272  * @param[in] address new D-Bus address
273  * @param data custom user's data pointer passed to vsm_add_state_callback() function
274  */
275 typedef void (*VsmZoneDbusStateCallback)(const char* zoneId,
276                                              const char* address,
277                                              void* data);
278
279 /**
280  * Get dbus address of each zone.
281  *
282  * @param[in] client vasum-server's client
283  * @param[out] keys array of zones name
284  * @param[out] values array of zones dbus address
285  * @return status of this function call
286  * @post keys[i] corresponds to values[i]
287  * @remark Use vsm_array_string_free() to free memory occupied by @p keys and @p values.
288  */
289 VsmStatus vsm_get_zone_dbuses(VsmClient client, VsmArrayString* keys, VsmArrayString* values);
290
291 /**
292  * Get zones name.
293  *
294  * @param[in] client vasum-server's client
295  * @param[out] array array of zones name
296  * @return status of this function call
297  * @remark Use vsm_array_string_free() to free memory occupied by @p array.
298  */
299 VsmStatus vsm_get_zone_ids(VsmClient client, VsmArrayString* array);
300
301 /**
302  * Get active (foreground) zone name.
303  *
304  * @param[in] client vasum-server's client
305  * @param[out] id active zone name
306  * @return status of this function call
307  * @remark Use @p vsm_string_free() to free memory occupied by @p id.
308  */
309 VsmStatus vsm_get_active_zone_id(VsmClient client, VsmString* id);
310
311 /**
312  * Get zone rootfs path.
313  *
314  * @param[in] client vasum-server's client
315  * @param[in] id zone name
316  * @param[out] rootpath zone rootfs path
317  * @return status of this function call
318  * @remark Use @p vsm_string_free() to free memory occupied by @p rootpath.
319  */
320 VsmStatus vsm_get_zone_rootpath(VsmClient client, const char* id, VsmString* rootpath);
321
322 /**
323  * Get zone name of process with given pid.
324  *
325  * @param[in] client vasum-server's client
326  * @param[in] pid process id
327  * @param[out] id active zone name
328  * @return status of this function call
329  * @remark Use @p vsm_string_free() to free memory occupied by @p id.
330  */
331 VsmStatus vsm_lookup_zone_by_pid(VsmClient client, int pid, VsmString* id);
332
333 /**
334  * Get zone informations of zone with given id.
335  *
336  * @param[in] client vasum-server's client
337  * @param[in] id zone name
338  * @param[out] zone zone informations
339  * @return status of this function call
340  * @remark Use @p vsm_zone_free() to free memory occupied by @p zone
341  */
342 VsmStatus vsm_lookup_zone_by_id(VsmClient client, const char* id, VsmZone* zone);
343
344 /**
345  * Get zone name with given terminal.
346  *
347  * @param[in] client vasum-server's client
348  * @param[in] terminal terminal id
349  * @param[out] id zone name with given terminal
350  * @return status of this function call
351  * @remark Use @p vsm_string_free() to free memory occupied by @p id.
352  */
353 VsmStatus vsm_lookup_zone_by_terminal_id(VsmClient client, int terminal, VsmString* id);
354
355 /**
356  * Set active (foreground) zone.
357  *
358  * @param[in] client vasum-server's client
359  * @param[in] id zone name
360  * @return status of this function call
361  */
362 VsmStatus vsm_set_active_zone(VsmClient client, const char* id);
363
364 /**
365  * Create and add zone
366  *
367  * @param[in] client vasum-server's client
368  * @param[in] id zone id
369  * @param[in] tname template name, NULL is equivalent to "default"
370  * @return status of this function call
371  */
372 VsmStatus vsm_create_zone(VsmClient client, const char* id, const char* tname);
373
374 /**
375  * Remove zone
376  *
377  * @param[in] client vasum-server's client
378  * @param[in] id zone id
379  * @param[in] force if 0 data will be kept, otherwise data will be lost
380  * @return status of this function call
381  */
382 VsmStatus vsm_destroy_zone(VsmClient client, const char* id, int force);
383
384 /**
385  * Shutdown zone
386  *
387  * @param[in] client vasum-server's client
388  * @param[in] id zone name
389  * @return status of this function call
390  */
391 VsmStatus vsm_shutdown_zone(VsmClient client, const char* id);
392
393 /**
394  * Start zone
395  *
396  * @param[in] client vasum-server's client
397  * @param[in] id zone name
398  * @return status of this function call
399  */
400 VsmStatus vsm_start_zone(VsmClient client, const char* id);
401
402 /**
403  * Lock zone
404  *
405  * @param[in] client vasum-server's client
406  * @param[in] id zone name
407  * @return status of this function call
408  */
409 VsmStatus vsm_lock_zone(VsmClient client, const char* id);
410
411 /**
412  * Unlock zone
413  *
414  * @param[in] client vasum-server's client
415  * @param[in] id zone name
416  * @return status of this function call
417  */
418 VsmStatus vsm_unlock_zone(VsmClient client, const char* id);
419
420 /**
421  * Register dbus state change callback function.
422  *
423  * @note The callback function will be invoked on a different thread.
424  *
425  * @param[in] client vasum-server's client
426  * @param[in] zoneDbusStateCallback callback function
427  * @param[in] data some extra data that will be passed to callback function
428  * @param[out] subscriptionId subscription identifier that can be used to unsubscribe signal,
429  *                      pointer can be NULL.
430  * @return status of this function call
431  */
432 VsmStatus vsm_add_state_callback(VsmClient client,
433                                  VsmZoneDbusStateCallback zoneDbusStateCallback,
434                                  void* data,
435                                  VsmSubscriptionId* subscriptionId);
436
437 /**
438  * Unregister dbus state change callback function.
439  *
440  * @param[in] client vasum-server's client
441  * @param[in] subscriptionId subscription identifier returned by vsm_add_state_callback
442  * @return status of this function call
443  */
444 VsmStatus vsm_del_state_callback(VsmClient client, VsmSubscriptionId subscriptionId);
445
446 /**
447  * Grant access to device
448  *
449  * @param[in] client vasum-server's client
450  * @param[in] zone zone name
451  * @param[in] device device path
452  * @param[in] flags access flags
453  * @return status of this function call
454  */
455 VsmStatus vsm_grant_device(VsmClient client,
456                            const char* zone,
457                            const char* device,
458                            uint32_t flags);
459
460 /**
461  * Revoke access to device
462  *
463  * @param[in] client vasum-server's client
464  * @param[in] zone zone name
465  * @param[in] device device path
466  * @return status of this function call
467  */
468 VsmStatus vsm_revoke_device(VsmClient client, const char* zone, const char* device);
469
470 /**
471  * Get array of netdev from given zone
472  *
473  * @param[in] client vasum-server's client
474  * @param[in] zone zone name
475  * @param[out] netdevIds array of netdev id
476  * @return status of this function call
477  * @remark Use vsm_array_string_free() to free memory occupied by @p netdevIds.
478  */
479 VsmStatus vsm_zone_get_netdevs(VsmClient client, const char* zone, VsmArrayString* netdevIds);
480
481 /**
482  * Get ipv4 address for given netdevId
483  *
484  * @param[in] client vasum-server's client
485  * @param[in] zone zone name
486  * @param[in] netdevId netdev id
487  * @param[out] addr ipv4 address
488  * @return status of this function call
489  */
490 VsmStatus vsm_netdev_get_ipv4_addr(VsmClient client,
491                                    const char* zone,
492                                    const char* netdevId,
493                                    struct in_addr *addr);
494
495 /**
496  * Get ipv6 address for given netdevId
497  *
498  * @param[in] client vasum-server's client
499  * @param[in] zone zone name
500  * @param[in] netdevId netdev id
501  * @param[out] addr ipv6 address
502  * @return status of this function call
503  */
504 VsmStatus vsm_netdev_get_ipv6_addr(VsmClient client,
505                                    const char* zone,
506                                    const char* netdevId,
507                                    struct in6_addr *addr);
508
509 /**
510  * Set ipv4 address for given netdevId
511  *
512  * @param[in] client vasum-server's client
513  * @param[in] zone zone name
514  * @param[in] netdevId netdev id
515  * @param[in] addr ipv4 address
516  * @param[in] prefix bit-length of the network prefix
517  * @return status of this function call
518  */
519 VsmStatus vsm_netdev_set_ipv4_addr(VsmClient client,
520                                    const char* zone,
521                                    const char* netdevId,
522                                    struct in_addr *addr,
523                                    int prefix);
524
525 /**
526  * Set ipv6 address for given netdevId
527  *
528  * @param[in] client vasum-server's client
529  * @param[in] zone zone name
530  * @param[in] netdevId netdev id
531  * @param[in] addr ipv6 address
532  * @param[in] prefix bit-length of the network prefix
533  * @return status of this function call
534  */
535 VsmStatus vsm_netdev_set_ipv6_addr(VsmClient client,
536                                    const char* zone,
537                                    const char* netdevId,
538                                    struct in6_addr *addr,
539                                    int prefix);
540
541 /**
542  * Remove ipv4 address from netdev
543  *
544  * @param[in] client vasum-server's client
545  * @param[in] zone zone name
546  * @param[in] netdevId network device id
547  * @param[in] addr ipv4 address
548  * @param[in] prefix bit-length of the network prefix
549  * @return status of this function call
550  */
551 VsmStatus vsm_netdev_del_ipv4_addr(VsmClient client,
552                                    const char* zone,
553                                    const char* netdevId,
554                                    struct in_addr* addr,
555                                    int prefix);
556
557 /**
558  * Remove ipv6 address from netdev
559  *
560  * @param[in] client vasum-server's client
561  * @param[in] zone zone name
562  * @param[in] netdevId network device id
563  * @param[in] addr ipv6 address
564  * @param[in] prefix bit-length of the network prefix
565  * @return status of this function call
566  */
567 VsmStatus vsm_netdev_del_ipv6_addr(VsmClient client,
568                                    const char* zone,
569                                    const char* netdevId,
570                                    struct in6_addr* addr,
571                                    int prefix);
572
573 /**
574  * Turn up a network device in the zone
575  *
576  * @param[in] client vasum-server's client
577  * @param[in] zone zone name
578  * @param[in] netdevId netdev id
579  * @return status of this function call
580  */
581 VsmStatus vsm_netdev_up(VsmClient client,
582                         const char* zone,
583                         const char* netdevId);
584
585 /**
586  * Turn down a network device in the zone
587  *
588  * @param[in] client vasum-server's client
589  * @param[in] zone zone name
590  * @param[in] netdevId netdev id
591  * @return status of this function call
592  */
593 VsmStatus vsm_netdev_down(VsmClient client,
594                           const char* zone,
595                           const char* netdevId);
596
597
598 /**
599  * Create veth netdev in zone
600  *
601  * @param[in] client vasum-server's client
602  * @param[in] zone zone name
603  * @param[in] zoneDev in host network device id
604  * @param[in] hostDev in zone network device id
605  * @return status of this function call
606  */
607 VsmStatus vsm_create_netdev_veth(VsmClient client,
608                                  const char* zone,
609                                  const char* zoneDev,
610                                  const char* hostDev);
611 /**
612  * Create macvlab in zone
613  *
614  * @param[in] client vasum-server's client
615  * @param[in] zone zone name
616  * @param[in] zoneDev in host network device id
617  * @param[in] hostDev in zone network device id
618  * @return status of this function call
619  */
620 VsmStatus vsm_create_netdev_macvlan(VsmClient client,
621                                     const char* zone,
622                                     const char* zoneDev,
623                                     const char* hostDev,
624                                     enum macvlan_mode mode);
625 /**
626  * Create/move phys netdev in/to zone
627  *
628  * @param[in] client vasum-server's client
629  * @param[in] zone zone name
630  * @param[in] devId network device id
631  * @return status of this function call
632  */
633 VsmStatus vsm_create_netdev_phys(VsmClient client, const char* zone, const char* devId);
634
635 /**
636  * Get netdev informations
637  *
638  * @param[in] client vasum-server's client
639  * @param[in] zone zone name
640  * @param[in] netdevId network device id
641  * @param[out] netdev netdev informations
642  * @return status of this function call
643  * @remark Use vsm_netdev_free() to free memory occupied by @p netdev.
644  */
645 VsmStatus vsm_lookup_netdev_by_name(VsmClient client,
646                                     const char* zone,
647                                     const char* netdevId,
648                                     VsmNetdev* netdev);
649
650 /**
651  * Remove netdev from zone
652  *
653  * @param[in] client vasum-server's client
654  * @param[in] zone zone name
655  * @param[in] devId network device id
656  * @return status of this function call
657  */
658 VsmStatus vsm_destroy_netdev(VsmClient client, const char* zone, const char* devId);
659
660 /**
661  * Create file, directory or pipe in zone
662  *
663  * Declare file, directory or pipe that will be created while zone startup
664  *
665  * @param[in] client vasum-server's client
666  * @param[in] type file type
667  * @param[in] zone zone id
668  * @param[in] path path to file
669  * @param[in] flags if O_CREAT bit is set then file will be created in zone,
670  *                  otherwise file will by copied from host;
671  *                  it is meaningful only when O_CREAT is set
672  * @param[in] mode mode of file
673  * @return status of this function call
674  */
675 VsmStatus vsm_declare_file(VsmClient client,
676                            const char* zone,
677                            VsmFileType type,
678                            const char* path,
679                            int32_t flags,
680                            mode_t mode);
681
682 /**
683  * Create mount point in zone
684  *
685  * Declare mount that will be created while zone startup
686  * Parameters are passed to mount system function
687  *
688  * @param[in] client vasum-server's client
689  * @param[in] source device path (path in host)
690  * @param[in] zone zone id
691  * @param[in] target mount point (path in zone)
692  * @param[in] type filesystem type
693  * @param[in] flags mount flags as in mount function
694  * @param[in] data additional data as in mount function
695  * @return status of this function call
696  */
697 VsmStatus vsm_declare_mount(VsmClient client,
698                             const char* source,
699                             const char* zone,
700                             const char* target,
701                             const char* type,
702                             uint64_t flags,
703                             const char* data);
704
705 /**
706  * Create link in zone
707  *
708  * Declare link that will be created while zone startup
709  * Parameters are passed to link system function
710  *
711  * @param[in] client vasum-server's client
712  * @param[in] source path to link source (in host)
713  * @param[in] zone zone id
714  * @param[in] target path to link name (in zone)
715  * @return status of this function call
716  */
717 VsmStatus vsm_declare_link(VsmClient client,
718                            const char *source,
719                            const char* zone,
720                            const char *target);
721
722 /**
723  * Get all declarations
724  *
725  * Gets all declarations of resourcies
726  * (@see ::vsm_declare_link, @see ::vsm_declare_mount, @see ::vsm_declare_linki)
727  *
728  * @param[in] client vasum-server's client
729  * @param[in] zone zone id
730  * @param[out] declarations array of declarations id
731  * @return status of this function call
732  */
733 VsmStatus vsm_list_declarations(VsmClient client,
734                                 const char* zone,
735                                 VsmArrayString* declarations);
736
737 /**
738  * Remove declaration
739  *
740  * Removes given declaration by its id (@see ::vsm_list_declarations)
741  *
742  * @param[in] client vasum-server's client
743  * @param[in] zone zone id
744  * @param[in] declaration declaration id
745  * @return status of this function call
746  */
747 VsmStatus vsm_remove_declaration(VsmClient client,
748                                  const char* zone,
749                                  VsmString declaration);
750
751
752 /** @} Host API */
753
754
755 /**
756  * @name Zone API
757  *
758  * Functions using org.tizen.vasum.zone.manager D-Bus interface.
759  *
760  * @{
761  */
762
763 /**
764  * Notification callback function signature.
765  *
766  * @param[in] zone source zone
767  * @param[in] application sending application name
768  * @param[in] message notification message
769  * @param data custom user's data pointer passed to vsm_add_notification_callback()
770  */
771 typedef void (*VsmNotificationCallback)(const char* zone,
772                                         const char* application,
773                                         const char* message,
774                                         void* data);
775 /**
776  * Send message to active zone.
777  *
778  * @param[in] client vasum-server's client
779  * @param[in] application application name
780  * @param[in] message message
781  * @return status of this function call
782  */
783 VsmStatus vsm_notify_active_zone(VsmClient client, const char* application, const char* message);
784
785 /**
786  * Move file between zones.
787  *
788  * @param[in] client vasum-server's client
789  * @param[in] destZone destination zone id
790  * @param[in] path path to moved file
791  * @return status of this function call
792  */
793 VsmStatus vsm_file_move_request(VsmClient client, const char* destZone, const char* path);
794
795 /**
796  * Register notification callback function.
797  *
798  * @note The callback function will be invoked on a different thread.
799  *
800  * @param[in] client vasum-server's client
801  * @param[in] notificationCallback callback function
802  * @param[in] data some extra data that will be passed to callback function
803  * @param[out] subscriptionId subscription identifier that can be used to unsubscribe signal,
804  *                      pointer can be NULL.
805  * @return status of this function call
806  */
807 VsmStatus vsm_add_notification_callback(VsmClient client,
808                                         VsmNotificationCallback notificationCallback,
809                                         void* data,
810                                         VsmSubscriptionId* subscriptionId);
811
812 /**
813  * Unregister notification callback function.
814  *
815  * @param[in] client vasum-server's client
816  * @param[in] subscriptionId subscription identifier returned by vsm_add_notification_callback
817  * @return status of this function call
818  */
819 VsmStatus vsm_del_notification_callback(VsmClient client, VsmSubscriptionId subscriptionId);
820
821 #endif /* __VASUM_WRAPPER_SOURCE__ */
822
823 /** @} Zone API */
824
825 #ifdef __cplusplus
826 }
827 #endif
828
829 #endif /* VASUM_CLIENT_H */