dmlite  0.6
utils.h
Go to the documentation of this file.
1 /** @file include/dmlite/c/utils.h
2  * @brief C wrapper for DMLite utils.
3  * @author Alejandro Álvarez Ayllon <aalvarez@cern.ch>
4  */
5 #ifndef DMLITE_UTILS_H
6 #define DMLITE_UTILS_H
7 
8 #include "any.h"
9 #include "dmlite/common/config.h"
10 
11 #include <limits.h>
12 #include <stdint.h>
13 
14 #define ACL_ENTRIES_MAX 300
15 #define ACL_SIZE 13
16 #define CSUMTYPE_MAX 3
17 #define CSUMVALUE_MAX 33
18 #define GUID_MAX 36
19 #ifndef HOST_NAME_MAX
20 # define HOST_NAME_MAX _POSIX_HOST_NAME_MAX
21 #endif
22 #define QUERY_MAX 1024
23 #define SCHEME_MAX 7
24 #define URL_MAX 8192
25 
26 #define ACL_USER_OBJ 1
27 #define ACL_USER 2
28 #define ACL_GROUP_OBJ 3
29 #define ACL_GROUP 4
30 #define ACL_MASK 5
31 #define ACL_OTHER 6
32 #define ACL_DEFAULT 0x20
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 /** @brief Handles URL */
39 typedef struct dmlite_url {
42  unsigned port;
43  char path [PATH_MAX];
45 } dmlite_url;
46 
47 /** @brief Handles ACL entries */
48 typedef struct dmlite_aclentry {
49  uint8_t type;
50  uint8_t perm;
51  uint32_t id;
53 
54 /**
55  * @brief Creates a new dmlite_url.
56  */
58 
59 /**
60  * @brief Parses a URL.
61  * @param source Original URL.
62  * @return Parsed URL.
63  * @note dest->query must be NULL for the first call, so it
64  * is internally allocated.
65  */
66 dmlite_url* dmlite_parse_url(const char* source);
67 
68 /**
69  * @brief Frees the given url.
70  * @param url The url to free.
71  */
72 void dmlite_url_free(dmlite_url* url);
73 
74 /**
75  * @brief Serializes a URL.
76  * @param url The url to serialize.
77  * @param buffer Where to put the serialized version.
78  * @param bsize The buffer size.
79  * @return Buffer, NULL on error.
80  */
81 char* dmlite_url_serialize(dmlite_url* url, char* buffer, size_t bsize);
82 
83 /**
84  * @brief Serializes into a string a set of ACL entries
85  * @param nEntries The number of ACL entries in the array.
86  * @param acl The ACL.
87  * @param buffer Where to put the resulting string.
88  * @param bsize The buffer size.
89  */
90 void dmlite_serialize_acls(unsigned nEntries, dmlite_aclentry* acl,
91  char* buffer, size_t bsize);
92 
93 /**
94  * @brief Deserializes a string into an array of ACL entries.
95  * @param buffer The string.
96  * @param nEntries The resulting number of ACL entries.
97  * @param acl The resulting ACL.
98  */
99 void dmlite_deserialize_acl(const char* buffer, unsigned* nEntries,
100  dmlite_aclentry** acl);
101 
102 /**
103  * @brief Frees an array of ACL entries as returned by dm_deserialize_acls
104  * @param nEntries The number of entries in the array.
105  * @param acl The ACL.
106  */
107 void dmlite_acl_free(unsigned nEntries, dmlite_aclentry* acl);
108 
109 #ifdef __cplusplus
110 }
111 #endif
112 
113 #endif /* DMLITE_UTILS_H */
dmlite_url * dmlite_parse_url(const char *source)
Parses a URL.
void dmlite_url_free(dmlite_url *url)
Frees the given url.
struct dmlite_aclentry dmlite_aclentry
Handles ACL entries.
char domain[HOST_NAME_MAX]
Definition: utils.h:41
struct dmlite_any_dict dmlite_any_dict
Handles key-&gt;value pairs.
Definition: any.h:25
uint8_t type
Definition: utils.h:49
void dmlite_acl_free(unsigned nEntries, dmlite_aclentry *acl)
Frees an array of ACL entries as returned by dm_deserialize_acls.
Header generated by CMake with the build configuration used.
#define SCHEME_MAX
Definition: utils.h:23
void dmlite_serialize_acls(unsigned nEntries, dmlite_aclentry *acl, char *buffer, size_t bsize)
Serializes into a string a set of ACL entries.
unsigned port
Definition: utils.h:42
char * dmlite_url_serialize(dmlite_url *url, char *buffer, size_t bsize)
Serializes a URL.
uint8_t perm
Definition: utils.h:50
Opaque handler to pass different types of values to the API.
char scheme[SCHEME_MAX]
Definition: utils.h:40
Handles ACL entries.
Definition: utils.h:48
char path[PATH_MAX]
Definition: utils.h:43
dmlite_any_dict * query
Definition: utils.h:44
dmlite_url * dmlite_url_new(void)
Creates a new dmlite_url.
#define HOST_NAME_MAX
Definition: utils.h:20
Handles URL.
Definition: utils.h:39
uint32_t id
Definition: utils.h:51
struct dmlite_url dmlite_url
Handles URL.
void dmlite_deserialize_acl(const char *buffer, unsigned *nEntries, dmlite_aclentry **acl)
Deserializes a string into an array of ACL entries.