All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cl_udf.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2008-2013 by Aerospike.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to
6  * deal in the Software without restriction, including without limitation the
7  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8  * sell copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20  * IN THE SOFTWARE.
21  *****************************************************************************/
22 #pragma once
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 
29 #include <openssl/sha.h>
30 
31 #include <citrusleaf/cl_cluster.h>
32 #include <citrusleaf/cf_crypto.h>
33 
34 #include <aerospike/as_result.h>
35 #include <aerospike/as_types.h>
36 
37 /******************************************************************************
38  * CONSTANTS
39  ******************************************************************************/
40 
41 #define AS_UDF_LUA 0
42 
43 /******************************************************************************
44  * DATA TYPES
45  ******************************************************************************/
46 
47 typedef uint8_t cl_udf_type;
48 
49 typedef struct cl_udf_file_s {
50  char name[128];
51  uint8_t hash[CF_SHA_HEX_BUFF_LEN];
52  cl_udf_type type;
54 } cl_udf_file;
55 
56 typedef struct cl_udf_info_s {
57  char * error;
58  char filename[128];
60  char * gen;
61  uint8_t hash[CF_SHA_HEX_BUFF_LEN];
62 } cl_udf_info;
63 
64 /******************************************************************************
65  * FUNCTIONS
66  ******************************************************************************/
67 
68 /**
69  * Apply a UDF to a record.
70  * @param result will be updated with the result of the call. The as_result.value member should be freed by the user.
71  */
72 cl_rv citrusleaf_udf_record_apply(cl_cluster * cluster, const char * ns, const char * set,
73  const cl_object * key, const char * filename, const char * function, as_list * arglist,
74  int timeout, as_result * result);
75 
76 /**
77  * @param files - An array of filenames. Each entry is string. The array and each entry must be freed by the user.
78  * @param count - Number of entries.
79  * @param error - Contains an error message, if the return value was non-zero. The value must be freed by the user.
80  */
81 cl_rv citrusleaf_udf_list(cl_cluster * cluster, cl_udf_file ** files, int * count, char ** error);
82 
83 /**
84  * @param filename - The name of the file to download from the cluster.
85  * @param contents - The contents of the file. The contents must be freed by the user.
86  * @param size - The size of the contents of the file.
87  * @param error - Contains an error message, if the return value was non-zero. The value must be freed by the user.
88  */
89 cl_rv citrusleaf_udf_get(cl_cluster * cluster, const char * filename, cl_udf_file * file,
90  cl_udf_type udf_type, char ** error);
91 
92 /**
93  * @param filename - The name of the file to download from the cluster.
94  * @param contents - The contents of the file. The value must be freed by the user.
95  * @param size - The size of the contents of the file.
96  * @param gen - The generation value of the file. The value must be freed by the user.
97  * @param error - Contains an error message, if the return value was non-zero. The value must be freed by the user.
98  */
99 cl_rv citrusleaf_udf_get_with_gen(cl_cluster * cluster, const char * filename, cl_udf_file * file,
100  cl_udf_type udf_type, char ** gen, char ** error) ;
101 
102 /**
103  * @param filename - The name of the file being uploaded to the cluster.
104  * @param contents - The contents of the file being uploaded to the cluster.
105  * @param error - Contains an error message, if the return value was non-zero. The value must be freed by the user.
106  */
107 cl_rv citrusleaf_udf_put(cl_cluster * cluster, const char * filename, as_bytes *content,
108  cl_udf_type udf_type, char ** error);
109 
110 /**
111  * @param filename - The file to be removed from the cluster.
112  * @param error - Contains an error message, if the return value was non-zero. The value must be freed by the user.
113  */
114 cl_rv citrusleaf_udf_remove(cl_cluster * cluster, const char * filename, char ** error);
115 
116 /******************************************************************************
117  * UTILITY FUNCTIONS
118  ******************************************************************************/
119 
121 
122 #ifdef __cplusplus
123 } // end extern "C"
124 #endif
125