@@ -7,7 +7,7 @@ Author: netkiller<netkiller@msn.com>
7
7
#include <mysql.h>
8
8
#include <string.h>
9
9
#include <io.h>
10
-
10
+ #include <openssl/md5.h>
11
11
#include "image.h"
12
12
13
13
/* ------------------------ image_check ----------------------------- */
@@ -18,7 +18,7 @@ my_bool image_check_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
18
18
if (args -> arg_count != 1 )
19
19
{
20
20
strncpy (message ,
21
- "two arguments must be supplied: image_check('<filename>')." ,
21
+ "one arguments must be supplied: image_check('<filename>')." ,
22
22
MYSQL_ERRMSG_SIZE );
23
23
return 1 ;
24
24
}
@@ -168,3 +168,93 @@ void image_remove_deinit(UDF_INIT *initid)
168
168
{
169
169
return ;
170
170
}
171
+
172
+ /* ------------------------ image_crc32 ----------------------------- */
173
+
174
+ my_bool image_crc32_init (UDF_INIT * initid , UDF_ARGS * args , char * message )
175
+ {
176
+ if (args -> arg_count != 1 )
177
+ {
178
+ strncpy (message ,
179
+ "one arguments must be supplied: image_crc32('<filename>')." ,
180
+ MYSQL_ERRMSG_SIZE );
181
+ return 1 ;
182
+ }
183
+
184
+ args -> arg_type [0 ]= STRING_RESULT ;
185
+ return 0 ;
186
+ }
187
+
188
+ char * image_crc32 (UDF_INIT * initid , UDF_ARGS * args ,
189
+ __attribute__ ((unused )) char * result ,
190
+ unsigned long * length ,
191
+ __attribute__ ((unused )) char * is_null ,
192
+ __attribute__ ((unused )) char * error )
193
+ {
194
+
195
+ char * status ;
196
+ char * data ;
197
+
198
+ data = readfile ( args -> args [0 ]);
199
+ if ( data != NULL ){
200
+ asprintf (& status , "%lu" , crc32 (0 , (const void * )data , strlen (data )));
201
+ }else {
202
+ status = "false" ;
203
+ }
204
+ * length = strlen (status );
205
+ return ((char * )status );
206
+ }
207
+
208
+ void image_crc32_deinit (UDF_INIT * initid )
209
+ {
210
+ return ;
211
+ }
212
+
213
+ /* ------------------------ image_md5sum ----------------------------- */
214
+ /*
215
+ my_bool image_md5sum_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
216
+ {
217
+ if (args->arg_count != 1)
218
+ {
219
+ strncpy(message,
220
+ "one arguments must be supplied: image_md5sum('<filename>').",
221
+ MYSQL_ERRMSG_SIZE);
222
+ return 1;
223
+ }
224
+
225
+ args->arg_type[0]= STRING_RESULT;
226
+ return 0;
227
+ }
228
+
229
+ char *image_md5sum(UDF_INIT *initid, UDF_ARGS *args,
230
+ __attribute__ ((unused)) char *result,
231
+ unsigned long *length,
232
+ __attribute__ ((unused)) char *is_null,
233
+ __attribute__ ((unused)) char *error)
234
+ {
235
+
236
+ char *status;
237
+ char *data;
238
+ unsigned char digest[MD5_DIGEST_LENGTH];
239
+ char string[33];
240
+ int i;
241
+ data = readfile( args->args[0] );
242
+ if( data != NULL ){
243
+ MD5((unsigned char*)&data, strlen(data), (unsigned char*)&digest);
244
+ for(i = 0; i < 16; i++)
245
+ sprintf(&string[i*2], "%02x", (unsigned int)digest[i]);
246
+
247
+ asprintf(&status, "md5 digest: %s", string);
248
+ //status = string;
249
+ }else{
250
+ status = "false";
251
+ }
252
+ *length = strlen(status);
253
+ return ((char *)status);
254
+ }
255
+
256
+ void image_md5sum_deinit(UDF_INIT *initid)
257
+ {
258
+ return;
259
+ }
260
+ */
0 commit comments