Develop and Download Open Source Software

Browse CVS Repository

Annotation of /xoonips/AL/commonal.cc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.13 - (hide annotations) (download) (as text)
Sat Nov 27 00:35:39 2004 UTC (19 years, 4 months ago) by youi
Branch: MAIN
Changes since 1.12: +118 -89 lines
File MIME type: text/x-c++src
getAccountsを定義.
getAccountを修正,内部でgetAccountsを呼び出す.
criteria2strを定義.

1 youi 1.1 /*
2     *
3 youi 1.13 * $Revision: 1.12 $
4 youi 1.2 * $Log: commonal.cc,v $
5 youi 1.13 * Revision 1.12 2004/11/26 09:45:28 youi
6     * getAccount??絎?臂?
7     *
8 youi 1.12 * Revision 1.11 2004/11/26 08:16:26 aga
9     * ??etSession, loginUser, createSession, freeResult(const session_t*) 篆??.
10     *
11 aga 1.11 * Revision 1.10 2004/11/26 07:57:42 youi
12     * updateAccount, deleteAccount??絎?臂?
13     * mysql_query紊掩??????tderr?吾?????若?潟?若?????????若?<???祉?若?吾???阪??.
14     *
15 youi 1.10 * Revision 1.9 2004/11/26 07:38:02 aga
16     * ??AILUE -> FAILURE.
17     *
18 aga 1.9 * Revision 1.8 2004/11/26 06:36:55 aga
19     * ??reateSession, getSession ??篏???.
20     *
21 aga 1.8 * Revision 1.7 2004/11/26 04:51:47 youi
22     * dbprefix??絎?臂?????.
23     * insertAccount??絎?臂?????.
24     * isValidSessionID??絎?臂?????.
25     *
26 youi 1.7 * Revision 1.6 2004/11/26 04:35:55 aga
27     * ??oginUser(), logoutUser()??篏???.
28     *
29 aga 1.6 * Revision 1.5 2004/11/26 01:08:25 aga
30     * ??ddSlashes()篏???.
31     *
32 aga 1.5 * Revision 1.4 2004/11/25 12:14:29 youi
33     * getUid????????絎?臂?????.
34     *
35 youi 1.4 * Revision 1.3 2004/11/25 11:13:59 youi
36     * getLastErrorString/setLastErrorString??絎?臂?
37     *
38 youi 1.3 * Revision 1.2 2004/11/25 08:55:19 youi
39     * 綣??違??????篆??.
40     * freeResult??菴遵??.
41     *
42 youi 1.2 * Revision 1.1 2004/11/25 05:14:58 youi
43     * initial version
44     *
45 youi 1.1 *
46     */
47     #include <stdio.h>
48 aga 1.6 #include <stdlib.h>
49 youi 1.1 #include <string.h>
50     #include <mysql.h>
51 youi 1.10 #include <errmsg.h>
52 youi 1.3 #include <string>
53 youi 1.7 using namespace std;
54 youi 1.1
55     #include "common.h"
56     #include "account.h"
57     #include "group.h"
58     #include "session.h"
59     #include "criteria.h"
60     #include "commonal.h"
61    
62 youi 1.7
63 youi 1.1 static MYSQL* mysql = NULL; //!< MySQL????潟????/span>
64 youi 1.7 static string dbprefix; //!< XOOPS???若?帥???若?鴻???若??????REFIX
65 aga 1.5
66     /**
67     *
68     * php??ddslashes????????
69     *
70     * @param addslashes???鴻????絖?????NULL??絎?筝?????
71     * @return addslashes????????絖???
72     */
73     string addSlashes( const char *str )
74     {
75     int len = strlen(str);
76     char *buf = new char[len*2+1];
77     int bufLen = mysql_real_escape_string( mysql, buf, str, len );
78     string s( buf, bufLen );
79     return s;
80     }
81    
82 youi 1.13 /**
83     *
84     * criteria ?? SQL?????????
85     *
86     *
87     *
88     */
89     string criteria2str( criteria* cri )
90     {
91     string sql;
92    
93     if( cri -> getLimitStart( ) != 0 || cri -> getLimitRows( ) != 0 ){
94     sql += " LIMIT " + string( intToString( cri -> getLimitStart( ) ) )
95     + ", " + string( intToString( cri -> getLimitRows( ) ) );
96     }
97     const orderby* odrby = cri -> headOrderBy( );
98     if( odrby != 0 ){
99     sql += " ORDER BY " + string( odrby -> getColumn( ) );
100     sql += ( odrby -> getOrder( ) == orderby::DESC ) ? " DESC" : " ";
101     while( ( odrby = cri -> nextOrderBy( ) ) != 0 ){
102     sql += ", " + string( odrby -> getColumn( ) );
103     sql += ( odrby -> getOrder( ) == orderby::DESC ) ? " DESC" : " ";
104     }
105     }
106     return sql;
107     }
108 youi 1.1
109     /**
110     *
111     * ???若?帥???若?鴻????????
112     *
113     * @param host ???若?帥???若?鴻?????鴻????
114     * @param user ???若?帥???若?鴻???≪???祉?鴻???????若?九??
115     * @param password 筝?荐????若?吟?????鴻???若??
116     * @param dbname ???若?帥???若?鴻??????
117     * @param prefix XOOPS???若?帥???若?鴻???若??????REFIX
118     * @return result_t
119     * @refer result_t
120     */
121     result_t initializeDB( const char* host, const char* user, const char* password, const char* dbname, const char* prefix )
122     {
123     // ?≪??・膓?筝???????筝???????/span>
124     if ( mysql != NULL )
125     mysql_close( mysql );
126    
127 youi 1.7 dbprefix = prefix;
128    
129 youi 1.1 // ????????・膓?
130     mysql = mysql_init(NULL);
131     if ( mysql == NULL ){
132     return RES_DB_INITIALIZE_ERROR;
133     }
134     char *unix_socket = NULL; // ?
135     uint flag = 0; // ?
136     if ( NULL == mysql_real_connect( mysql, host, user, password, dbname, 3306, unix_socket, flag ) ){
137     return RES_DB_CONNECT_ERROR;
138     }
139    
140 youi 1.2 return RES_OK;
141 youi 1.1 }
142    
143    
144     /**
145     *
146     * Platform???若?倶?粋??倶????緇?
147     *
148     * @param
149     * @return
150     *
151     */
152 youi 1.2 bool isActivated( sessionid_t sid, userid_t uid )
153 youi 1.1 {
154     return false;
155     }
156    
157     /**
158     *
159     * Platform???若?倶?粋??倶??紊???/span>
160     *
161     * @param
162     * @return
163     *
164     */
165 youi 1.2 result_t activate( sessionid_t sid, userid_t uid, bool activate )
166 youi 1.1 {
167     return RES_ERROR;
168     }
169    
170     /**
171     *
172     * ?≪?????潟????/span>
173     *
174     * @param
175     * @return
176     *
177     */
178 youi 1.2 int getAccountCount( sessionid_t sid )
179 youi 1.1 {
180     return 0;
181     }
182    
183     /**
184     *
185     * ?≪?????潟??????/span>
186     *
187     * @param
188 youi 1.10 * @return RES_OK | RES_NO_SUCH_SESSION | RES_DB_QUERY_ERROR
189 youi 1.1 *
190     */
191 youi 1.2 result_t deleteAccount( sessionid_t sid, userid_t uid )
192 youi 1.1 {
193 youi 1.10 if( !isValidSessionID( sid ) ) return RES_NO_SUCH_SESSION;
194    
195     string sql;
196     sql = "DELETE FROM " + dbprefix + "_users ";
197     sql += "WHERE uid = " + string( unsignedIntToString( uid ) );
198     if( mysql_query( mysql, sql.c_str( ) ) ){
199     fprintf( stderr, "%d %s\n", mysql_errno(mysql), mysql_error(mysql) );
200     return RES_DB_QUERY_ERROR;
201     }
202    
203     sql = "DELETE FROM " + dbprefix + "_vpaccount_users ";
204     sql += "WHERE uid = " + string( unsignedIntToString( uid ) );
205     if( mysql_query( mysql, sql.c_str( ) ) ){
206     fprintf( stderr, "%d %s\n", mysql_errno(mysql), mysql_error(mysql) );
207     return RES_DB_QUERY_ERROR;
208     }
209    
210     return RES_OK;
211 youi 1.1 }
212    
213     /**
214     *
215     * ?≪?????潟?????怨??
216     *
217 youi 1.13 * @param sid ?祉???激?с??D
218     * @param uid ??緇??????????若?吟??ID
219     * @param acc ??緇??????≪?????潟??????account_t)?????ゃ?潟?帥???吾??莨若??綣???/span>
220     * @return RES_OK | RES_NO_SUCH_USER | RES_NO_SUCH_SESSION | RES_DB_QUERY_ERROR | RES_ERROR
221 youi 1.1 *
222     */
223 youi 1.12 result_t getAccount( sessionid_t sid, userid_t uid, const account_t** acc )
224 youi 1.1 {
225 youi 1.13 int len;
226     static criteria c;
227     result_t res = getAccounts( sid, &uid, 1, &c, acc, &len );
228     if( len == 0 ) return RES_NO_SUCH_USER;
229     return res;
230     }
231    
232     /**
233     *
234     * ?≪?????潟?????怨??
235     *
236     * @param sid ?祉???激?с??D
237     * @param uids ??緇??????????若?吟??ID??????
238     * @param uidsLen uids???????膣???/span>
239     * @param cri 腟???????我??絎?鐚??純?若???>散??絎?
240     * @param accounts 罎?膣∝??????????????ゃ?潟?帥???吾??莨若??綣???/span>
241     * @param accountsLen 罎?膣∝???????????*accounts???膣???
242     * @return RES_OK| RES_NO_SUCH_SESSION | RES_DB_QUERY_ERROR
243     *
244     */
245     result_t getAccounts( sessionid_t sid, const userid_t* uids, int uidsLen, criteria_t* cri, const account_t** accounts, int* accountsLen )
246     {
247 youi 1.12 if( !isValidSessionID( sid ) ) return RES_NO_SUCH_SESSION;
248    
249     string sql;
250     MYSQL_RES* result;
251     MYSQL_ROW row;
252 youi 1.13 account_t* dst = new account_t[ uidsLen ];
253 youi 1.12
254 youi 1.13 sql += "SELECT u1.uid, u1.name, u1.uname, u1.email, u1.url, u1.user_avatar, u1.user_regdate, u1.user_icq, u1.user_from, u1.user_sig, u1.user_viewemail, u1.actkey, u1.user_aim, u1.user_yim, u1.user_msnm, u1.pass, u1.posts, u1.attachsig, u1.rank, u1.level, u1.theme, u1.timezone_offset, u1.last_login, u1.umode, u1.uorder, u1.notify_method, u1.notify_mode, u1.user_occ, u1.bio, u1.user_intrest, u1.user_mailok, u2.activate, u2.address, u2.institute, u2.tel, u2.organization, u2.country, u2.zipcode, u2.fax, u2.base_url, u2.notice_mail, u2.notice_mail_since ";
255     sql += "FROM " + dbprefix + "_users AS u1, " + dbprefix + "_vpaccount_users AS u2 ";
256     sql += "WHERE u1.uid = u2.uid AND ( u1.uid=" + string( unsignedIntToString( uids[ 0 ] ) );
257     for( int i = 1; i < uidsLen; i++ ){
258     sql += " OR u1.uid=" + string( unsignedIntToString( uids[ i ] ) );
259 youi 1.12 }
260 youi 1.13 sql += " ) ";
261     sql += criteria2str( cri );
262 youi 1.12 if( mysql_query( mysql, sql.c_str( ) ) ){
263 youi 1.13 fprintf( stderr, "%s\n", sql.c_str( ) );
264 youi 1.12 fprintf( stderr, "%d %s\n", mysql_errno(mysql), mysql_error(mysql) );
265     return RES_DB_QUERY_ERROR;
266     }
267 youi 1.13 result = mysql_use_result( mysql ) ;
268     *accountsLen=0;
269     for( int i = 0; ( row = mysql_fetch_row(result) ) != 0 && i < uidsLen ; i++ ){
270     dst[ i ].setUID( atoi( row[ 0 ] ) );
271     dst[ i ].setName( row[ 1 ] );
272     dst[ i ].setUname( row[ 2 ] );
273     dst[ i ].setEmail( row[ 3 ] );
274     dst[ i ].setURL( row[ 4 ] );
275     dst[ i ].setUserAvatar( row[ 5 ] );
276     dst[ i ].setUserRegdate( atoi( row[ 6 ] ) );
277     dst[ i ].setUserIcq( row[ 7 ] );
278     dst[ i ].setUserFrom( row[ 8 ] );
279     dst[ i ].setUserSig( row[ 9 ] );
280     dst[ i ].setUserViewemail( atoi( row[ 10 ] ) );
281     dst[ i ].setActkey( row[ 11 ] );
282     dst[ i ].setUserAim( row[ 12 ] );
283     dst[ i ].setUserYim( row[ 13 ] );
284     dst[ i ].setUserMsnm( row[ 14 ] );
285     dst[ i ].setPass( row[ 15 ] );
286     dst[ i ].setPosts( atoi( row[ 16 ] ) );
287     dst[ i ].setAttachsig( atoi( row[ 17 ] ) );
288     dst[ i ].setRank( atoi( row[ 18 ] ) );
289     dst[ i ].setLevel( atoi( row[ 19 ] ) );
290     dst[ i ].setTheme( row[ 20 ] );
291     dst[ i ].setTimezoneOffset( atof( row[ 21 ] ) );
292     dst[ i ].setLastLogin( atoi( row[ 22 ] ) );
293     dst[ i ].setUmode( row[ 23 ] );
294     dst[ i ].setUorder( atoi( row[ 24 ] ) );
295     dst[ i ].setNotifyMethod( atoi( row[ 25 ] ) );
296     dst[ i ].setNotifyMode( atoi( row[ 26 ] ) );
297     dst[ i ].setUserOcc( row[ 27 ] );
298     dst[ i ].setBio( row[ 28 ] );
299     dst[ i ].setUserIntrest( row[ 29 ] );
300     dst[ i ].setUserMailok( atoi( row[ 30 ] ) );
301     dst[ i ].setActivate( atoi( row[ 31 ] ) );
302     dst[ i ].setAddress( row[ 32 ] );
303     dst[ i ].setInstitute( row[ 33 ] );
304     dst[ i ].setTel( row[ 34 ] );
305     dst[ i ].setOrganization( row[ 35 ] );
306     dst[ i ].setCountry( row[ 36 ] );
307     dst[ i ].setZipcode( row[ 37 ] );
308     dst[ i ].setFax( row[ 38 ] );
309     dst[ i ].setBaseURL( row[ 39 ] );
310     dst[ i ].setNoticeMail( atoi( row[ 40 ] ) );
311     dst[ i ].setNoticeMailSince( atoi( row[ 41 ] ) );
312     ( *accountsLen )++;
313 youi 1.12 }
314     mysql_free_result( result );
315 youi 1.13 *accounts = dst;
316 youi 1.12 return RES_OK;
317 youi 1.1 }
318    
319     /**
320     *
321     * ?≪?????潟???脂??/span>
322     *
323 youi 1.7 * @param sid ?祉???激?с??/span>
324 youi 1.10 * @param account ?脂?蚊?????≪?????潟??????/span>
325     * @return RES_OK | RES_NO_SUCH_SESSION | RES_DB_QUERY_ERROR | RES_ERROR
326 youi 1.1 *
327     */
328 youi 1.2 result_t insertAccount( sessionid_t sid, const account_t* account )
329 youi 1.1 {
330 youi 1.10 if( !isValidSessionID( sid ) ) return RES_NO_SUCH_SESSION;
331    
332 youi 1.7 string sql;
333     string tmp;
334     char buf[ 12 ];
335    
336     //xoops?????若?吟???若???????吾??莨若??
337     sql = "INSERT INTO " + dbprefix + "_users (uname, name, email, url, user_avatar, user_regdate, user_icq, user_from, user_sig, user_viewemail, actkey, user_aim, user_yim, user_msnm, pass, posts, attachsig, rank, level, theme, timezone_offset, last_login, umode, uorder, notify_method, notify_mode, user_occ, bio, user_intrest, user_mailok) VALUES (";
338     sql += "'" + string( addSlashes( account -> getUname( ) ) ) + "', ";
339     sql += "'" + string( addSlashes( account -> getName( ) ) ) + "', ";
340     sql += "'" + string( addSlashes( account -> getEmail( ) ) ) + "', ";
341     sql += "'" + string( addSlashes( account -> getURL( ) ) ) + "', ";
342     sql += "'" + string( addSlashes( account -> getUserAvatar( ) ) ) + "', ";
343     snprintf( buf, 12, "%d", time( NULL ) );
344     sql += string( buf ) + ", ";
345     sql += "'" + string( addSlashes( account -> getUserIcq( ) ) ) + "', ";
346     sql += "'" + string( addSlashes( account -> getUserFrom( ) ) ) + "', ";
347     sql += "'" + string( addSlashes( account -> getUserSig( ) ) ) + "', ";
348     snprintf( buf, 12, "%d", account -> getUserViewemail( ) );
349     sql += string( buf ) + ", ";
350     sql += "'" + string( addSlashes( account -> getActkey( ) ) ) + "', ";
351     sql += "'" + string( addSlashes( account -> getUserAim( ) ) ) + "', ";
352     sql += "'" + string( addSlashes( account -> getUserYim( ) ) ) + "', ";
353     sql += "'" + string( addSlashes( account -> getUserMsnm( ) ) ) + "', ";
354     sql += "'" + string( addSlashes( account -> getPass( ) ) ) + "', ";
355     snprintf( buf, 12, "%d", account -> getPosts( ) );
356     sql += string( buf ) + ", ";
357     snprintf( buf, 12, "%d", account -> getAttachsig( ) );
358     sql += string( buf ) + ", ";
359     snprintf( buf, 12, "%d", account -> getRank( ) );
360     sql += string( buf ) + ", ";
361     snprintf( buf, 12, "%d", account -> getLevel( ) );
362     sql += string( buf ) + ", ";
363     sql += "'" + string( addSlashes( account -> getTheme( ) ) ) + "', ";
364     snprintf( buf, 12, "%lf", account -> getTimezoneOffset( ) );
365     sql += string( buf ) + ", ";
366     sql += "0, "; //last login
367     sql += "'" + string( addSlashes( account -> getUmode( ) ) ) + "', ";
368     snprintf( buf, 12, "%d", account -> getUorder( ) );
369     sql += string( buf ) + ", ";
370     snprintf( buf, 12, "%d", account -> getNotifyMethod( ) );
371     sql += string( buf ) + ", ";
372     snprintf( buf, 12, "%d", account -> getNotifyMode( ) );
373     sql += string( buf ) + ", ";
374     sql += "'" + string( addSlashes( account -> getUserOcc( ) ) ) + "', ";
375     sql += "'" + string( addSlashes( account -> getBio( ) ) ) + "', ";
376     sql += "'" + string( addSlashes( account -> getUserIntrest( ) ) ) + "', ";
377     snprintf( buf, 12, "%d", account -> getUserMailok( ) );
378     sql += string( buf ) + ")";
379     if( mysql_query( mysql, sql.c_str( ) ) ){
380 youi 1.10 fprintf( stderr, "%s\n", sql.c_str( ) );
381     fprintf( stderr, "%d %s\n", mysql_errno(mysql), mysql_error(mysql) );
382 youi 1.7 return RES_DB_QUERY_ERROR;
383     }
384    
385     //???若??D????緇?????
386     userid_t uid;
387     if( getUid( account -> getUname( ), &uid ) != RES_OK ){
388     return RES_ERROR;
389     }
390    
391     //vpaccount?????若?吟???若??????????????宴???吾??莨若??
392 youi 1.10 sql = "INSERT INTO " + dbprefix + "_vpaccount_users (uid, activate, address, institute, tel, organization, country, zipcode, fax, base_url, notice_mail, notice_mail_since) VALUES (";
393 youi 1.7 snprintf( buf, 12, "%d", uid );
394     sql += string( buf ) + ", ";
395     if( account -> getActivate() ){
396     sql += "1, ";
397     }else{
398     sql += "0, ";
399     }
400     sql += "'" + string( addSlashes( account -> getAddress() ) ) + "', ";
401     sql += "'" + string( addSlashes( account -> getInstitute() ) ) + "', ";
402     sql += "'" + string( addSlashes( account -> getTel() ) ) + "', ";
403     sql += "'" + string( addSlashes( account -> getOrganization() ) ) + "', ";
404     sql += "'" + string( addSlashes( account -> getCountry() ) ) + "', ";
405     sql += "'" + string( addSlashes( account -> getZipcode() ) ) + "', ";
406     sql += "'" + string( addSlashes( account -> getFax() ) ) + "', ";
407     sql += "'" + string( addSlashes( account -> getBaseURL() ) ) + "', ";
408     snprintf( buf, 12, "%d", account -> getNoticeMail( ) );
409     sql += string( buf ) + ", ";
410     snprintf( buf, 12, "%d", account -> getNoticeMailSince( ) );
411     sql += string( buf ) + ")";
412     if( mysql_query( mysql, sql.c_str( ) ) ){
413 youi 1.10 fprintf( stderr, "%s\n", sql.c_str( ) );
414     fprintf( stderr, "%d %s\n", mysql_errno(mysql), mysql_error(mysql) );
415 youi 1.7 //xoops_users??nsert???????潟?若???????ゃ????
416     sql = "DELETE FROM " + dbprefix + "_users where uid=";
417     snprintf( buf, 12, "%d", uid );
418     sql += string( buf );
419 youi 1.10 mysql_query( mysql, sql.c_str( ) );
420 youi 1.7 return RES_DB_QUERY_ERROR;
421     }
422    
423     return RES_OK;
424 youi 1.1 }
425    
426     /**
427     *
428     * ?≪?????潟??紊???/span>
429     *
430     * @param
431 youi 1.10 * @return RES_OK | RES_NO_SUCH_SESSION | RES_DB_QUERY_ERROR
432 youi 1.1 *
433     */
434 youi 1.2 result_t updateAccount( sessionid_t sid, const account_t* account )
435 youi 1.1 {
436 youi 1.10 if( !isValidSessionID( sid ) ) return RES_NO_SUCH_SESSION;
437    
438     string sql;
439     string tmp;
440     char buf[ 12 ];
441    
442     //xoops?????若?吟???若???????吾??莨若??
443     sql = "UPDATE " + dbprefix + "_users SET ";
444     sql += "uname='" + string( addSlashes( account -> getUname( ) ) ) + "', ";
445     sql += "name='" + string( addSlashes( account -> getName( ) ) ) + "', ";
446     sql += "email='" + string( addSlashes( account -> getEmail( ) ) ) + "', ";
447     sql += "url='" + string( addSlashes( account -> getURL( ) ) ) + "', ";
448     sql += "user_avatar='" + string( addSlashes( account -> getUserAvatar( ) ) ) + "', ";
449     sql += "user_regdate=" + string( intToString( account -> getUserRegdate( ) ) ) + ", ";
450     sql += "user_icq='" + string( addSlashes( account -> getUserIcq( ) ) ) + "', ";
451     sql += "user_from='" + string( addSlashes( account -> getUserFrom( ) ) ) + "', ";
452     sql += "user_sig='" + string( addSlashes( account -> getUserSig( ) ) ) + "', ";
453     sql += "user_viewemail=" + string( intToString( account -> getUserViewemail( ) ) ) + ", ";
454     sql += "actkey='" + string( addSlashes( account -> getActkey( ) ) ) + "', ";
455     sql += "user_aim='" + string( addSlashes( account -> getUserAim( ) ) ) + "', ";
456     sql += "user_yim='" + string( addSlashes( account -> getUserYim( ) ) ) + "', ";
457     sql += "user_msnm='" + string( addSlashes( account -> getUserMsnm( ) ) ) + "', ";
458     sql += "pass='" + string( account -> getPass( ) ) + "', ";
459     sql += "posts=" + string( intToString( account -> getPosts( ) ) ) + ", ";
460     sql += "attachsig=" + string( intToString( account -> getAttachsig( ) ) ) + ", ";
461     sql += "rank=" + string( intToString( account -> getRank( ) ) ) + ", ";
462     sql += "level=" + string( intToString( account -> getLevel( ) ) ) + ", ";
463     sql += "theme='" + string( addSlashes( account -> getTheme( ) ) ) + "', ";
464     snprintf( buf, 12, "%.2f", account -> getTimezoneOffset( ) );
465     sql += "timezone_offset=" + string( buf ) + ", ";
466     sql += "last_login=" + string( unsignedIntToString( account -> getLastLogin( ) ) ) + ", ";
467     sql += "umode='" + string( account -> getUmode( ) ) + "', ";
468     sql += "uorder=" + string( intToString( account -> getUorder( ) ) ) + ", ";
469     sql += "notify_method=" + string( intToString( account -> getNotifyMethod( ) ) ) + ", ";
470     sql += "notify_mode=" + string( intToString( account -> getNotifyMode( ) ) ) + ", ";
471     sql += "user_occ='" + string( addSlashes( account -> getUserOcc( ) ) ) + "', ";
472     sql += "bio='" + string( addSlashes( account -> getBio( ) ) ) + "', ";
473     sql += "user_intrest='" + string( addSlashes( account -> getUserIntrest( ) ) ) + "', ";
474     sql += "user_mailok=" + string( intToString( account -> getUserMailok( ) ) );
475     sql += " WHERE uid = " + string( intToString( account -> getUID( ) ) );
476    
477     if( mysql_query( mysql, sql.c_str( ) ) ){
478     fprintf( stderr, "%s\n", sql.c_str( ) );
479     fprintf( stderr, "%d %s\n", mysql_errno(mysql), mysql_error(mysql) );
480     return RES_DB_QUERY_ERROR;
481     }
482    
483     //vpaccount?????若?吟???若??????????????宴??筝??吾??????
484     sql = "UPDATE " + dbprefix + "_vpaccount_users SET ";
485     sql += "activate=";
486     if( account -> getActivate() ){
487     sql += "1, ";
488     }else{
489     sql += "0, ";
490     }
491     sql += "address='" + string( addSlashes( account -> getAddress() ) ) + "', ";
492     sql += "institute='" + string( addSlashes( account -> getInstitute() ) ) + "', ";
493     sql += "tel='" + string( addSlashes( account -> getTel() ) ) + "', ";
494     sql += "organization='" + string( addSlashes( account -> getOrganization() ) ) + "', ";
495     sql += "country='" + string( addSlashes( account -> getCountry() ) ) + "', ";
496     sql += "zipcode='" + string( addSlashes( account -> getZipcode() ) ) + "', ";
497     sql += "fax='" + string( addSlashes( account -> getFax() ) ) + "', ";
498     sql += "base_url='" + string( addSlashes( account -> getBaseURL() ) ) + "', ";
499     sql += "notice_mail=" + string( intToString( account -> getNoticeMail( ) ) ) + ", ";
500     sql += "notice_mail_since=" + string( intToString( account -> getNoticeMailSince( ) ) );
501     sql += " WHERE uid = " + string( intToString( account -> getUID( ) ) );
502    
503     if( mysql_query( mysql, sql.c_str( ) ) ){
504     fprintf( stderr, "%s\n", sql.c_str( ) );
505     fprintf( stderr, "%d %s\n", mysql_errno(mysql), mysql_error(mysql) );
506     return RES_DB_QUERY_ERROR;
507     }
508    
509     return RES_OK;
510 youi 1.1 }
511    
512     /**
513     *
514     * ???若??D筝?荀?/span>
515     *
516     * @param
517     * @return
518     *
519     */
520 youi 1.13 result_t dumpUids( sessionid_t sid, criteria_t* cri, userid_t** uids, int* uidsLen )
521 youi 1.1 {
522     return RES_ERROR;
523     }
524    
525     /**
526     *
527     * ?違???若????/span>
528     *
529     * @param
530     * @return
531     *
532     */
533 youi 1.2 int getGroupCount( sessionid_t sid )
534 youi 1.1 {
535     return 0;
536     }
537    
538     /**
539     *
540     * ??絮??違???若??筝?荀у??
541     *
542     * @param
543     * @return
544     *
545     */
546 youi 1.13 result_t getGroupsByUid( sessionid_t sid, userid_t uid, criteria_t* cri, groupid_t** gids, int* gidsLen )
547 youi 1.1 {
548     return RES_ERROR;
549     }
550    
551     /**
552     *
553     * ?違???若??膊∞??罔????????
554     *
555     * @param
556     * @return
557     *
558     */
559 youi 1.2 bool isGroupAdmin( sessionid_t sid, groupid_t gid, userid_t uid )
560 youi 1.1 {
561     return RES_ERROR;
562     }
563    
564     /**
565     *
566     * ?違???若??ID筝?荀?/span>
567     *
568     * @param
569     * @return
570     *
571     */
572 youi 1.13 result_t dumpGids( sessionid_t sid, criteria_t* cri, groupid_t** gids, int* gidsLen )
573 youi 1.1 {
574     return RES_ERROR;
575     }
576    
577     /**
578     *
579     * ?違???若??膊∞????ID??緇?
580     *
581     * @param
582     * @return
583     *
584     */
585 youi 1.13 result_t dumpGroupAdmins( sessionid_t sid, groupid_t gid, criteria_t* cri, userid_t** uids, int* uidsLen )
586 youi 1.1 {
587     return RES_ERROR;
588     }
589    
590     /**
591     *
592     * ?違???若????絮????若?九????/span>
593     *
594     * @param
595     * @return
596     *
597     */
598 youi 1.2 result_t deleteMember( sessionid_t sid, groupid_t gid, userid_t uid )
599 youi 1.1 {
600     return RES_ERROR;
601     }
602    
603     /**
604     *
605     * ?違???若????絮????若?区申??
606     *
607     * @param
608     * @return
609     *
610     */
611 youi 1.2 result_t insertMember( sessionid_t sid, groupid_t gid, userid_t uid )
612 youi 1.1 {
613     return RES_ERROR;
614     }
615    
616     /**
617     *
618     * ?違???若????絮????若?九??
619     *
620     * @param
621     * @return
622     *
623     */
624 youi 1.13 result_t getMembers( sessionid_t sid, groupid_t gid, criteria_t* cri, userid_t** uids, int* uidsLen )
625 youi 1.1 {
626     return RES_ERROR;
627     }
628    
629     /**
630     *
631     * ?違???若????????/span>
632     *
633     * @param
634     * @return
635     *
636     */
637 youi 1.2 result_t deleteGroup( sessionid_t sid, groupid_t gid )
638 youi 1.1 {
639     return RES_ERROR;
640     }
641    
642     /**
643     *
644     * ?違???若?????脂??/span>
645     *
646     * @param
647     * @return
648     *
649     */
650 youi 1.2 result_t insertGroup( sessionid_t sid, const group_t* group )
651 youi 1.1 {
652     return RES_ERROR;
653     }
654    
655     /**
656     *
657     * ?違???若???????/span>
658     *
659     * @param
660     * @return
661     *
662     */
663 youi 1.2 result_t updateGroup( sessionid_t sid, const group_t* group )
664 youi 1.1 {
665     return RES_ERROR;
666     }
667    
668     /**
669     *
670     * ?違???若?????怨??
671     *
672     * @param
673     * @return
674     *
675     */
676 youi 1.2 result_t getGroup( sessionid_t sid, groupid_t gid, const group_t** group )
677 youi 1.1 {
678     return RES_ERROR;
679     }
680    
681     /**
682     *
683     * ?違???若?????怨??
684     *
685     * @param
686     * @return
687     *
688     */
689 youi 1.13 result_t getGroups( sessionid_t sid, groupid_t* gids, int gidsLen, criteria_t* cri, const group_t** groups, int* groupsLen )
690 youi 1.1 {
691     return RES_ERROR;
692     }
693    
694     /**
695     *
696     * ?≪?????若?炊┤???????
697     *
698     * @param
699     * @return
700     *
701     */
702 youi 1.2 bool isModerator( sessionid_t sid, userid_t uid )
703 youi 1.1 {
704     return RES_ERROR;
705     }
706    
707     /**
708     *
709     * ???若??D??緇?
710     *
711 youi 1.7 * @param uname ID????緇??????????若?吟?弱??
712     * @param uid ID??篁e?ャ??????紊??違?????ゃ?潟??/span>
713     * @return RES_ERROR | RES_OK
714     * @refer result_t
715 youi 1.1 *
716     */
717 youi 1.2 result_t getUid( const char* uname, userid_t* uid )
718 youi 1.1 {
719 youi 1.4 string sql;
720    
721 youi 1.7 if( uname == NULL ) return RES_ERROR;
722    
723     string uname2 = addSlashes( uname );
724 youi 1.10 sql = "SELECT uid FROM " + dbprefix + "_users WHERE uname='" + uname2 + "';";
725 youi 1.4 if( mysql_query( mysql, sql.c_str( ) ) ){
726 youi 1.10 fprintf( stderr, "%d %s\n", mysql_errno(mysql), mysql_error(mysql) );
727 youi 1.4 return RES_DB_QUERY_ERROR;
728     }
729 youi 1.10 MYSQL_RES* result = mysql_store_result( mysql ) ;
730 youi 1.4 MYSQL_ROW row = mysql_fetch_row(result);
731     if( row ){
732     *uid = atoi( row[0] );
733     mysql_free_result( result );
734     return RES_OK;
735     }else{
736     mysql_free_result( result );
737     return RES_NO_SUCH_USER;
738     }
739 youi 1.1 }
740    
741     /**
742     *
743 aga 1.8 * ?祉???激?с?潟??篏?????xoops_vpaccount_session???吾??莨若???? sessionid_t??session???????
744     *
745     * @param uid xoops_users??id
746     * @param remoteHost remote ip (host order)
747     * @param session sessionid_t???????????????????ゃ?潟?帥??
748     * @return RES_OK ????
749     * @return RES_DB_QUERY_ERROR DB????????筝?????????/span>
750     */
751     static result_t addSession( userid_t uid, unsigned long remoteHost, sessionid_t* session )
752     {
753     result_t ret;
754     string sql = "INSERT INTO " + dbprefix + "_vpaccount_session (uid,remote_host) values (" +
755     unsignedIntToString(uid) + "," + unsignedIntToString((unsigned int)remoteHost) + ")";
756     if ( 0 == mysql_query( mysql, sql.c_str() ) ){
757     *session = (int)mysql_insert_id(mysql);
758     ret = RES_OK;
759     }
760     else {
761     ret = RES_DB_QUERY_ERROR;
762     }
763     return ret;
764     }
765    
766    
767     /**
768     *
769 youi 1.1 * ???違?ゃ?活?荐若???祉???激?с?割???
770     *
771 aga 1.6 * @param uname ???違?ゃ?喝??
772     * @param passwd ???鴻???若??
773     * @param session sessionid_t???????????????????ゃ?潟?帥??
774     * @return RES_OK ???違?ゃ?恰??????session??essionid_t???吾??莨若??????
775     * @return RES_LOGIN_FAILURE uname?障????asswd???医幻
776     * @return RES_DB_QUERY_ERROR DB????????筝?????????/span>
777 youi 1.1 *
778     */
779 aga 1.6 result_t loginUser(const char* uname, const char* passwd, sessionid_t* session )
780 youi 1.1 {
781 aga 1.6 result_t ret;
782     string sql;
783    
784     // uname, passwd -> uid
785     string escUname = addSlashes( uname );
786     string escPasswd = addSlashes( passwd );
787 youi 1.10 sql = "SELECT uid FROM " + dbprefix + "_users WHERE uname='" + escUname + "' and pass=md5('" + escPasswd + "')";
788 aga 1.6 if( 0 == mysql_query( mysql, sql.c_str( ) ) ){
789     MYSQL_RES* result = mysql_store_result( mysql );
790     if( result ){
791     MYSQL_ROW row = mysql_fetch_row(result);
792     if( row ){
793 aga 1.8 userid_t uid = atoi(row[0]);
794     ret = addSession( uid, 0, session );
795 aga 1.6 }else{
796 aga 1.9 ret = RES_LOGIN_FAILURE;
797 aga 1.6 }
798     mysql_free_result( result );
799     }else {
800     ret = RES_DB_QUERY_ERROR;
801     }
802     }else{
803     ret = RES_DB_QUERY_ERROR;
804     }
805    
806     return ret;
807 youi 1.1 }
808    
809     /**
810     *
811     * ???違?≪???????祉???激?с?括?篋?
812     *
813 aga 1.6 * @param sid session id
814     * @return ????
815 youi 1.1 *
816     */
817 youi 1.10 void logoutUser( sessionid_t sid )
818     {
819 aga 1.6 result_t ret;
820     string sql;
821 youi 1.10
822 aga 1.6 sql = "DELETE FROM " + dbprefix + "_vpaccount_session WHERE sid=" + intToString((int)sid);
823     if ( 0 == mysql_query( mysql, sql.c_str() ) ){
824     if ( mysql_affected_rows(mysql) == 1 ){
825     // ???違?≪????????
826     }
827     else {
828     // sid???≦??/span>
829     }
830     }
831     else {
832     // DB????????筝?????????/span>
833     }
834     }
835 youi 1.1
836     /**
837     *
838     * ?祉???激?с?潟?????.<br>
839     * XOOPS??ession???若????????蚊??????sess_id?????essionid??膈???????
840     * ?逸?session_t??篏?????????
841 youi 1.2 * ???若?帥???若?鴻???祉???激?с?潟????違?????宴??荐??蚊????
842 youi 1.1 *
843 aga 1.8 * @param sessionid xoops??ession_id
844     * @param uid xoops_users??id
845     * @param remoteHost remote ip (host order)
846     * @param session sessionid_t???????????????????ゃ?潟?帥??
847     * @return RES_OK
848     * @return RES_ERROR
849     * @return RES_DB_QUERY_ERROR
850 youi 1.1 *
851     */
852 aga 1.8 result_t createSession( const char* sessionid, userid_t uid, unsigned long remoteHost, sessionid_t* session )
853 youi 1.1 {
854 aga 1.8 result_t ret;
855     string sql;
856    
857     string escSessionid = addSlashes(sessionid);
858     sql = "SELECT sess_id from " + dbprefix + "_session where sess_id='" + escSessionid + "'";
859     if( 0 == mysql_query( mysql, sql.c_str( ) ) ){
860     MYSQL_RES* result = mysql_store_result( mysql );
861     if( result ){
862     MYSQL_ROW row = mysql_fetch_row(result);
863     if( row ){
864     ret = addSession( uid, remoteHost, session );
865     }else{
866     ret = RES_ERROR;
867     }
868     mysql_free_result( result );
869     }else {
870     ret = RES_DB_QUERY_ERROR;
871     }
872     }else{
873     ret = RES_DB_QUERY_ERROR;
874     }
875    
876 aga 1.11 return ret;
877 youi 1.1 }
878    
879     /**
880     *
881     * ?祉???激?с?潟???膣違??session_t?у??????.<br>
882     *
883 aga 1.8 * @param sess_id
884     * @param session
885 youi 1.1 * @return
886     *
887     */
888 aga 1.8 result_t getSession( sessionid_t sess_id, const session_t** ppsession )
889 youi 1.1 {
890 aga 1.8 result_t ret;
891     string sql;
892    
893     sql = "SELECT sid, uid, unix_timestamp(timestamp), remote_host from " + dbprefix +
894     "_vpaccount_session where sid=" + unsignedIntToString((unsigned int)sess_id);
895     if( 0 == mysql_query( mysql, sql.c_str( ) ) ){
896     MYSQL_RES* result = mysql_store_result( mysql );
897     if( result ){
898     MYSQL_ROW row = mysql_fetch_row(result);
899     if( row ){
900 aga 1.11 session_t *p = new session[1];
901 aga 1.8 p->setSessionID(sess_id);
902     p->setUserID(atoi(row[1]));
903     p->setDate(atoi(row[2]));
904     p->setRemoteHost(atoi(row[3]));
905     *ppsession = p;
906     ret = RES_OK;
907     }else{
908     ret = RES_NO_SUCH_SESSION;
909     }
910     mysql_free_result( result );
911     }else {
912     ret = RES_DB_QUERY_ERROR;
913     }
914     }else{
915     ret = RES_DB_QUERY_ERROR;
916     }
917    
918 aga 1.11 return ret;
919 youi 1.1 }
920 youi 1.2
921 youi 1.7 /**
922     *
923     * ?祉???激?с?潟???綵??с?????с????????.
924     *
925     * @param sid ???с??????????session
926     * @return true 罩e?
927     * @return false 筝?罩?/span>
928     *
929     */
930     bool isValidSessionID( sessionid_t sid )
931     {
932     string sql;
933     string sidstr;
934     char buf[ 12 ];
935     snprintf( buf, 12, "%d", sid );
936    
937 youi 1.10 sql = "SELECT * FROM " + dbprefix + "_vpaccount_session WHERE sid=" + string( buf );
938 youi 1.7 if( mysql_query( mysql, sql.c_str( ) ) ){
939     return false;
940     }
941 youi 1.10 MYSQL_RES* result = mysql_store_result( mysql ) ;
942 youi 1.7 MYSQL_ROW row = mysql_fetch_row(result);
943     if( row ){
944     return true;
945     }else{
946     return false;
947     }
948     }
949    
950 youi 1.12 void freeResult( const account_t* ptr ){ delete[] ( account_t* )ptr; }
951     void freeResult( const group_t* ptr ){ delete[] ( group_t* )ptr; }
952     void freeResult( const session_t* ptr ){ delete[] ( session_t* )ptr; }
953     void freeResult( const int* ptr ){ delete[] ( int* )ptr; }
954 youi 1.2
955 youi 1.3 static string errstr;
956     const char* getLastErrorString()
957     {
958     return errstr.c_str( );
959     }
960    
961     void setLastErrorString( const char* str )
962     {
963     errstr = str;
964     }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26