Remove wrapper. Old API is not supported anymore.
[platform/core/security/vasum.git] / client / vasum-client.h
index 06ad043..47bac7b 100644 (file)
 
 /**
  * @file
- * @author  Mateusz Malicki (m.malicki2@samsung.com)
- * @brief   This file contains the public API for Vasum Client
+ * @author   Mateusz Malicki (m.malicki2@samsung.com)
+ * @brief    This file contains the public API for Vasum Client
+ * @defgroup libvasum-client libvasum-client
+ * @brief    C library for interfacing Vasum
+ *
+ * All functionalities that are possible using the Vasum's Command Line Interface can also be done with libvasum-client's calls.
+ *
+ * @par Simple usage:
+ * Basic usage:
+ * - Create VsmClient with vsm_client_create(). It'll be needed for all communication with Vasum.
+ * - Establish the connection with the daemon using vsm_connect()
+ * - Do what you need to do with the zones
+ * - Free the client with vsm_client_free()
  *
- * @par Example usage:
  * @code
 #include <stdio.h>
-#include "client/vasum-client.h"
+#include <vasum-client.h>
 
 int main(int argc, char** argv)
 {
@@ -34,14 +44,16 @@ int main(int argc, char** argv)
     VsmArrayString values = NULL;
     int ret = 0;
 
-    client = vsm_client_create(); // create client handle
+    // Create client handle
+    client = vsm_client_create();
     if (NULL == client) {
         // error!
         ret = 1;
         goto finish;
     }
 
-    status = vsm_connect(client); // connect to dbus
+    // Connect to Vasum
+    status = vsm_connect(client);
     if (VSMCLIENT_SUCCESS != status) {
         // error!
         ret = 1;
@@ -66,8 +78,82 @@ finish:
     return ret;
 }
  @endcode
- */
 
+ * @par Polling loop
+ *
+ * By default libVasum will create a separate thread for his communication with Vasum. Most of the time it'll sleep so it shouldn't be a concern.
+ * It's also possible to connect to an existing polling loop. To do this you'll need to:
+ * - Get the poll file descriptor with vsm_get_poll_fd()
+ * - Use epoll/poll/select to wait for events on the file descriptor
+ * - Call vsm_enter_eventloop() every time there's an event
+ *
+ * For example:
+ * @code
+#include <pthread.h>
+#include <assert.h>
+#include <stdio.h>
+#include <signal.h>
+#include <sys/epoll.h>
+#include <vasum-client.h>
+
+volatile static sig_atomic_t running;
+static int LOOP_INTERVAL = 1000; // ms
+
+void* main_loop(void* client)
+{
+    int fd = -1;
+    VsmStatus status = vsm_get_poll_fd(client, &fd);
+    assert(VSMCLIENT_SUCCESS == status);
+
+    while (running) {
+        struct epoll_event event;
+        int num = epoll_wait(fd, &event, 1, LOOP_INTERVAL);
+        if (num > 0) {
+            status = vsm_enter_eventloop(client, 0 , 0);
+            assert(VSMCLIENT_SUCCESS == status);
+        }
+    }
+    return NULL;
+}
+
+int main(int argc, char** argv)
+{
+    pthread_t loop;
+    VsmStatus status;
+    VsmClient client;
+    int ret = 0;
+
+    client = vsm_client_create();
+    assert(client);
+
+    status = vsm_set_dispatcher_type(client, VSMDISPATCHER_EXTERNAL);
+    assert(VSMCLIENT_SUCCESS == status);
+
+    status = vsm_connect(client);
+    assert(VSMCLIENT_SUCCESS == status);
+
+    // start event loop
+    running = 1;
+    ret = pthread_create(&loop, NULL, main_loop, client);
+    assert(ret == 0);
+
+    // make vsm_* calls on client
+    // ...
+
+    status = vsm_disconnect(client);
+    assert(VSMCLIENT_SUCCESS == status);
+
+    //stop event loop
+    running = 0;
+    ret = pthread_join(loop, NULL);
+    assert(ret == 0);
+
+    vsm_client_free(client); // destroy client handle
+    return ret;
+}
+ @endcode
+ */
+/*@{*/
 #ifndef VASUM_CLIENT_H
 #define VASUM_CLIENT_H
 
@@ -82,26 +168,27 @@ extern "C"
 #endif
 
 /**
- * vasum-server's client pointer.
+ * vasum-server's opaque client pointer.
  */
 typedef void* VsmClient;
 
 /**
  * NULL-terminated string type.
  *
- * @sa vsm_array_string_free
+ * @sa vsm_string_free
  */
 typedef char* VsmString;
 
 /**
  * NULL-terminated array of strings type.
  *
- * @sa vsm_string_free
+ * @sa vsm_array_string_free
  */
 typedef VsmString* VsmArrayString;
 
