dmlite
0.6
|
00001 /** @file include/dmlite/c/utils.h 00002 * @brief C wrapper for DMLite utils. 00003 * @author Alejandro Álvarez Ayllon <aalvarez@cern.ch> 00004 */ 00005 #ifndef DMLITE_UTILS_H 00006 #define DMLITE_UTILS_H 00007 00008 #include "any.h" 00009 #include "../common/config.h" 00010 00011 #include <limits.h> 00012 #include <stdint.h> 00013 00014 #define ACL_ENTRIES_MAX 300 00015 #define ACL_SIZE 13 00016 #define CSUMTYPE_MAX 3 00017 #define CSUMVALUE_MAX 33 00018 #define GUID_MAX 36 00019 #ifndef HOST_NAME_MAX 00020 # define HOST_NAME_MAX _POSIX_HOST_NAME_MAX 00021 #endif 00022 #define QUERY_MAX 1024 00023 #define SCHEME_MAX 7 00024 #define URL_MAX 8192 00025 00026 #define ACL_USER_OBJ 1 00027 #define ACL_USER 2 00028 #define ACL_GROUP_OBJ 3 00029 #define ACL_GROUP 4 00030 #define ACL_MASK 5 00031 #define ACL_OTHER 6 00032 #define ACL_DEFAULT 0x20 00033 00034 #ifdef __cplusplus 00035 extern "C" { 00036 #endif 00037 00038 /** @brief Handles URL */ 00039 typedef struct dmlite_url { 00040 char scheme[SCHEME_MAX]; 00041 char domain[HOST_NAME_MAX]; 00042 unsigned port; 00043 char path [PATH_MAX]; 00044 dmlite_any_dict* query; 00045 } dmlite_url; 00046 00047 /** @brief Handles ACL entries */ 00048 typedef struct dmlite_aclentry { 00049 uint8_t type; 00050 uint8_t perm; 00051 uint32_t id; 00052 } dmlite_aclentry; 00053 00054 /** 00055 * @brief Creates a new dmlite_url. 00056 */ 00057 dmlite_url* dmlite_url_new(void); 00058 00059 /** 00060 * @brief Parses a URL. 00061 * @param source Original URL. 00062 * @return Parsed URL. 00063 * @note dest->query must be NULL for the first call, so it 00064 * is internally allocated. 00065 */ 00066 dmlite_url* dmlite_parse_url(const char* source); 00067 00068 /** 00069 * @brief Frees the given url. 00070 * @param url The url to free. 00071 */ 00072 void dmlite_url_free(dmlite_url* url); 00073 00074 /** 00075 * @brief Serializes a URL. 00076 * @param url The url to serialize. 00077 * @param buffer Where to put the serialized version. 00078 * @param bsize The buffer size. 00079 * @return Buffer, NULL on error. 00080 */ 00081 char* dmlite_url_serialize(dmlite_url* url, char* buffer, size_t bsize); 00082 00083 /** 00084 * @brief Serializes into a string a set of ACL entries 00085 * @param nEntries The number of ACL entries in the array. 00086 * @param acl The ACL. 00087 * @param buffer Where to put the resulting string. 00088 * @param bsize The buffer size. 00089 */ 00090 void dmlite_serialize_acls(unsigned nEntries, dmlite_aclentry* acl, 00091 char* buffer, size_t bsize); 00092 00093 /** 00094 * @brief Deserializes a string into an array of ACL entries. 00095 * @param buffer The string. 00096 * @param nEntries The resulting number of ACL entries. 00097 * @param acl The resulting ACL. 00098 */ 00099 void dmlite_deserialize_acl(const char* buffer, unsigned* nEntries, 00100 dmlite_aclentry** acl); 00101 00102 /** 00103 * @brief Frees an array of ACL entries as returned by dm_deserialize_acls 00104 * @param nEntries The number of entries in the array. 00105 * @param acl The ACL. 00106 */ 00107 void dmlite_acl_free(unsigned nEntries, dmlite_aclentry* acl); 00108 00109 #ifdef __cplusplus 00110 } 00111 #endif 00112 00113 #endif /* DMLITE_UTILS_H */