|
| 1 | +/* |
| 2 | +Homepage: http://netkiller.github.io/ |
| 3 | +Author: netkiller<netkiller@msn.com> |
| 4 | +*/ |
| 5 | +#include <stdlib.h> |
| 6 | +#include <stdio.h> |
| 7 | +#include <mysql.h> |
| 8 | +#include <string.h> |
| 9 | +#include <sys/io.h> |
| 10 | +#include <sys/stat.h> |
| 11 | +#include <sys/types.h> |
| 12 | +#include <fcntl.h> |
| 13 | + |
| 14 | +#include "outfile.h" |
| 15 | + |
| 16 | +/* ------------------------ outfile_create ----------------------------- */ |
| 17 | + |
| 18 | +my_bool outfile_create_init(UDF_INIT *initid, UDF_ARGS *args, char *message) |
| 19 | +{ |
| 20 | + |
| 21 | + if (args->arg_count != 1) |
| 22 | + { |
| 23 | + strncpy(message, |
| 24 | + "one arguments must be supplied: outfile_create('<pipename>').", |
| 25 | + MYSQL_ERRMSG_SIZE); |
| 26 | + return 1; |
| 27 | + } |
| 28 | + args->arg_type[0]= STRING_RESULT; |
| 29 | + |
| 30 | + return 0; |
| 31 | +} |
| 32 | + |
| 33 | +char *outfile_create(UDF_INIT *initid, UDF_ARGS *args, |
| 34 | + __attribute__ ((unused)) char *result, |
| 35 | + unsigned long *length, |
| 36 | + __attribute__ ((unused)) char *is_null, |
| 37 | + __attribute__ ((unused)) char *error) |
| 38 | +{ |
| 39 | + |
| 40 | + char *status; |
| 41 | + if (create_outfile(args->args[0]) == 0) |
| 42 | + status = "ture"; |
| 43 | + else |
| 44 | + status = "false"; |
| 45 | + |
| 46 | + *length = strlen(status); |
| 47 | + return ((char *)status); |
| 48 | + |
| 49 | +} |
| 50 | + |
| 51 | +void outfile_create_deinit(UDF_INIT *initid) |
| 52 | +{ |
| 53 | + return; |
| 54 | +} |
| 55 | + |
| 56 | +/* ------------------------ outfile_remove ----------------------------- */ |
| 57 | + |
| 58 | +my_bool outfile_remove_init(UDF_INIT *initid, UDF_ARGS *args, char *message) |
| 59 | +{ |
| 60 | + |
| 61 | + if (args->arg_count != 1) |
| 62 | + { |
| 63 | + strncpy(message,"one arguments must be supplied: outfile_remove('<pipename>').", MYSQL_ERRMSG_SIZE); |
| 64 | + return 1; |
| 65 | + } |
| 66 | + |
| 67 | + args->arg_type[0]= STRING_RESULT; |
| 68 | + |
| 69 | + return 0; |
| 70 | +} |
| 71 | + |
| 72 | +char *outfile_remove(UDF_INIT *initid, UDF_ARGS *args, |
| 73 | + __attribute__ ((unused)) char *result, |
| 74 | + unsigned long *length, |
| 75 | + __attribute__ ((unused)) char *is_null, |
| 76 | + __attribute__ ((unused)) char *error) |
| 77 | +{ |
| 78 | + |
| 79 | + char *data; |
| 80 | + if( remove_outfile(args->args[0]) == 0 ) |
| 81 | + data = "true"; |
| 82 | + else |
| 83 | + //asprintf(&data, "ARG0=%s, ARG1=%d", args->args[0], errno); |
| 84 | + data = "false"; |
| 85 | + |
| 86 | + *length = strlen(data); |
| 87 | + return ((char *)data); |
| 88 | + |
| 89 | +} |
| 90 | + |
| 91 | +void outfile_remove_deinit(UDF_INIT *initid) |
| 92 | +{ |
| 93 | + return; |
| 94 | +} |
| 95 | + |
| 96 | +/* ------------------------ outfile_read ----------------------------- */ |
| 97 | + |
| 98 | +my_bool outfile_read_init(UDF_INIT *initid, UDF_ARGS *args, char *message) |
| 99 | +{ |
| 100 | + |
| 101 | + if (args->arg_count != 1) |
| 102 | + { |
| 103 | + strncpy(message, "one arguments must be supplied: outfile_read('<pipename>').", MYSQL_ERRMSG_SIZE); |
| 104 | + return 1; |
| 105 | + } |
| 106 | + |
| 107 | + args->arg_type[0]= STRING_RESULT; |
| 108 | + |
| 109 | + return 0; |
| 110 | +} |
| 111 | + |
| 112 | +char *outfile_read(UDF_INIT *initid, UDF_ARGS *args, |
| 113 | + __attribute__ ((unused)) char *result, |
| 114 | + unsigned long *length, |
| 115 | + __attribute__ ((unused)) char *is_null, |
| 116 | + __attribute__ ((unused)) char *error) |
| 117 | +{ |
| 118 | + |
| 119 | + char *data; |
| 120 | + |
| 121 | + data = read_outfile(args->args[0]); |
| 122 | + |
| 123 | + //asprintf(&data, "ARG0=%s, ARG1=%d", args->args[0], args->args[1]); |
| 124 | + *length = strlen(data); |
| 125 | + return ((char *)data); |
| 126 | + |
| 127 | +} |
| 128 | + |
| 129 | +void outfile_read_deinit(UDF_INIT *initid) |
| 130 | +{ |
| 131 | + return; |
| 132 | +} |
| 133 | + |
| 134 | +/* ------------------------ outfile_write ----------------------------- */ |
| 135 | + |
| 136 | +my_bool outfile_write_init(UDF_INIT *initid, UDF_ARGS *args, char *message) |
| 137 | +{ |
| 138 | + if (args->arg_count != 2) |
| 139 | + { |
| 140 | + strncpy(message, "two arguments must be supplied: outfile_write('pipename','message').", MYSQL_ERRMSG_SIZE); |
| 141 | + return 1; |
| 142 | + } |
| 143 | + |
| 144 | + args->arg_type[0]= STRING_RESULT; |
| 145 | + return 0; |
| 146 | +} |
| 147 | + |
| 148 | +char *outfile_write(UDF_INIT *initid, UDF_ARGS *args, |
| 149 | + __attribute__ ((unused)) char *result, |
| 150 | + unsigned long *length, |
| 151 | + __attribute__ ((unused)) char *is_null, |
| 152 | + __attribute__ ((unused)) char *error) |
| 153 | +{ |
| 154 | + |
| 155 | + char *status; |
| 156 | + //asprintf(&status, "SAFENET_URL=%s, SAFENET_KEY=%s", safe_url, safe_key); |
| 157 | + if( write_outfile( args->args[0], args->args[1] ) == -1) |
| 158 | + status = "false"; |
| 159 | + else |
| 160 | + status = "true"; |
| 161 | + |
| 162 | + *length = strlen(status); |
| 163 | + return ((char *)status); |
| 164 | +} |
| 165 | + |
| 166 | +void outfile_write_deinit(UDF_INIT *initid) |
| 167 | +{ |
| 168 | + return; |
| 169 | +} |
0 commit comments