33 |
table=STRING;authid=STRING;passwd=STRING[;user=STRING][;rccol=STRING] |
table=STRING;authid=STRING;passwd=STRING[;user=STRING][;rccol=STRING] |
34 |
[;port=NUMBER][;socket=STRING][;bufsize=NUMBER] |
[;port=NUMBER][;socket=STRING][;bufsize=NUMBER] |
35 |
|
|
|
mysql://anubis:seCReT@localhost/ANUBIS;table=users;usercol=user;\ |
|
|
passcol=pass;pathcol=rcfile |
|
36 |
*/ |
*/ |
37 |
|
|
38 |
struct anubis_mysql_db { |
struct anubis_mysql_db { |
46 |
size_t bufsize; |
size_t bufsize; |
47 |
}; |
}; |
48 |
|
|
49 |
|
#define ERR_MISS 0 |
50 |
|
#define ERR_BADBUFSIZE 1 |
51 |
|
#define ERR_BADPORT 2 |
52 |
|
#define ERR_CANTCONNECT 3 |
53 |
|
|
54 |
|
static char *open_err_tab[] = { |
55 |
|
N_("Required parameters are missing"), /* ERR_MISS */ |
56 |
|
N_("Invalid buffer size"), /* ERR_BADBUFSIZE */ |
57 |
|
N_("Invalid port number"), /* ERR_BADPORT */ |
58 |
|
N_("Cannot connect to the database"), /* ERR_CANTCONNECT */ |
59 |
|
}; |
60 |
|
|
61 |
|
#define open_error_text(s) gettext(open_err_tab[s]) |
62 |
|
|
63 |
/* Open the plaintext database. ARG is the full pathname to the file */ |
/* Open the plaintext database. ARG is the full pathname to the file */ |
64 |
static int |
static int |
65 |
mysql_db_open (void **dp, ANUBIS_URL *url, enum anubis_db_mode mode) |
mysql_db_open (void **dp, ANUBIS_URL *url, enum anubis_db_mode mode, |
66 |
|
char **errp) |
67 |
{ |
{ |
68 |
struct anubis_mysql_db *amp = NULL; |
struct anubis_mysql_db *amp = NULL; |
69 |
const char *table = anubis_url_get_arg(url, "table"); |
const char *table = anubis_url_get_arg(url, "table"); |
75 |
const char *s = anubis_url_get_arg(url, "bufsize"); |
const char *s = anubis_url_get_arg(url, "bufsize"); |
76 |
int port = 0; |
int port = 0; |
77 |
size_t bufsize = 1024; |
size_t bufsize = 1024; |
78 |
|
|
79 |
|
if (!table || !authid || !passwd || !user || !rccol) { |
80 |
|
*errp = open_error_text(ERR_MISS); |
81 |
|
return ANUBIS_DB_FAIL; |
82 |
|
} |
83 |
|
|
84 |
if (s) { |
if (s) { |
85 |
char *p; |
char *p; |
86 |
bufsize = strtoul(s, &p, 10); |
bufsize = strtoul(s, &p, 10); |
87 |
|
if (*p) { |
88 |
|
*errp = open_error_text(ERR_BADBUFSIZE); |
89 |
|
return ANUBIS_DB_FAIL; |
90 |
|
} |
91 |
} |
} |
92 |
|
|
93 |
if (portstr) { |
if (portstr) { |
94 |
char *p; |
char *p; |
95 |
port = strtoul(portstr, &p, 10); |
port = strtoul(portstr, &p, 10); |
96 |
if (*p) |
if (*p) { |
97 |
return EINVAL; |
*errp = open_error_text(ERR_BADPORT); |
98 |
|
return ANUBIS_DB_FAIL; |
99 |
|
} |
100 |
} |
} |
101 |
|
|
102 |
amp = xmalloc(sizeof(*amp)); |
amp = xmalloc(sizeof(*amp)); |
109 |
anubis_url_get_arg(url, "socket"), |
anubis_url_get_arg(url, "socket"), |
110 |
0)) { |
0)) { |
111 |
free(amp); |
free(amp); |
112 |
return EINVAL; |
*errp = open_error_text(ERR_CANTCONNECT); |
113 |
|
return ANUBIS_DB_FAIL; |
114 |
} |
} |
115 |
amp->table = strdup(table); |
amp->table = strdup(table); |
116 |
amp->authid = strdup(authid); |
amp->authid = strdup(authid); |