dmlite  0.4
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 <limits.h>
9 #include <stdint.h>
10 
11 #define ACL_ENTRIES_MAX 300
12 #define ACL_SIZE 13
13 #define CSUMTYPE_MAX 3
14 #define CSUMVALUE_MAX 33
15 #define GUID_MAX 36
16 #ifndef HOST_NAME_MAX
17 # define HOST_NAME_MAX _POSIX_HOST_NAME_MAX
18 #endif
19 #define QUERY_MAX 1024
20 #define SCHEME_MAX 7
21 #define URL_MAX 8192
22 
23 #define ACL_USER_OBJ 1
24 #define ACL_USER 2
25 #define ACL_GROUP_OBJ 3
26 #define ACL_GROUP 4
27 #define ACL_MASK 5
28 #define ACL_OTHER 6
29 #define ACL_DEFAULT 0x20
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 /** @brief Handles URL */
36 typedef struct dmlite_url {
39  unsigned port;
40  char path [PATH_MAX];
41  char query [QUERY_MAX];
42 } dmlite_url;
43 
44 /** @brief Handles ACL entries */
45 typedef struct dmlite_aclentry {
46  uint8_t type;
47  uint8_t perm;
48  uint32_t id;
50 
51 
52 /**
53  * @brief Parses a URL.
54  * @param source Original URL.
55  * @param dest Parsed URL.
56  */
57 void dmlite_parse_url(const char* source, dmlite_url* dest);
58 
59 /**
60  * @brief Serializes into a string a set of ACL entries
61  * @param nEntries The number of ACL entries in the array.
62  * @param acl The ACL.
63  * @param buffer Where to put the resulting string.
64  * @param bsize The buffer size.
65  */
66 void dmlite_serialize_acls(unsigned nEntries, dmlite_aclentry* acl,
67  char* buffer, size_t bsize);
68 
69 /**
70  * @brief Deserializes a string into an array of ACL entries.
71  * @param buffer The string.
72  * @param nEntries The resulting number of ACL entries.
73  * @param acl The resulting ACL.
74  */
75 void dmlite_deserialize_acl(const char* buffer, unsigned* nEntries,
76  dmlite_aclentry** acl);
77 
78 /**
79  * @brief Frees an array of ACL entries as returned by dm_deserialize_acls
80  * @param nEntries The number of entries in the array.
81  * @param acl The ACL.
82  */
83 void dmlite_acl_free(unsigned nEntries, dmlite_aclentry* acl);
84 
85 #ifdef __cplusplus
86 }
87 #endif
88 
89 #endif /* DMLITE_UTILS_H */