Skip to content

Commit 51a778b

Browse files
committed
mysql images plugin 1.0 release
1 parent 97d7e30 commit 51a778b

File tree

3 files changed

+90
-12
lines changed

3 files changed

+90
-12
lines changed

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,18 @@ Setup
1313

1414
Test
1515
----
16-
mysql> select image_check('/www/images/logo.png');
16+
mysql> select image_check('/www/images/logo.png');
17+
18+
Plugin
19+
------
20+
drop function image_check;
21+
drop function image_remove;
22+
drop function image_rename;
23+
24+
create function image_check returns string soname 'mysql_image.so';
25+
create function image_remove returns string soname 'mysql_image.so';
26+
create function image_rename returns string soname 'mysql_image.so';
27+
28+
select image_check('/tmp/filename');
29+
select image_remove('/tmp/filename');
30+
select image_rename('/tmp/aa','/tmp/bb');

src/image.c

Lines changed: 71 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
Homepage: http://netkiller.github.io/
33
Author: netkiller<netkiller@msn.com>
44
*/
5-
5+
#include <stdlib.h>
6+
#include <stdio.h>
67
#include <mysql.h>
78
#include <string.h>
8-
#include <stdio.h>
9-
#include <stdlib.h>
9+
#include <io.h>
1010

1111
#include "image.h"
1212

@@ -18,7 +18,7 @@ my_bool image_check_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
1818
if (args->arg_count != 1)
1919
{
2020
strncpy(message,
21-
"two arguments must be supplied: image_check('<data>').",
21+
"two arguments must be supplied: image_check('<filename>').",
2222
MYSQL_ERRMSG_SIZE);
2323
return 1;
2424
}
@@ -35,7 +35,11 @@ char *image_check(UDF_INIT *initid, UDF_ARGS *args,
3535
{
3636

3737
char *data;
38-
data = "image_check";
38+
if (!access(args->args[0],0) )
39+
data = "ture";
40+
else
41+
data = "false";
42+
3943
*length = strlen(data);
4044
return ((char *)data);
4145

@@ -46,6 +50,49 @@ void image_check_deinit(UDF_INIT *initid)
4650
return;
4751
}
4852

53+
/* ------------------------ image_rename ----------------------------- */
54+
55+
my_bool image_rename_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
56+
{
57+
58+
if (args->arg_count != 2)
59+
{
60+
strcpy(message,
61+
"two arguments must be supplied: image_move('<file1>','<file2>').");
62+
return 1;
63+
}
64+
65+
args->arg_type[0]= STRING_RESULT;
66+
67+
return 0;
68+
}
69+
70+
char *image_rename(UDF_INIT *initid, UDF_ARGS *args,
71+
__attribute__ ((unused)) char *result,
72+
unsigned long *length,
73+
__attribute__ ((unused)) char *is_null,
74+
__attribute__ ((unused)) char *error)
75+
{
76+
77+
char *data;
78+
int errno;
79+
errno = rename(args->args[0], args->args[1]);
80+
if( errno == 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 image_rename_deinit(UDF_INIT *initid)
92+
{
93+
return;
94+
}
95+
4996
/* ------------------------ image_move ----------------------------- */
5097

5198
my_bool image_move_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
@@ -54,7 +101,7 @@ my_bool image_move_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
54101
if (args->arg_count != 1)
55102
{
56103
strncpy(message,
57-
"two arguments must be supplied: image_move('<data>').",
104+
"two arguments must be supplied: image_move('<filename>').",
58105
MYSQL_ERRMSG_SIZE);
59106
return 1;
60107
}
@@ -87,6 +134,15 @@ void image_move_deinit(UDF_INIT *initid)
87134

88135
my_bool image_remove_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
89136
{
137+
if (args->arg_count != 1)
138+
{
139+
strncpy(message,
140+
"two arguments must be supplied: image_remove('<filename>').",
141+
MYSQL_ERRMSG_SIZE);
142+
return 1;
143+
}
144+
145+
args->arg_type[0]= STRING_RESULT;
90146
return 0;
91147
}
92148

@@ -97,11 +153,15 @@ char *image_remove(UDF_INIT *initid, UDF_ARGS *args,
97153
__attribute__ ((unused)) char *error)
98154
{
99155

100-
char *config;
101-
//asprintf(&config, "SAFENET_URL=%s, SAFENET_KEY=%s", safe_url, safe_key);
102-
config = "image_remove";
103-
*length = strlen(config);
104-
return ((char *)config);
156+
char *status;
157+
//asprintf(&status, "SAFENET_URL=%s, SAFENET_KEY=%s", safe_url, safe_key);
158+
if( !remove( args->args[0] ) )
159+
status = "true";
160+
else
161+
status = "false";
162+
163+
*length = strlen(status);
164+
return ((char *)status);
105165
}
106166

107167
void image_remove_deinit(UDF_INIT *initid)

src/image.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@ void image_move_deinit(UDF_INIT *initid);
99
my_bool image_remove_init(UDF_INIT *initid, UDF_ARGS *args, char *message);
1010
char *image_remove(UDF_INIT *initid, UDF_ARGS *args, char *result, unsigned long *length, char *is_null, char *error);
1111
void image_remove_deinit(UDF_INIT *initid);
12+
13+
my_bool image_rename_init(UDF_INIT *initid, UDF_ARGS *args, char *message);
14+
char *image_rename(UDF_INIT *initid, UDF_ARGS *args, char *result, unsigned long *length, char *is_null, char *error);
15+
void image_rename_deinit(UDF_INIT *initid);

0 commit comments

Comments
 (0)