+typedef void *VsmAddrList;
 /**
- * Completion status of communication function.
+ * Completion status of libvasum-client's functions
  */
 typedef enum {
     VSMCLIENT_CUSTOM_ERROR,     /**< User specified error */
@@ -135,19 +222,9 @@ typedef enum {
 } VsmZoneState;
 
 /**
- * Zone information structure
- */
-typedef struct {
-    char* id;
-    int terminal;
-    VsmZoneState state;
-    char *rootfs_path;
-} VsmZoneStructure;
-
-/**
  * Zone information
  */
-typedef VsmZoneStructure* VsmZone;
+typedef void* VsmZone;
 
 /**
  * Netowrk device type
@@ -159,17 +236,9 @@ typedef enum {
 } VsmNetdevType;
 
 /**
- * Network device information structure
- */
-typedef struct {
-    char* name;
-    VsmNetdevType type;
-} VsmNetdevStructure;
-
-/**
  * Network device information
  */
-typedef VsmNetdevStructure* VsmNetdev;
+typedef void* VsmNetdev;
 
 /**
  * File type
@@ -182,80 +251,12 @@ typedef enum {
 
 /**
  * Event dispacher types.
- *
- * @par Example usage:
- * @code
-#include <pthread.h>
-#include <assert.h>
-#include <stdio.h>
-#include <signal.h>
-#include <sys/epoll.h>
-#include <vasum-client.h>
-
-volatile static sig_atomic_t running;
-static int LOOP_INTERVAL = 1000; // ms
-
-void* main_loop(void* client)
-{
-    int fd = -1;
-    VsmStatus status = vsm_get_poll_fd(client, &fd);
-    assert(VSMCLIENT_SUCCESS == status);
-
-    while (running) {
-        struct epoll_event event;
-        int num = epoll_wait(fd, &event, 1, LOOP_INTERVAL);
-        if (num > 0) {
-            status = vsm_enter_eventloop(client, 0 , 0);
-            assert(VSMCLIENT_SUCCESS == status);
-        }
-    }
-    return NULL;
-}
-
-int main(int argc, char** argv)
-{
-    pthread_t loop;
-    VsmStatus status;
-    VsmClient client;
-    int ret = 0;
-
-    client = vsm_client_create();
-    assert(client);
-
-    status = vsm_set_dispatcher_type(client, VSMDISPATCHER_EXTERNAL);
-    assert(VSMCLIENT_SUCCESS == status);
-
-    status = vsm_connect(client);
-    assert(VSMCLIENT_SUCCESS == status);
-
-    // start event loop
-    running = 1;
-    ret = pthread_create(&loop, NULL, main_loop, client);
-    assert(ret == 0);
-
-    // make vsm_* calls on client
-    // ...
-
-    status = vsm_disconnect(client);
-    assert(VSMCLIENT_SUCCESS == status);
-
-    //stop event loop
-    running = 0;
-    ret = pthread_join(loop, NULL);
-    assert(ret == 0);
-
-    vsm_client_free(client); // destroy client handle
-    return ret;
-}
- @endcode
  */
 typedef enum {
     VSMDISPATCHER_EXTERNAL,         /**< User must handle dispatching messages */
     VSMDISPATCHER_INTERNAL          /**< Library will take care of dispatching messages */
 } VsmDispacherType;
 
-#ifndef __VASUM_WRAPPER_SOURCE__
-
 /**
  * Get file descriptor associated with event dispatcher of zone client
  *
@@ -371,6 +372,38 @@ void vsm_array_string_free(VsmArrayString astring);
 void vsm_string_free(VsmString string);
 
 /**
+ * Get zone id (offline)
+ *
+ * @param zone VsmZone
+ * @return zone id
+ */
+VsmString vsm_zone_get_id(VsmZone zone);
+
+/**
+ * Get zone terminal (offline)
+ *
+ * @param zone VsmZone
+ * @return zone terminal
+ */
+int vsm_zone_get_terminal(VsmZone zone);
+
+/**
+ * Get zone state (offline)
+ *
+ * @param zone VsmZone
+ * @return zone state
+ */
+VsmZoneState vsm_zone_get_state(VsmZone zone);
+
+/**
+ * Get zone rootfs path (offline)
+ *
+ * @param zone VsmZone
+ * @return zone rootfs path
+ */
+VsmString vsm_zone_get_rootfs(VsmZone zone);
+
+/**
  * Release VsmZone
  *
  * @param zone VsmZone
@@ -378,19 +411,27 @@ void vsm_string_free(VsmString string);
 void vsm_zone_free(VsmZone zone);
 
 /**
- * Release VsmNetdev
+ * Get netdev name (offline)
  *
  * @param netdev VsmNetdev
+ * @return netdev name
  */
-void vsm_netdev_free(VsmNetdev netdev);
+VsmString vsm_netdev_get_name(VsmNetdev netdev);
 
 /**
- * @name Host API
+ * Get netdev type (offline)
  *
- * Functions using org.tizen.vasum.host.manager D-Bus interface.
+ * @param netdev VsmNetdev
+ * @return netdev type
+ */
+VsmNetdevType vsm_netdev_get_type(VsmNetdev netdev);
+
+/**
+ * Release VsmNetdev
  *
- * @{
+ * @param netdev VsmNetdev
  */
+void vsm_netdev_free(VsmNetdev netdev);
 
 /**
  * Zone's D-Bus state change callback function signature.
@@ -452,17 +493,6 @@ VsmStatus vsm_get_zone_ids(VsmClient client, VsmArrayString* array);
 VsmStatus vsm_get_active_zone_id(VsmClient client, VsmString* id);
 
 /**
- * Get zone rootfs path.
- *
- * @param[in] client vasum-server's client
- * @param[in] id zone name
- * @param[out] rootpath zone rootfs path
- * @return status of this function call
- * @remark Use @p vsm_string_free() to free memory occupied by @p rootpath.
- */
-VsmStatus vsm_get_zone_rootpath(VsmClient client, const char* id, VsmString* rootpath);
-
-/**
  * Get zone name of process with given pid.
  *
  * @param[in] client vasum-server's client
@@ -621,6 +651,29 @@ VsmStatus vsm_revoke_device(VsmClient client, const char* zone, const char* devi
  */
 VsmStatus vsm_zone_get_netdevs(VsmClient client, const char* zone, VsmArrayString* netdevIds);
 
+
+/**
+ * Get ipv4 address for given netdevId
+ *
+ * @param[in] client vasum-server's client
+ * @param[in] zone zone name
+ * @param[in] netdevId netdev id
+ * @param[out] addrs ip address array
+ * @return status of this function call
+ * @remark Use vsm_netdev_addr_free() to free memory occupied by address array.
+ */
+VsmStatus vsm_netdev_get_ip_addr(VsmClient client,
+                                 const char* zone,
+                                 const char* netdevId,
+                                 VsmAddrList *addrs);
+
+/**
+ * Release VsmAddrList
+ *
+ * @param addrs VsmAddrList
+ */
+void vsm_addrlist_free(VsmAddrList addrs);
+
 /**
  * Get ipv4 address for given netdevId
  *
@@ -650,7 +703,7 @@ VsmStatus vsm_netdev_get_ipv6_addr(VsmClient client,
                                    struct in6_addr *addr);
 
 /**
- * Set ipv4 address for given netdevId
+ * Add ipv4 address for given netdevId
  *
  * @param[in] client vasum-server's client
  * @param[in] zone zone name
@@ -659,14 +712,14 @@ VsmStatus vsm_netdev_get_ipv6_addr(VsmClient client,
  * @param[in] prefix bit-length of the network prefix
  * @return status of this function call
  */
-VsmStatus vsm_netdev_set_ipv4_addr(VsmClient client,
+VsmStatus vsm_netdev_add_ipv4_addr(VsmClient client,
                                    const char* zone,
                                    const char* netdevId,
                                    struct in_addr *addr,
                                    int prefix);
 
 /**
- * Set ipv6 address for given netdevId
+ * Add ipv6 address for given netdevId
  *
  * @param[in] client vasum-server's client
  * @param[in] zone zone name
@@ -675,7 +728,7 @@ VsmStatus vsm_netdev_set_ipv4_addr(VsmClient client,
  * @param[in] prefix bit-length of the network prefix
  * @return status of this function call
  */
-VsmStatus vsm_netdev_set_ipv6_addr(VsmClient client,
+VsmStatus vsm_netdev_add_ipv6_addr(VsmClient client,
                                    const char* zone,
                                    const char* netdevId,
                                    struct in6_addr *addr,
@@ -902,13 +955,38 @@ VsmStatus vsm_remove_declaration(VsmClient client,
  */
 VsmStatus vsm_clean_up_zones_root(VsmClient client);
 
-/** @} Host API */
+/**
+ * Retrieve array size
+ *
+ * @return array size
+ */
+unsigned int vsm_addrlist_size(VsmAddrList addrs);
 
+/**
+ * Get address type for i'th entry
+ *
+ * @return network type (AF_INET or AF_INET6)
+ */
+int vsm_addrlist_get_type(VsmAddrList addrs, unsigned int i);
 
-#endif /* __VASUM_WRAPPER_SOURCE__ */
+/**
+ * Get pointer to in_addr property for i'th entry
+ * see inet_ntop man pages
+ *
+ * @return poiner of in_addr
+ */
+const void *vsm_addrlist_get_addr(VsmAddrList addrs, unsigned int i);
+
+/**
+ * Get address prefix for i'th entry
+ *
+ * @return adress prefix (mask bits count)
+ */
+unsigned int vsm_addrlist_get_prefix(VsmAddrList addrs, unsigned int i);
 
 #ifdef __cplusplus
 }
 #endif
 
 #endif /* VASUM_CLIENT_H */
+/*@}*/