1 #! /bin/sh /usr/share/dpatch/dpatch-run
2 ## 012-charset.dpatch by Joey Schulze <joey@infodrom.org>
4 ## DP: Add support for specifying the connection character set
5 ## DP: via Auth_MySQL_CharacterSet.
8 diff -urNad mod-auth-mysql~/DIRECTIVES mod-auth-mysql/DIRECTIVES
9 --- mod-auth-mysql~/DIRECTIVES 2008-11-21 17:05:40.000000000 +0100
10 +++ mod-auth-mysql/DIRECTIVES 2008-11-21 17:05:40.000000000 +0100
12 Auth_MySQL_DefaultDB <database_name>
13 Synonym for Auth_MySQL_General_DB.
15 +Auth_MySQL_CharacterSet <character set>
17 + Set the connection character set to the specified one. Otherwise no
18 + particular character set is used when the connection is created.
19 + This could cause problems with differently encoded strings and table
20 + or column collations. The parameter must be a valid MySQL
21 + character. It is mandatory if the character set used for tables/rows
22 + differs from the default.
24 +AuthMySQL_CharacterSet <character set>
25 + Synonym for Auth_MySQL_CharacterSet.
28 Describes the data you're guarding.
30 diff -urNad mod-auth-mysql~/mod_auth_mysql.c mod-auth-mysql/mod_auth_mysql.c
31 --- mod-auth-mysql~/mod_auth_mysql.c 2008-11-21 17:05:40.000000000 +0100
32 +++ mod-auth-mysql/mod_auth_mysql.c 2008-11-21 17:05:50.000000000 +0100
46 auth_mysql_cleanup(void *ptr)
48 mysql_auth_config_rec *sec = ptr;
50 sizeof(mysql_auth_config_rec));
53 - sec->db_name = sec->db_socket = sec->db_user = sec->db_pwd = NULL;
54 + sec->db_name = sec->db_socket = sec->db_user = sec->db_pwd = sec->db_charset = NULL;
57 /* When the memory for this connection record is cleaned, we must
59 (void*)APR_OFFSETOF(mysql_auth_config_rec, db_name),
60 OR_AUTHCFG, "database name" ),
62 + AP_INIT_TAKE1( "Auth_MySQL_CharacterSet", ap_set_string_slot,
63 + (void*)APR_OFFSETOF(mysql_auth_config_rec, db_charset),
64 + OR_AUTHCFG, "character set" ),
66 + AP_INIT_TAKE1( "AuthMySQL_CharacterSet", ap_set_string_slot,
67 + (void*)APR_OFFSETOF(mysql_auth_config_rec, db_charset),
68 + OR_AUTHCFG, "character set" ),
70 AP_INIT_TAKE1( "Auth_MySQL_Password_Table", ap_set_string_slot,
71 (void*)APR_OFFSETOF(mysql_auth_config_rec, user_table),
72 OR_AUTHCFG, "Name of the MySQL table containing the password/user-name combination" ),
73 @@ -1072,6 +1082,14 @@
74 (void *) XtOffsetOf(mysql_auth_config_rec, db_name),
75 OR_AUTHCFG, TAKE1, "database name" },
77 + { "Auth_MySQL_CharacterSet", ap_set_string_slot,
78 + (void *) XtOffsetOf(mysql_auth_config_rec, db_charset),
79 + OR_AUTHCFG, TAKE1, "character set" },
81 + { "AuthMySQL_CharacterSet", ap_set_string_slot,
82 + (void *) XtOffsetOf(mysql_auth_config_rec, db_charset),
83 + OR_AUTHCFG, TAKE1, "character set" },
85 { "Auth_MySQL_Password_Table", ap_set_string_slot,
86 (void *) XtOffsetOf(mysql_auth_config_rec, user_table),
87 OR_AUTHCFG, TAKE1, "Name of the MySQL table containing the password/user-name combination" },
89 #if MYSQL_VERSION_ID >= 50013
90 my_bool do_reconnect = 1;
94 APACHELOG(APLOG_DEBUG, r, "Opening DB connection for %s", sec->dir);
96 @@ -1354,6 +1373,30 @@
100 + if (sec->db_charset) {
101 + APACHELOG(APLOG_DEBUG, r,
102 + "Setting character set to %s", sec->db_charset);
104 + query = (char *) PSTRCAT(r->pool, "SET CHARACTER SET ", sec->db_charset, NULL);
106 + APACHELOG(APLOG_ERR, r,
107 + "Failed to create query string - we're no good...");
111 + if (mysql_query(sec->dbh, query)) {
114 + APACHELOG(APLOG_ERR, r,
115 + "Query call failed: %s (%i)", mysql_error(sec->dbh),
116 + mysql_errno(sec->dbh));
119 + APACHELOG(APLOG_DEBUG, r, "Failed query was: [%s]", query);
124 /* W00t! We made it! */