Develop and Download Open Source Software

Browse CVS Repository

Diff of /xoonips/AL/commonal.cc

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

revision 1.27 by aga, Mon Dec 6 11:34:47 2004 UTC revision 1.28 by youi, Tue Dec 14 12:02:08 2004 UTC
# Line 2  Line 2 
2   *   *
3   * $Revision$   * $Revision$
4   * $Log$   * $Log$
5     * Revision 1.28  2004/12/14 12:02:08  youi
6     * __WIN__を定義したときはwindowsのdll作成に必要な処理を行なう.
7     * USE_SYSLOGを定義したときはsyslogdへメッセージを出力する.
8     * getAccounts: uidsLenが0のときの処理を追加した.
9     *
10   * Revision 1.27  2004/12/06 11:34:47  aga   * Revision 1.27  2004/12/06 11:34:47  aga
11   * ・uninitializeDB()を追加.   * ・uninitializeDB()を追加.
12   *   *
# Line 112  Line 117 
117   *   *
118   *   *
119   */   */
120    #ifdef __WIN__
121    #include <winsock.h>
122    #define my_socket SOCKET
123    #else
124    typedef int my_socket;
125    #endif
126    
127    #ifdef USE_SYSLOG
128    #include <syslog.h>
129    #endif
130    
131  #include <stdio.h>  #include <stdio.h>
132  #include <stdlib.h>  #include <stdlib.h>
133  #include <string.h>  #include <string.h>
# Line 128  using namespace std; Line 144  using namespace std;
144  #include "criteria.h"  #include "criteria.h"
145  #include "commonal.h"  #include "commonal.h"
146    
147    #ifdef __WIN__
148    typedef MYSQL* (__stdcall *mysql_init_t)(MYSQL *mysql);
149    typedef void (__stdcall *mysql_close_t)(MYSQL *mysql);
150    typedef MYSQL* (__stdcall *mysql_real_connect_t)(MYSQL *mysql, const char *host, const char *user, const char *passwd, const char *db, unsigned int port, const char *unix_socket, unsigned int client_flag);
151    typedef unsigned long (__stdcall *mysql_real_escape_string_t)(MYSQL *mysql, char *to, const char *from, unsigned long length);
152    typedef MYSQL_RES* (__stdcall *mysql_store_result_t)(MYSQL *mysql);
153    typedef MYSQL_RES* (__stdcall *mysql_use_result_t)(MYSQL *mysql);
154    typedef int (__stdcall *mysql_query_t)(MYSQL *mysql, const char *query);
155    typedef my_ulonglong (__stdcall *mysql_num_rows_t)(MYSQL_RES *result);
156    typedef MYSQL_ROW (__stdcall *mysql_fetch_row_t)(MYSQL_RES *result);
157    typedef unsigned int (__stdcall *mysql_errno_t)(MYSQL *mysql);
158    typedef char*  (__stdcall *mysql_error_t)(MYSQL *mysql);
159    typedef my_ulonglong (__stdcall *mysql_insert_id_t)(MYSQL *mysql);
160    typedef void (__stdcall *mysql_free_result_t)(MYSQL_RES *result);
161    typedef my_ulonglong (_stdcall* mysql_affected_rows_t)(MYSQL *mysql);
162    
163    mysql_init_t fp_mysql_init = NULL;
164    mysql_close_t fp_mysql_close = NULL;
165    mysql_real_connect_t fp_mysql_real_connect = NULL;
166    mysql_real_escape_string_t fp_mysql_real_escape_string = NULL;
167    mysql_store_result_t fp_mysql_store_result = NULL;
168    mysql_use_result_t fp_mysql_use_result = NULL;
169    mysql_query_t fp_mysql_query = NULL;
170    mysql_num_rows_t fp_mysql_num_rows = NULL;
171    mysql_fetch_row_t fp_mysql_fetch_row = NULL;
172    mysql_errno_t fp_mysql_errno = NULL;
173    mysql_error_t fp_mysql_error = NULL;
174    mysql_insert_id_t fp_mysql_insert_id = NULL;
175    mysql_free_result_t fp_mysql_free_result = NULL;
176    mysql_affected_rows_t fp_mysql_affected_rows = NULL;
177    #else
178    #define fp_mysql_init mysql_init
179    #define fp_mysql_close mysql_close
180    #define fp_mysql_real_connect mysql_real_connect
181    #define fp_mysql_real_escape_string mysql_real_escape_string
182    #define fp_mysql_store_result mysql_store_result
183    #define fp_mysql_use_result mysql_use_result
184    #define fp_mysql_query mysql_query
185    #define fp_mysql_num_rows mysql_num_rows
186    #define fp_mysql_fetch_row mysql_fetch_row
187    #define fp_mysql_errno mysql_errno
188    #define fp_mysql_error mysql_error
189    #define fp_mysql_insert_id mysql_insert_id
190    #define fp_mysql_free_result mysql_free_result
191    #define fp_mysql_affected_rows mysql_affected_rows
192    #endif
193    
194  static MYSQL* mysql = NULL; //!< MySQLのハンドル  static MYSQL* mysql = NULL; //!< MySQLのハンドル
195  static string dbprefix; //!< XOOPSデータベーステーブルのPREFIX  static string dbprefix; //!< XOOPSデータベーステーブルのPREFIX
# Line 147  string addSlashes( const char *str ) Line 209  string addSlashes( const char *str )
209          }          }
210          int len = strlen(str);          int len = strlen(str);
211          char *buf = new char[len*2+1];          char *buf = new char[len*2+1];
212          int bufLen = mysql_real_escape_string( mysql, buf, str, len );          int bufLen = fp_mysql_real_escape_string( mysql, buf, str, len );
213          string s( buf, bufLen );          string s( buf, bufLen );
214          return s;          return s;
215  }  }
# Line 170  static bool gidExists( groupid_t gid ) Line 232  static bool gidExists( groupid_t gid )
232            
233      sql = "SELECT * FROM " + dbprefix + "_vpaccount_groups ";      sql = "SELECT * FROM " + dbprefix + "_vpaccount_groups ";
234      sql += "WHERE gid=" + string( unsignedIntToString( gid ) );      sql += "WHERE gid=" + string( unsignedIntToString( gid ) );
235      if( mysql_query( mysql, sql.c_str( ) ) ){      if( fp_mysql_query( mysql, sql.c_str( ) ) ){
236          fprintf( stderr, "%d %s\n", mysql_errno(mysql), mysql_error(mysql) );          fprintf( stderr, "%d %s\n", fp_mysql_errno(mysql), fp_mysql_error(mysql) );
237          return false;          return false;
238      }      }
239      result = mysql_store_result( mysql ) ;      result = fp_mysql_store_result( mysql ) ;
240      if( !mysql_fetch_row(result) ){      if( !fp_mysql_fetch_row(result) ){
241          mysql_free_result( result );          fp_mysql_free_result( result );
242          return false;          return false;
243      }      }
244      mysql_free_result( result );      fp_mysql_free_result( result );
245      return true;      return true;
246  }  }
247    
# Line 202  static bool uidExists( userid_t uid ) Line 264  static bool uidExists( userid_t uid )
264            
265      sql = "SELECT * FROM " + dbprefix + "_vpaccount_users ";      sql = "SELECT * FROM " + dbprefix + "_vpaccount_users ";
266      sql += "WHERE uid=" + string( unsignedIntToString( uid ) );      sql += "WHERE uid=" + string( unsignedIntToString( uid ) );
267      if( mysql_query( mysql, sql.c_str( ) ) ){      if( fp_mysql_query( mysql, sql.c_str( ) ) ){
268          fprintf( stderr, "%d %s\n", mysql_errno(mysql), mysql_error(mysql) );          fprintf( stderr, "%d %s\n", fp_mysql_errno(mysql), fp_mysql_error(mysql) );
269          return false;          return false;
270      }      }
271      result = mysql_store_result( mysql ) ;      result = fp_mysql_store_result( mysql ) ;
272      if( !mysql_fetch_row(result) ){      if( !fp_mysql_fetch_row(result) ){
273          mysql_free_result( result );          fp_mysql_free_result( result );
274          return false;          return false;
275      }      }
276      mysql_free_result( result );      fp_mysql_free_result( result );
277      return true;      return true;
278  }  }
279    
# Line 260  result_t initializeDB( const char* host, Line 322  result_t initializeDB( const char* host,
322  {  {
323      // 既に接続中なら、一旦切断      // 既に接続中なら、一旦切断
324      if ( mysql != NULL )      if ( mysql != NULL )
325          mysql_close( mysql );          fp_mysql_close( mysql );
326            
327      dbprefix = prefix;      dbprefix = prefix;
328            
329            
330      // 初期化と接続      // 初期化と接続
331      mysql = mysql_init(NULL);      mysql = fp_mysql_init(NULL);
332      if ( mysql == NULL ){      if ( mysql == NULL ){
333          return RES_DB_INITIALIZE_ERROR;          return RES_DB_INITIALIZE_ERROR;
334      }      }
335      char *unix_socket = NULL; // ?      char *unix_socket = NULL; // ?
336      uint flag = 0;       // ?      unsigned int flag = 0;       // ?
337      if ( NULL == mysql_real_connect( mysql, host, user, password, dbname, 3306, unix_socket, flag ) ){      if ( NULL == fp_mysql_real_connect( mysql, host, user, password, dbname, 3306, unix_socket, flag ) ){
338          return RES_DB_CONNECT_ERROR;          return RES_DB_CONNECT_ERROR;
339      }      }
340            
# Line 289  result_t initializeDB( const char* host, Line 351  result_t initializeDB( const char* host,
351  result_t uninitializeDB()  result_t uninitializeDB()
352  {  {
353      if ( mysql != NULL ){      if ( mysql != NULL ){
354          mysql_close( mysql );          fp_mysql_close( mysql );
355          mysql = NULL;          mysql = NULL;
356      }      }
357            
# Line 316  bool isActivated( sessionid_t sid, useri Line 378  bool isActivated( sessionid_t sid, useri
378            
379      sql = "SELECT * FROM " + dbprefix + "_vpaccount_users ";      sql = "SELECT * FROM " + dbprefix + "_vpaccount_users ";
380      sql += "WHERE activate=1 and uid=" + string( unsignedIntToString( uid ) );      sql += "WHERE activate=1 and uid=" + string( unsignedIntToString( uid ) );
381      if( mysql_query( mysql, sql.c_str( ) ) ){      if( fp_mysql_query( mysql, sql.c_str( ) ) ){
382          fprintf( stderr, "%d %s\n", mysql_errno(mysql), mysql_error(mysql) );          fprintf( stderr, "%d %s\n", fp_mysql_errno(mysql), fp_mysql_error(mysql) );
383          return false;          return false;
384      }      }
385      result = mysql_store_result( mysql ) ;      result = fp_mysql_store_result( mysql ) ;
386      if( row = mysql_fetch_row(result) ){      if( row = fp_mysql_fetch_row(result) ){
387          mysql_free_result( result );          fp_mysql_free_result( result );
388          return true;          return true;
389      }      }
390      return false;      return false;
# Line 348  result_t activate( sessionid_t sid, user Line 410  result_t activate( sessionid_t sid, user
410      sql = "UPDATE " + dbprefix + "_vpaccount_users ";      sql = "UPDATE " + dbprefix + "_vpaccount_users ";
411      sql += "SET activate=" + string( activate ? "1" : "0" );      sql += "SET activate=" + string( activate ? "1" : "0" );
412      sql += " WHERE uid=" + string( unsignedIntToString( uid ) );      sql += " WHERE uid=" + string( unsignedIntToString( uid ) );
413      if( mysql_query( mysql, sql.c_str( ) ) ){      if( fp_mysql_query( mysql, sql.c_str( ) ) ){
414          fprintf( stderr, "%d %s\n", mysql_errno(mysql), mysql_error(mysql) );          fprintf( stderr, "%d %s\n", fp_mysql_errno(mysql), fp_mysql_error(mysql) );
415          return RES_DB_QUERY_ERROR;          return RES_DB_QUERY_ERROR;
416      }      }
417      if ( mysql_affected_rows(mysql) == 0 ){      if ( fp_mysql_affected_rows(mysql) == 0 ){
418          // 更新失敗          // 更新失敗
419          return RES_NO_SUCH_USER;          return RES_NO_SUCH_USER;
420      }      }
# Line 379  int getAccountCount( sessionid_t sid ) Line 441  int getAccountCount( sessionid_t sid )
441            
442      //アカウント数を求める      //アカウント数を求める
443      sql = "SELECT COUNT(*) FROM " + dbprefix + "_vpaccount_users ";      sql = "SELECT COUNT(*) FROM " + dbprefix + "_vpaccount_users ";
444      if( mysql_query( mysql, sql.c_str( ) ) ){      if( fp_mysql_query( mysql, sql.c_str( ) ) ){
445          fprintf( stderr, "%d %s\n", mysql_errno(mysql), mysql_error(mysql) );          fprintf( stderr, "%d %s\n", fp_mysql_errno(mysql), fp_mysql_error(mysql) );
446          return 0;          return 0;
447      }      }
448      result = mysql_store_result( mysql ) ;      result = fp_mysql_store_result( mysql ) ;
449      if( row = mysql_fetch_row(result) ){      if( row = fp_mysql_fetch_row(result) ){
450          ret = atoi( row[ 0 ] );          ret = atoi( row[ 0 ] != NULL ? row[ 0 ] : "" );
451      }else{      }else{
452          mysql_free_result( result );          fp_mysql_free_result( result );
453          return 0;          return 0;
454      }      }
455      mysql_free_result( result );      fp_mysql_free_result( result );
456      return ret;      return ret;
457  }  }
458    
# Line 412  result_t deleteAccount( sessionid_t sid, Line 474  result_t deleteAccount( sessionid_t sid,
474      string sql;      string sql;
475      sql = "DELETE FROM " + dbprefix + "_users ";      sql = "DELETE FROM " + dbprefix + "_users ";
476      sql += "WHERE uid = " + string( unsignedIntToString( uid ) );      sql += "WHERE uid = " + string( unsignedIntToString( uid ) );
477      if( mysql_query( mysql, sql.c_str( ) ) ){      if( fp_mysql_query( mysql, sql.c_str( ) ) ){
478          fprintf( stderr, "%d %s\n", mysql_errno(mysql), mysql_error(mysql) );          fprintf( stderr, "%d %s\n", fp_mysql_errno(mysql), fp_mysql_error(mysql) );
479          return RES_DB_QUERY_ERROR;          return RES_DB_QUERY_ERROR;
480      }      }
481            
482      sql = "DELETE FROM " + dbprefix + "_vpaccount_users ";      sql = "DELETE FROM " + dbprefix + "_vpaccount_users ";
483      sql += "WHERE uid = " + string( unsignedIntToString( uid ) );      sql += "WHERE uid = " + string( unsignedIntToString( uid ) );
484      if( mysql_query( mysql, sql.c_str( ) ) ){      if( fp_mysql_query( mysql, sql.c_str( ) ) ){
485          fprintf( stderr, "%d %s\n", mysql_errno(mysql), mysql_error(mysql) );          fprintf( stderr, "%d %s\n", fp_mysql_errno(mysql), fp_mysql_error(mysql) );
486          return RES_DB_QUERY_ERROR;          return RES_DB_QUERY_ERROR;
487      }      }
488            
# Line 466  result_t getAccount( sessionid_t sid, us Line 528  result_t getAccount( sessionid_t sid, us
528   */   */
529  result_t getAccounts( sessionid_t sid, const userid_t* uids, int uidsLen, criteria_t* cri, const account_t** accounts, int* accountsLen )  result_t getAccounts( sessionid_t sid, const userid_t* uids, int uidsLen, criteria_t* cri, const account_t** accounts, int* accountsLen )
530  {  {
531    #ifdef USE_SYSLOG
532        openlog( "commonal", LOG_ODELAY, LOG_USER );
533    #endif
534      if( mysql == NULL ) return RES_DB_NOT_INITIALIZED;      if( mysql == NULL ) return RES_DB_NOT_INITIALIZED;
535      if( !isValidSessionID( sid ) ) return RES_NO_SUCH_SESSION;      if( !isValidSessionID( sid ) ) return RES_NO_SUCH_SESSION;
536        if( uidsLen <= 0 ){
537            *accounts = new account_t[ 0 ];
538            *accountsLen = 0;
539    #ifdef USE_SYSLOG
540            closelog( );
541    #endif
542            return RES_OK;
543        }
544            
545      string sql;      string sql;
546      MYSQL_RES* result;      MYSQL_RES* result;
# Line 476  result_t getAccounts( sessionid_t sid, c Line 549  result_t getAccounts( sessionid_t sid, c
549            
550      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.division, u2.tel, u2.company_name, u2.country, u2.zipcode, u2.fax, u2.base_url, u2.notice_mail, u2.notice_mail_since ";      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.division, u2.tel, u2.company_name, u2.country, u2.zipcode, u2.fax, u2.base_url, u2.notice_mail, u2.notice_mail_since ";
551      sql += "FROM " + dbprefix + "_users AS u1, " + dbprefix + "_vpaccount_users AS u2 ";      sql += "FROM " + dbprefix + "_users AS u1, " + dbprefix + "_vpaccount_users AS u2 ";
552      sql += "WHERE u1.uid = u2.uid AND ( u1.uid=" + string( unsignedIntToString( uids[ 0 ] ) );      sql += "WHERE u1.uid = u2.uid ";
553      for( int i = 1; i < uidsLen; i++ ){      if( uidsLen > 0 ){
554          sql += " OR u1.uid=" + string( unsignedIntToString( uids[ i ] ) );          sql += "AND ( u1.uid=" + string( unsignedIntToString( uids[ 0 ] ) );
555            for( int i = 1; i < uidsLen; i++ ){
556                sql += " OR u1.uid=" + string( unsignedIntToString( uids[ i ] ) );
557            }
558            sql += " ) ";
559      }      }
     sql += " ) ";  
560      sql += criteria2str( cri );      sql += criteria2str( cri );
561      if( mysql_query( mysql, sql.c_str( ) ) ){  #ifdef USE_SYSLOG
562        syslog( LOG_DEBUG, sql.c_str( ) );
563    #endif
564        if( fp_mysql_query( mysql, sql.c_str( ) ) ){
565          fprintf( stderr, "%s\n", sql.c_str( ) );          fprintf( stderr, "%s\n", sql.c_str( ) );
566          fprintf( stderr, "%d %s\n", mysql_errno(mysql), mysql_error(mysql) );          fprintf( stderr, "%d %s\n", fp_mysql_errno(mysql), fp_mysql_error(mysql) );
567    #ifdef USE_SYSLOG
568            syslog( LOG_ERR, "query failed %d %s", fp_mysql_errno(mysql), fp_mysql_error(mysql) );
569            closelog( );
570    #endif
571          return RES_DB_QUERY_ERROR;          return RES_DB_QUERY_ERROR;
572      }      }
573      result = mysql_use_result( mysql ) ;  #ifdef USE_SYSLOG
574        syslog( LOG_DEBUG, "query succeed" );
575    #endif
576        result = fp_mysql_use_result( mysql ) ;
577      *accountsLen=0;      *accountsLen=0;
578      for( int i = 0; ( row = mysql_fetch_row(result) ) != 0 && i < uidsLen ; i++ ){      for( int i = 0; ( row = fp_mysql_fetch_row(result) ) != 0 && i < uidsLen ; i++ ){
579          dst[ i ].setUID( atoi( row[ 0 ] ) );  #ifdef USE_SYSLOG
580            syslog( LOG_DEBUG, "set to account_t %d", i );
581    #endif
582            dst[ i ].setUID( atoi( row[ 0 ] != NULL ? row[ 0 ] : "" ) );
583          dst[ i ].setName( row[ 1 ] );          dst[ i ].setName( row[ 1 ] );
584          dst[ i ].setUname( row[ 2 ] );          dst[ i ].setUname( row[ 2 ] );
585          dst[ i ].setEmail( row[ 3 ] );          dst[ i ].setEmail( row[ 3 ] );
586          dst[ i ].setURL( row[ 4 ] );          dst[ i ].setURL( row[ 4 ] );
587          dst[ i ].setUserAvatar( row[ 5 ] );          dst[ i ].setUserAvatar( row[ 5 ] );
588          dst[ i ].setUserRegdate( atoi( row[ 6 ] ) );          dst[ i ].setUserRegdate( atoi( row[ 6 ] != NULL ? row[ 6 ] : "" ) );
589          dst[ i ].setUserIcq( row[ 7 ] );          dst[ i ].setUserIcq( row[ 7 ] );
590          dst[ i ].setUserFrom( row[ 8 ] );          dst[ i ].setUserFrom( row[ 8 ] );
591          dst[ i ].setUserSig( row[ 9 ] );          dst[ i ].setUserSig( row[ 9 ] );
592          dst[ i ].setUserViewemail( atoi( row[ 10 ] ) );          dst[ i ].setUserViewemail( atoi( row[ 10 ] != NULL ? row[ 10 ] : "" ) );
593          dst[ i ].setActkey( row[ 11 ] );          dst[ i ].setActkey( row[ 11 ] );
594          dst[ i ].setUserAim( row[ 12 ] );          dst[ i ].setUserAim( row[ 12 ] );
595          dst[ i ].setUserYim( row[ 13 ] );          dst[ i ].setUserYim( row[ 13 ] );
596          dst[ i ].setUserMsnm( row[ 14 ] );          dst[ i ].setUserMsnm( row[ 14 ] );
597          dst[ i ].setPass( row[ 15 ] );          dst[ i ].setPass( row[ 15 ] );
598          dst[ i ].setPosts( atoi( row[ 16 ] ) );          dst[ i ].setPosts( atoi( row[ 16 ] != NULL ? row[ 16 ] : "" ) );
599          dst[ i ].setAttachsig( atoi( row[ 17 ] ) );          dst[ i ].setAttachsig( atoi( row[ 17 ] != NULL ? row[ 17 ] : "" ) );
600          dst[ i ].setRank( atoi( row[ 18 ] ) );          dst[ i ].setRank( atoi( row[ 18 ] != NULL ? row[ 18 ] : "" ) );
601          dst[ i ].setLevel( atoi( row[ 19 ] ) );          dst[ i ].setLevel( atoi( row[ 19 ] != NULL ? row[ 19 ] : "" ) );
602          dst[ i ].setTheme( row[ 20 ] );          dst[ i ].setTheme( row[ 20 ] );
603          dst[ i ].setTimezoneOffset( atof( row[ 21 ] ) );          dst[ i ].setTimezoneOffset( atof( row[ 21 ] ) );
604          dst[ i ].setLastLogin( atoi( row[ 22 ] ) );          dst[ i ].setLastLogin( atoi( row[ 22 ] != NULL ? row[ 22 ] : "" ) );
605          dst[ i ].setUmode( row[ 23 ] );          dst[ i ].setUmode( row[ 23 ] );
606          dst[ i ].setUorder( atoi( row[ 24 ] ) );          dst[ i ].setUorder( atoi( row[ 24 ] != NULL ? row[ 24 ] : "" ) );
607          dst[ i ].setNotifyMethod( atoi( row[ 25 ] ) );          dst[ i ].setNotifyMethod( atoi( row[ 25 ] != NULL ? row[ 25 ] : "" ) );
608          dst[ i ].setNotifyMode( atoi( row[ 26 ] ) );          dst[ i ].setNotifyMode( atoi( row[ 26 ] != NULL ? row[ 26 ] : "" ) );
609          dst[ i ].setUserOcc( row[ 27 ] );          dst[ i ].setUserOcc( row[ 27 ] );
610          dst[ i ].setBio( row[ 28 ] );          dst[ i ].setBio( row[ 28 ] );
611          dst[ i ].setUserIntrest( row[ 29 ] );          dst[ i ].setUserIntrest( row[ 29 ] );
612          dst[ i ].setUserMailok( atoi( row[ 30 ] ) );          dst[ i ].setUserMailok( atoi( row[ 30 ] != NULL ? row[ 30 ] : "" ) );
613          dst[ i ].setActivate( atoi( row[ 31 ] ) );          dst[ i ].setActivate( atoi( row[ 31 ] != NULL ? row[ 31 ] : "" ) );
614          dst[ i ].setAddress( row[ 32 ] );          dst[ i ].setAddress( row[ 32 ] );
615          dst[ i ].setDivision( row[ 33 ] );          dst[ i ].setDivision( row[ 33 ] );
616          dst[ i ].setTel( row[ 34 ] );          dst[ i ].setTel( row[ 34 ] );
# Line 530  result_t getAccounts( sessionid_t sid, c Line 619  result_t getAccounts( sessionid_t sid, c
619          dst[ i ].setZipcode( row[ 37 ] );          dst[ i ].setZipcode( row[ 37 ] );
620          dst[ i ].setFax( row[ 38 ] );          dst[ i ].setFax( row[ 38 ] );
621          dst[ i ].setBaseURL( row[ 39 ] );          dst[ i ].setBaseURL( row[ 39 ] );
622          dst[ i ].setNoticeMail( atoi( row[ 40 ] ) );          dst[ i ].setNoticeMail( atoi( row[ 40 ] != NULL ? row[ 40 ] : "" ) );
623          dst[ i ].setNoticeMailSince( atoi( row[ 41 ] ) );          dst[ i ].setNoticeMailSince( atoi( row[ 41 ] != NULL ? row[ 41 ] : "" ) );
624          ( *accountsLen )++;          ( *accountsLen )++;
625      }      }
626      while( row = mysql_fetch_row(result) );      while( row = fp_mysql_fetch_row(result) );
627      mysql_free_result( result );      fp_mysql_free_result( result );
628      *accounts = dst;      *accounts = dst;
629    #ifdef USE_SYSLOG
630        syslog( LOG_DEBUG, "return RES_OK" );
631        closelog( );
632    #endif
633      return RES_OK;      return RES_OK;
634  }  }
635    
# Line 607  result_t insertAccount( sessionid_t sid, Line 700  result_t insertAccount( sessionid_t sid,
700      sql += "'" + string( addSlashes( account -> getUserIntrest( ) ) ) + "', ";      sql += "'" + string( addSlashes( account -> getUserIntrest( ) ) ) + "', ";
701      snprintf( buf, 12, "%d", account -> getUserMailok( ) );      snprintf( buf, 12, "%d", account -> getUserMailok( ) );
702      sql += string( buf ) + ")";      sql += string( buf ) + ")";
703      if( mysql_query( mysql, sql.c_str( ) ) ){      if( fp_mysql_query( mysql, sql.c_str( ) ) ){
704          fprintf( stderr, "%s\n", sql.c_str( ) );          fprintf( stderr, "%s\n", sql.c_str( ) );
705          fprintf( stderr, "%d %s\n", mysql_errno(mysql), mysql_error(mysql) );          fprintf( stderr, "%d %s\n", fp_mysql_errno(mysql), fp_mysql_error(mysql) );
706          return RES_DB_QUERY_ERROR;          return RES_DB_QUERY_ERROR;
707      }      }
708            
709      //ユーザIDを取得する      //ユーザIDを取得する
710      *uid = mysql_insert_id( mysql );      *uid = fp_mysql_insert_id( mysql );
711            
712      //vpaccountのユーザテーブルに残りの情報を書き込む      //vpaccountのユーザテーブルに残りの情報を書き込む
713      sql = "INSERT INTO " + dbprefix + "_vpaccount_users (uid, activate, address, division, tel, company_name, country, zipcode, fax, base_url, notice_mail, notice_mail_since) VALUES (";      sql = "INSERT INTO " + dbprefix + "_vpaccount_users (uid, activate, address, division, tel, company_name, country, zipcode, fax, base_url, notice_mail, notice_mail_since) VALUES (";
# Line 637  result_t insertAccount( sessionid_t sid, Line 730  result_t insertAccount( sessionid_t sid,
730      sql += string( buf ) + ", ";      sql += string( buf ) + ", ";
731      snprintf( buf, 12, "%d", account -> getNoticeMailSince( ) );      snprintf( buf, 12, "%d", account -> getNoticeMailSince( ) );
732      sql += string( buf ) + ")";      sql += string( buf ) + ")";
733      if( mysql_query( mysql, sql.c_str( ) ) ){      if( fp_mysql_query( mysql, sql.c_str( ) ) ){
734          fprintf( stderr, "%s\n", sql.c_str( ) );          fprintf( stderr, "%s\n", sql.c_str( ) );
735          fprintf( stderr, "%d %s\n", mysql_errno(mysql), mysql_error(mysql) );          fprintf( stderr, "%d %s\n", fp_mysql_errno(mysql), fp_mysql_error(mysql) );
736          //xoops_usersへinsertしたレコードを削除する          //xoops_usersへinsertしたレコードを削除する
737          sql = "DELETE FROM " + dbprefix + "_users where uid=";          sql = "DELETE FROM " + dbprefix + "_users where uid=";
738          snprintf( buf, 12, "%d", *uid );          snprintf( buf, 12, "%d", *uid );
739          sql += string( buf );          sql += string( buf );
740          mysql_query( mysql, sql.c_str( ) );          fp_mysql_query( mysql, sql.c_str( ) );
741          return RES_DB_QUERY_ERROR;          return RES_DB_QUERY_ERROR;
742      }      }
743            
# Line 710  result_t updateAccount( sessionid_t sid, Line 803  result_t updateAccount( sessionid_t sid,
803      sql += "user_mailok=" + string( intToString( account -> getUserMailok( ) ) );      sql += "user_mailok=" + string( intToString( account -> getUserMailok( ) ) );
804      sql += " WHERE uid = " + string( intToString( account -> getUID( ) ) );      sql += " WHERE uid = " + string( intToString( account -> getUID( ) ) );
805            
806      if( mysql_query( mysql, sql.c_str( ) ) ){      if( fp_mysql_query( mysql, sql.c_str( ) ) ){
807          fprintf( stderr, "%s\n", sql.c_str( ) );          fprintf( stderr, "%s\n", sql.c_str( ) );
808          fprintf( stderr, "%d %s\n", mysql_errno(mysql), mysql_error(mysql) );          fprintf( stderr, "%d %s\n", fp_mysql_errno(mysql), fp_mysql_error(mysql) );
809          return RES_DB_QUERY_ERROR;          return RES_DB_QUERY_ERROR;
810      }      }
811            
# Line 736  result_t updateAccount( sessionid_t sid, Line 829  result_t updateAccount( sessionid_t sid,
829      sql += "notice_mail_since=" + string( intToString( account -> getNoticeMailSince( ) ) );      sql += "notice_mail_since=" + string( intToString( account -> getNoticeMailSince( ) ) );
830      sql += " WHERE uid = " + string( intToString( account -> getUID( ) ) );      sql += " WHERE uid = " + string( intToString( account -> getUID( ) ) );
831            
832      if( mysql_query( mysql, sql.c_str( ) ) ){      if( fp_mysql_query( mysql, sql.c_str( ) ) ){
833          fprintf( stderr, "%s\n", sql.c_str( ) );          fprintf( stderr, "%s\n", sql.c_str( ) );
834          fprintf( stderr, "%d %s\n", mysql_errno(mysql), mysql_error(mysql) );          fprintf( stderr, "%d %s\n", fp_mysql_errno(mysql), fp_mysql_error(mysql) );
835          return RES_DB_QUERY_ERROR;          return RES_DB_QUERY_ERROR;
836      }      }
837            
# Line 771  result_t dumpUids( sessionid_t sid, crit Line 864  result_t dumpUids( sessionid_t sid, crit
864            
865      sql = "SELECT uid FROM " + dbprefix + "_vpaccount_users ";      sql = "SELECT uid FROM " + dbprefix + "_vpaccount_users ";
866      sql += criteria2str( cri );      sql += criteria2str( cri );
867      if( mysql_query( mysql, sql.c_str( ) ) ){      if( fp_mysql_query( mysql, sql.c_str( ) ) ){
868          fprintf( stderr, "%d %s\n", mysql_errno(mysql), mysql_error(mysql) );          fprintf( stderr, "%d %s\n", fp_mysql_errno(mysql), fp_mysql_error(mysql) );
869          return RES_DB_QUERY_ERROR;          return RES_DB_QUERY_ERROR;
870      }      }
871      result = mysql_store_result( mysql ) ;      result = fp_mysql_store_result( mysql ) ;
872      if( result == NULL ){      if( result == NULL ){
873          fprintf( stderr, "%d %s\n", mysql_errno(mysql), mysql_error(mysql) );          fprintf( stderr, "%d %s\n", fp_mysql_errno(mysql), fp_mysql_error(mysql) );
874          return RES_DB_QUERY_ERROR;          return RES_DB_QUERY_ERROR;
875      }      }
876      *uidsLen = mysql_num_rows( result );      *uidsLen = fp_mysql_num_rows( result );
877      dst = new userid_t[ *uidsLen ];      dst = new userid_t[ *uidsLen ];
878      for( int i = 0; ( row = mysql_fetch_row(result) ) != 0 && i < *uidsLen ; i++ ){      for( int i = 0; ( row = fp_mysql_fetch_row(result) ) != 0 && i < *uidsLen ; i++ ){
879          dst[ i ] = atoi( row[ 0 ] );          dst[ i ] = atoi( row[ 0 ] != NULL ? row[ 0 ] : "" );
880      }      }
881      mysql_free_result( result );      fp_mysql_free_result( result );
882      *uids = dst;      *uids = dst;
883            
884      return RES_OK;      return RES_OK;
# Line 812  int getGroupCount( sessionid_t sid ) Line 905  int getGroupCount( sessionid_t sid )
905            
906      //グループ数を求める      //グループ数を求める
907      sql = "SELECT COUNT(*) FROM " + dbprefix + "_vpaccount_groups";      sql = "SELECT COUNT(*) FROM " + dbprefix + "_vpaccount_groups";
908      if( mysql_query( mysql, sql.c_str( ) ) ){      if( fp_mysql_query( mysql, sql.c_str( ) ) ){
909          fprintf( stderr, "%d %s\n", mysql_errno(mysql), mysql_error(mysql) );          fprintf( stderr, "%d %s\n", fp_mysql_errno(mysql), fp_mysql_error(mysql) );
910          return RES_DB_QUERY_ERROR;          return RES_DB_QUERY_ERROR;
911      }      }
912      result = mysql_store_result( mysql ) ;      result = fp_mysql_store_result( mysql ) ;
913      if( row = mysql_fetch_row(result) ){      if( row = fp_mysql_fetch_row(result) ){
914          groupLen = atoi( row[ 0 ] );          groupLen = atoi( row[ 0 ] != NULL ? row[ 0 ] : "" );
915      }      }
916      mysql_free_result( result );      fp_mysql_free_result( result );
917      return groupLen;      return groupLen;
918  }  }
919    
# Line 848  result_t getGroupsByUid( sessionid_t sid Line 941  result_t getGroupsByUid( sessionid_t sid
941      sql = "SELECT count(*) FROM " + dbprefix + "_vpaccount_groups_users_link";      sql = "SELECT count(*) FROM " + dbprefix + "_vpaccount_groups_users_link";
942      sql += " WHERE uid=" + string( unsignedIntToString( uid ) );      sql += " WHERE uid=" + string( unsignedIntToString( uid ) );
943      sql += criteria2str( cri );      sql += criteria2str( cri );
944      if( mysql_query( mysql, sql.c_str( ) ) ){      if( fp_mysql_query( mysql, sql.c_str( ) ) ){
945          fprintf( stderr, "%s\n", sql.c_str( ) );          fprintf( stderr, "%s\n", sql.c_str( ) );
946          fprintf( stderr, "%d %s\n", mysql_errno(mysql), mysql_error(mysql) );          fprintf( stderr, "%d %s\n", fp_mysql_errno(mysql), fp_mysql_error(mysql) );
947          return RES_DB_QUERY_ERROR;          return RES_DB_QUERY_ERROR;
948      }      }
949      result = mysql_store_result( mysql ) ;      result = fp_mysql_store_result( mysql ) ;
950      if( row = mysql_fetch_row(result) ){      if( row = fp_mysql_fetch_row(result) ){
951          len = atoi( row[ 0 ] );          len = atoi( row[ 0 ] != NULL ? row[ 0 ] : "" );
952      }      }
953      mysql_free_result( result );      fp_mysql_free_result( result );
954            
955      sql = "SELECT gid, uid, is_admin FROM " + dbprefix + "_vpaccount_groups_users_link";      sql = "SELECT gid, uid, is_admin FROM " + dbprefix + "_vpaccount_groups_users_link";
956      sql += " WHERE uid=" + string( unsignedIntToString( uid ) );      sql += " WHERE uid=" + string( unsignedIntToString( uid ) );
957      sql += criteria2str( cri );      sql += criteria2str( cri );
958      if( mysql_query( mysql, sql.c_str( ) ) ){      if( fp_mysql_query( mysql, sql.c_str( ) ) ){
959          fprintf( stderr, "%s\n", sql.c_str( ) );          fprintf( stderr, "%s\n", sql.c_str( ) );
960          fprintf( stderr, "%d %s\n", mysql_errno(mysql), mysql_error(mysql) );          fprintf( stderr, "%d %s\n", fp_mysql_errno(mysql), fp_mysql_error(mysql) );
961          return RES_DB_QUERY_ERROR;          return RES_DB_QUERY_ERROR;
962      }      }
963      *gidsLen = 0;      *gidsLen = 0;
964      dst = new groupid_t[ len ];      dst = new groupid_t[ len ];
965      result = mysql_store_result( mysql ) ;      result = fp_mysql_store_result( mysql ) ;
966      for( int i = 0; ( row = mysql_fetch_row(result) ) != 0 && i < len ; i++ ){      for( int i = 0; ( row = fp_mysql_fetch_row(result) ) != 0 && i < len ; i++ ){
967          dst[ i ] = atoi( row[ 0 ] );          dst[ i ] = atoi( row[ 0 ] != NULL ? row[ 0 ] : "" );
968          ( *gidsLen )++;          ( *gidsLen )++;
969      }      }
970      mysql_free_result( result );      fp_mysql_free_result( result );
971      *gids = dst;      *gids = dst;
972            
973      return RES_OK;      return RES_OK;
# Line 905  bool isGroupAdmin( sessionid_t sid, grou Line 998  bool isGroupAdmin( sessionid_t sid, grou
998      sql += "WHERE gid=" + string( unsignedIntToString( gid ) );      sql += "WHERE gid=" + string( unsignedIntToString( gid ) );
999      sql += " AND uid=" + string( unsignedIntToString( uid ) );      sql += " AND uid=" + string( unsignedIntToString( uid ) );
1000      sql += " AND is_admin=1";      sql += " AND is_admin=1";
1001      if( mysql_query( mysql, sql.c_str( ) ) ){      if( fp_mysql_query( mysql, sql.c_str( ) ) ){
1002          fprintf( stderr, "%d %s\n", mysql_errno(mysql), mysql_error(mysql) );          fprintf( stderr, "%d %s\n", fp_mysql_errno(mysql), fp_mysql_error(mysql) );
1003          return false;          return false;
1004      }      }
1005      result = mysql_store_result( mysql );      result = fp_mysql_store_result( mysql );
1006      if( !mysql_fetch_row(result) ){      if( !fp_mysql_fetch_row(result) ){
1007          mysql_free_result( result );          fp_mysql_free_result( result );
1008          return false;          return false;
1009      }      }
1010            
1011      mysql_free_result( result );      fp_mysql_free_result( result );
1012      return true;;      return true;;
1013  }  }
1014    
# Line 939  result_t dumpGids( sessionid_t sid, crit Line 1032  result_t dumpGids( sessionid_t sid, crit
1032            
1033      sql = "SELECT gid FROM " + dbprefix + "_vpaccount_groups ";      sql = "SELECT gid FROM " + dbprefix + "_vpaccount_groups ";
1034      sql += criteria2str( cri );      sql += criteria2str( cri );
1035      if( mysql_query( mysql, sql.c_str( ) ) ){      if( fp_mysql_query( mysql, sql.c_str( ) ) ){
1036          fprintf( stderr, "%d %s\n", mysql_errno(mysql), mysql_error(mysql) );          fprintf( stderr, "%d %s\n", fp_mysql_errno(mysql), fp_mysql_error(mysql) );
1037          return RES_DB_QUERY_ERROR;          return RES_DB_QUERY_ERROR;
1038      }      }
1039      result = mysql_store_result( mysql ) ;      result = fp_mysql_store_result( mysql ) ;
1040      if( result == NULL ){      if( result == NULL ){
1041          fprintf( stderr, "%d %s\n", mysql_errno(mysql), mysql_error(mysql) );          fprintf( stderr, "%d %s\n", fp_mysql_errno(mysql), fp_mysql_error(mysql) );
1042          return RES_DB_QUERY_ERROR;          return RES_DB_QUERY_ERROR;
1043      }      }
1044      *gidsLen = mysql_num_rows( result );      *gidsLen = fp_mysql_num_rows( result );
1045      dst = new groupid_t[ *gidsLen ];      dst = new groupid_t[ *gidsLen ];
1046      for( int i = 0; ( row = mysql_fetch_row(result) ) != 0 && i < *gidsLen ; i++ ){      for( int i = 0; ( row = fp_mysql_fetch_row(result) ) != 0 && i < *gidsLen ; i++ ){
1047          dst[ i ] = atoi( row[ 0 ] );          dst[ i ] = atoi( row[ 0 ] != NULL ? row[ 0 ] : "" );
1048      }      }
1049      mysql_free_result( result );      fp_mysql_free_result( result );
1050      *gids = dst;      *gids = dst;
1051            
1052      return RES_OK;      return RES_OK;
# Line 969  result_t dumpGids( sessionid_t sid, crit Line 1062  result_t dumpGids( sessionid_t sid, crit
1062      //グループ数を求める      //グループ数を求める
1063      sql = "SELECT COUNT(*) FROM " + dbprefix + "_vpaccount_groups ";      sql = "SELECT COUNT(*) FROM " + dbprefix + "_vpaccount_groups ";
1064      sql += criteria2str( cri );      sql += criteria2str( cri );
1065      if( mysql_query( mysql, sql.c_str( ) ) ){      if( fp_mysql_query( mysql, sql.c_str( ) ) ){
1066          fprintf( stderr, "%d %s\n", mysql_errno(mysql), mysql_error(mysql) );          fprintf( stderr, "%d %s\n", fp_mysql_errno(mysql), fp_mysql_error(mysql) );
1067          return RES_DB_QUERY_ERROR;          return RES_DB_QUERY_ERROR;
1068      }      }
1069      result = mysql_store_result( mysql ) ;      result = fp_mysql_store_result( mysql ) ;
1070      if( row = mysql_fetch_row(result) ){      if( row = fp_mysql_fetch_row(result) ){
1071          *gidsLen = atoi( row[ 0 ] );          *gidsLen = atoi( row[ 0 ] != NULL ? row[ 0 ] : "" );
1072          dst = new groupid_t[ *gidsLen ];          dst = new groupid_t[ *gidsLen ];
1073      }else{      }else{
1074          mysql_free_result( result );          fp_mysql_free_result( result );
1075          return RES_ERROR;          return RES_ERROR;
1076      }      }
1077      mysql_free_result( result );      fp_mysql_free_result( result );
1078            
1079      sql = "SELECT gid, gname, gdesc FROM " + dbprefix + "_vpaccount_groups ";      sql = "SELECT gid, gname, gdesc FROM " + dbprefix + "_vpaccount_groups ";
1080      sql += criteria2str( cri );      sql += criteria2str( cri );
1081      if( mysql_query( mysql, sql.c_str( ) ) ){      if( fp_mysql_query( mysql, sql.c_str( ) ) ){
1082          fprintf( stderr, "%d %s\n", mysql_errno(mysql), mysql_error(mysql) );          fprintf( stderr, "%d %s\n", fp_mysql_errno(mysql), fp_mysql_error(mysql) );
1083          return RES_DB_QUERY_ERROR;          return RES_DB_QUERY_ERROR;
1084      }      }
1085            
1086      result = mysql_use_result( mysql ) ;      result = fp_mysql_use_result( mysql ) ;
1087      for( int i = 0; ( row = mysql_fetch_row(result) ) != 0 && i < *gidsLen ; i++ ){      for( int i = 0; ( row = fp_mysql_fetch_row(result) ) != 0 && i < *gidsLen ; i++ ){
1088          dst[ i ] = atoi( row[ 0 ] );          dst[ i ] = atoi( row[ 0 ] != NULL ? row[ 0 ] : "" );
1089      }      }
1090      mysql_free_result( result );      fp_mysql_free_result( result );
1091      *gids = dst;      *gids = dst;
1092            
1093      return RES_OK;      return RES_OK;
# Line 1029  result_t dumpGroupAdmins( sessionid_t si Line 1122  result_t dumpGroupAdmins( sessionid_t si
1122            
1123      sql = "SELECT uid FROM " + dbprefix + "_vpaccount_groups_users_link ";      sql = "SELECT uid FROM " + dbprefix + "_vpaccount_groups_users_link ";
1124      sql += " WHERE is_admin=1";      sql += " WHERE is_admin=1";
1125      if( mysql_query( mysql, sql.c_str( ) ) ){      if( fp_mysql_query( mysql, sql.c_str( ) ) ){
1126          fprintf( stderr, "%d %s\n", mysql_errno(mysql), mysql_error(mysql) );          fprintf( stderr, "%d %s\n", fp_mysql_errno(mysql), fp_mysql_error(mysql) );
1127          return RES_DB_QUERY_ERROR;          return RES_DB_QUERY_ERROR;
1128      }      }
1129            
1130      result = mysql_store_result( mysql );      result = fp_mysql_store_result( mysql );
1131      if( result == NULL ){      if( result == NULL ){
1132          fprintf( stderr, "%d %s\n", mysql_errno(mysql), mysql_error(mysql) );          fprintf( stderr, "%d %s\n", fp_mysql_errno(mysql), fp_mysql_error(mysql) );
1133          return RES_DB_QUERY_ERROR;          return RES_DB_QUERY_ERROR;
1134      }      }
1135            
1136      *uidsLen = mysql_num_rows( result );      *uidsLen = fp_mysql_num_rows( result );
1137      dst = new userid_t[ *uidsLen ];      dst = new userid_t[ *uidsLen ];
1138      for( int i = 0; ( row = mysql_fetch_row(result) ) != 0 && i < *uidsLen ; i++ ){      for( int i = 0; ( row = fp_mysql_fetch_row(result) ) != 0 && i < *uidsLen ; i++ ){
1139          dst[ i ] = atoi( row[ 0 ] );          dst[ i ] = atoi( row[ 0 ] != NULL ? row[ 0 ] : "" );
1140      }      }
1141      mysql_free_result( result );      fp_mysql_free_result( result );
1142      *uids = dst;      *uids = dst;
1143            
1144      return RES_OK;      return RES_OK;
# Line 1071  result_t deleteMember( sessionid_t sid, Line 1164  result_t deleteMember( sessionid_t sid,
1164      sql = "DELETE FROM " + dbprefix + "_vpaccount_groups_users_link ";      sql = "DELETE FROM " + dbprefix + "_vpaccount_groups_users_link ";
1165      sql += "WHERE gid=" + string( unsignedIntToString( gid ) );      sql += "WHERE gid=" + string( unsignedIntToString( gid ) );
1166      sql += " AND uid=" + string( unsignedIntToString( uid ) );      sql += " AND uid=" + string( unsignedIntToString( uid ) );
1167      if( mysql_query( mysql, sql.c_str( ) ) ){      if( fp_mysql_query( mysql, sql.c_str( ) ) ){
1168          fprintf( stderr, "%d %s\n", mysql_errno(mysql), mysql_error(mysql) );          fprintf( stderr, "%d %s\n", fp_mysql_errno(mysql), fp_mysql_error(mysql) );
1169          return RES_DB_QUERY_ERROR;          return RES_DB_QUERY_ERROR;
1170      }      }
1171      return RES_OK;      return RES_OK;
# Line 1090  result_t deleteMember( sessionid_t sid, Line 1183  result_t deleteMember( sessionid_t sid,
1183   * @return RES_DB_NOT_INITIALIZED   * @return RES_DB_NOT_INITIALIZED
1184   * @return RES_NO_SUCH_SESSION   * @return RES_NO_SUCH_SESSION
1185   * @return RES_DB_QUERY_ERROR   * @return RES_DB_QUERY_ERROR
1186   * @return RES_ERROR   * @return RES_ERROR
1187   *   *
1188   */   */
1189  result_t insertMember( sessionid_t sid, groupid_t gid, userid_t uid, bool admin )  result_t insertMember( sessionid_t sid, groupid_t gid, userid_t uid, bool admin )
# Line 1111  result_t insertMember( sessionid_t sid, Line 1204  result_t insertMember( sessionid_t sid,
1204      sql += string( unsignedIntToString( gid ) ) + ", ";      sql += string( unsignedIntToString( gid ) ) + ", ";
1205      sql += string( unsignedIntToString( uid ) ) + ", ";      sql += string( unsignedIntToString( uid ) ) + ", ";
1206      sql += string( admin ? "1" : "0" ) + ") ";      sql += string( admin ? "1" : "0" ) + ") ";
1207      if( mysql_query( mysql, sql.c_str( ) ) ){      if( fp_mysql_query( mysql, sql.c_str( ) ) ){
1208          fprintf( stderr, "%d %s\n", mysql_errno(mysql), mysql_error(mysql) );          fprintf( stderr, "%d %s\n", fp_mysql_errno(mysql), fp_mysql_error(mysql) );
1209          return RES_DB_QUERY_ERROR;          return RES_DB_QUERY_ERROR;
1210      }      }
1211      return RES_OK;      return RES_OK;
# Line 1141  result_t getMembers( sessionid_t sid, gr Line 1234  result_t getMembers( sessionid_t sid, gr
1234      //メンバー数を求めてメモリ確保      //メンバー数を求めてメモリ確保
1235      sql = "SELECT COUNT(*) FROM " + dbprefix + "_vpaccount_groups_users_link ";      sql = "SELECT COUNT(*) FROM " + dbprefix + "_vpaccount_groups_users_link ";
1236      sql += " WHERE gid=" + string( unsignedIntToString( gid ) );      sql += " WHERE gid=" + string( unsignedIntToString( gid ) );
1237      if( mysql_query( mysql, sql.c_str( ) ) ){      if( fp_mysql_query( mysql, sql.c_str( ) ) ){
1238          fprintf( stderr, "%s\n", sql.c_str( ) );          fprintf( stderr, "%s\n", sql.c_str( ) );
1239          fprintf( stderr, "%d %s\n", mysql_errno(mysql), mysql_error(mysql) );          fprintf( stderr, "%d %s\n", fp_mysql_errno(mysql), fp_mysql_error(mysql) );
1240          return RES_DB_QUERY_ERROR;          return RES_DB_QUERY_ERROR;
1241      }      }
1242      result = mysql_store_result( mysql ) ;      result = fp_mysql_store_result( mysql ) ;
1243      if( row = mysql_fetch_row(result) ){      if( row = fp_mysql_fetch_row(result) ){
1244          len = atoi( row[ 0 ] );          len = atoi( row[ 0 ] != NULL ? row[ 0 ] : "" );
1245          dst = new userid_t[ len ];          dst = new userid_t[ len ];
1246      }else{      }else{
1247          mysql_free_result( result );          fp_mysql_free_result( result );
1248          return RES_ERROR;          return RES_ERROR;
1249      }      }
1250      mysql_free_result( result );      fp_mysql_free_result( result );
1251            
1252      sql = "SELECT uid, gid, is_admin FROM " + dbprefix + "_vpaccount_groups_users_link ";      sql = "SELECT uid, gid, is_admin FROM " + dbprefix + "_vpaccount_groups_users_link ";
1253      sql += " WHERE gid=" + string( unsignedIntToString( gid ) );      sql += " WHERE gid=" + string( unsignedIntToString( gid ) );
1254      sql += " " + string( criteria2str( cri ) );      sql += " " + string( criteria2str( cri ) );
1255      if( mysql_query( mysql, sql.c_str( ) ) ){      if( fp_mysql_query( mysql, sql.c_str( ) ) ){
1256          fprintf( stderr, "%d %s\n", mysql_errno(mysql), mysql_error(mysql) );          fprintf( stderr, "%d %s\n", fp_mysql_errno(mysql), fp_mysql_error(mysql) );
1257          delete[] dst;          delete[] dst;
1258          *uidsLen = 0;          *uidsLen = 0;
1259          return RES_DB_QUERY_ERROR;          return RES_DB_QUERY_ERROR;
1260      }      }
1261      *uidsLen = 0;      *uidsLen = 0;
1262      result = mysql_use_result( mysql ) ;      result = fp_mysql_use_result( mysql ) ;
1263      for( int i = 0; ( row = mysql_fetch_row(result) ) != 0 && i < len ; i++ ){      for( int i = 0; ( row = fp_mysql_fetch_row(result) ) != 0 && i < len ; i++ ){
1264          dst[ i ] = atoi( row[ 0 ] );          dst[ i ] = atoi( row[ 0 ] != NULL ? row[ 0 ] : "" );
1265          ( *uidsLen )++;          ( *uidsLen )++;
1266      }      }
1267      while( row = mysql_fetch_row(result) );      while( row = fp_mysql_fetch_row(result) );
1268      mysql_free_result( result );      fp_mysql_free_result( result );
1269      *uids = dst;      *uids = dst;
1270      return RES_OK;      return RES_OK;
1271  }  }
# Line 1196  result_t deleteGroup( sessionid_t sid, g Line 1289  result_t deleteGroup( sessionid_t sid, g
1289      string sql;      string sql;
1290      sql = "DELETE FROM " + dbprefix + "_vpaccount_groups ";      sql = "DELETE FROM " + dbprefix + "_vpaccount_groups ";
1291      sql += "WHERE gid = " + string( unsignedIntToString( gid ) );      sql += "WHERE gid = " + string( unsignedIntToString( gid ) );
1292      if( mysql_query( mysql, sql.c_str( ) ) ){      if( fp_mysql_query( mysql, sql.c_str( ) ) ){
1293          fprintf( stderr, "%s\n", sql.c_str( ) );          fprintf( stderr, "%s\n", sql.c_str( ) );
1294          fprintf( stderr, "%d %s\n", mysql_errno(mysql), mysql_error(mysql) );          fprintf( stderr, "%d %s\n", fp_mysql_errno(mysql), fp_mysql_error(mysql) );
1295          return RES_DB_QUERY_ERROR;          return RES_DB_QUERY_ERROR;
1296      }      }
1297      return RES_OK;      return RES_OK;
# Line 1228  result_t insertGroup( sessionid_t sid, c Line 1321  result_t insertGroup( sessionid_t sid, c
1321      sql = "INSERT INTO " + dbprefix + "_vpaccount_groups ( gname, gdesc ) VALUES (";      sql = "INSERT INTO " + dbprefix + "_vpaccount_groups ( gname, gdesc ) VALUES (";
1322      sql += "'" + string( addSlashes( group -> getGname( ) ) ) + "', ";      sql += "'" + string( addSlashes( group -> getGname( ) ) ) + "', ";
1323      sql += "'" + string( addSlashes( group -> getDesc( ) ) ) + "' )";      sql += "'" + string( addSlashes( group -> getDesc( ) ) ) + "' )";
1324      if( mysql_query( mysql, sql.c_str( ) ) ){      if( fp_mysql_query( mysql, sql.c_str( ) ) ){
1325          fprintf( stderr, "%s\n", sql.c_str( ) );          fprintf( stderr, "%s\n", sql.c_str( ) );
1326          fprintf( stderr, "%d %s\n", mysql_errno(mysql), mysql_error(mysql) );          fprintf( stderr, "%d %s\n", fp_mysql_errno(mysql), fp_mysql_error(mysql) );
1327          return RES_DB_QUERY_ERROR;          return RES_DB_QUERY_ERROR;
1328      }      }
1329      *gid = mysql_insert_id( mysql );      *gid = fp_mysql_insert_id( mysql );
1330      return RES_OK;      return RES_OK;
1331  }  }
1332    
# Line 1263  result_t updateGroup( sessionid_t sid, c Line 1356  result_t updateGroup( sessionid_t sid, c
1356      sql += "gname='" + string( addSlashes( group -> getGname( ) ) ) + "', ";      sql += "gname='" + string( addSlashes( group -> getGname( ) ) ) + "', ";
1357      sql += "gdesc='" + string( addSlashes( group -> getDesc( ) ) ) + "' ";      sql += "gdesc='" + string( addSlashes( group -> getDesc( ) ) ) + "' ";
1358      sql += "WHERE gid=" + string( unsignedIntToString( group -> getGID( ) ) );      sql += "WHERE gid=" + string( unsignedIntToString( group -> getGID( ) ) );
1359      if( mysql_query( mysql, sql.c_str( ) ) ){      if( fp_mysql_query( mysql, sql.c_str( ) ) ){
1360          fprintf( stderr, "%s\n", sql.c_str( ) );          fprintf( stderr, "%s\n", sql.c_str( ) );
1361          fprintf( stderr, "%d %s\n", mysql_errno(mysql), mysql_error(mysql) );          fprintf( stderr, "%d %s\n", fp_mysql_errno(mysql), fp_mysql_error(mysql) );
1362          return RES_DB_QUERY_ERROR;          return RES_DB_QUERY_ERROR;
1363      }      }
1364      return RES_OK;      return RES_OK;
# Line 1322  result_t getGroups( sessionid_t sid, gro Line 1415  result_t getGroups( sessionid_t sid, gro
1415            
1416      sql += "SELECT gid, gname, gdesc ";      sql += "SELECT gid, gname, gdesc ";
1417      sql += "FROM " + dbprefix + "_vpaccount_groups ";      sql += "FROM " + dbprefix + "_vpaccount_groups ";
1418      sql += "WHERE gid=" + string( unsignedIntToString( gids[ 0 ] ) );      if( gidsLen > 0 ){
1419      for( int i = 1; i < gidsLen; i++ ){          sql += "WHERE gid=" + string( unsignedIntToString( gids[ 0 ] ) );
1420          sql += " OR gid=" + string( unsignedIntToString( gids[ i ] ) );          for( int i = 1; i < gidsLen; i++ ){
1421                sql += " OR gid=" + string( unsignedIntToString( gids[ i ] ) );
1422            }
1423      }      }
1424      sql += criteria2str( cri );      sql += criteria2str( cri );
1425      if( mysql_query( mysql, sql.c_str( ) ) ){      if( fp_mysql_query( mysql, sql.c_str( ) ) ){
1426          fprintf( stderr, "%s\n", sql.c_str( ) );          fprintf( stderr, "%s\n", sql.c_str( ) );
1427          fprintf( stderr, "%d %s\n", mysql_errno(mysql), mysql_error(mysql) );          fprintf( stderr, "%d %s\n", fp_mysql_errno(mysql), fp_mysql_error(mysql) );
1428          return RES_DB_QUERY_ERROR;          return RES_DB_QUERY_ERROR;
1429      }      }
1430      result = mysql_use_result( mysql ) ;      result = fp_mysql_use_result( mysql ) ;
1431      *groupsLen=0;      *groupsLen=0;
1432      for( int i = 0; ( row = mysql_fetch_row(result) ) != 0 && i < gidsLen ; i++ ){      for( int i = 0; ( row = fp_mysql_fetch_row(result) ) != 0 && i < gidsLen ; i++ ){
1433          dst[ i ].setGID( atoi( row[ 0 ] ) );          dst[ i ].setGID( atoi( row[ 0 ] != NULL ? row[ 0 ] : "" ) );
1434          dst[ i ].setGname( row[ 1 ] );          dst[ i ].setGname( row[ 1 ] );
1435          dst[ i ].setDesc( row[ 2 ] );          dst[ i ].setDesc( row[ 2 ] );
1436          ( *groupsLen )++;          ( *groupsLen )++;
1437      }      }
1438      while( row = mysql_fetch_row(result) );      while( row = fp_mysql_fetch_row(result) );
1439      mysql_free_result( result );      fp_mysql_free_result( result );
1440      *groups = dst;      *groups = dst;
1441      return RES_OK;      return RES_OK;
1442  }  }
# Line 1370  bool isModerator( sessionid_t sid, useri Line 1465  bool isModerator( sessionid_t sid, useri
1465            
1466      sql = "SELECT value FROM " + dbprefix + "_vpaccount_config";      sql = "SELECT value FROM " + dbprefix + "_vpaccount_config";
1467      sql += " WHERE name='moderator_gid'";      sql += " WHERE name='moderator_gid'";
1468      if( mysql_query( mysql, sql.c_str( ) ) ){      if( fp_mysql_query( mysql, sql.c_str( ) ) ){
1469          fprintf( stderr, "%s\n", sql.c_str( ) );          fprintf( stderr, "%s\n", sql.c_str( ) );
1470          fprintf( stderr, "%d %s\n", mysql_errno(mysql), mysql_error(mysql) );          fprintf( stderr, "%d %s\n", fp_mysql_errno(mysql), fp_mysql_error(mysql) );
1471          return false;          return false;
1472      }      }
1473      result = mysql_store_result( mysql ) ;      result = fp_mysql_store_result( mysql ) ;
1474      if( result == NULL ){      if( result == NULL ){
1475          fprintf( stderr, "%d %s\n", mysql_errno(mysql), mysql_error(mysql) );          fprintf( stderr, "%d %s\n", fp_mysql_errno(mysql), fp_mysql_error(mysql) );
1476          return false;          return false;
1477      }      }
1478      if( row = mysql_fetch_row(result) ){      if( row = fp_mysql_fetch_row(result) ){
1479          sql = "SELECT * from " + dbprefix + "_groups_users_link ";          sql = "SELECT * from " + dbprefix + "_groups_users_link ";
1480          sql += "WHERE groupid=" + string( row[ 0 ] );          sql += "WHERE groupid=" + string( row[ 0 ] );
1481          sql += " AND uid=" + string( unsignedIntToString( uid ) );          sql += " AND uid=" + string( unsignedIntToString( uid ) );
1482          mysql_free_result( result );          fp_mysql_free_result( result );
1483                    
1484          if( mysql_query( mysql, sql.c_str( ) ) ){          if( fp_mysql_query( mysql, sql.c_str( ) ) ){
1485              fprintf( stderr, "%d %s\n", mysql_errno(mysql), mysql_error(mysql) );              fprintf( stderr, "%d %s\n", fp_mysql_errno(mysql), fp_mysql_error(mysql) );
1486              return false;              return false;
1487          }          }
1488          result = mysql_store_result( mysql );          result = fp_mysql_store_result( mysql );
1489          if( result == NULL ){          if( result == NULL ){
1490              fprintf( stderr, "%d %s\n", mysql_errno(mysql), mysql_error(mysql) );              fprintf( stderr, "%d %s\n", fp_mysql_errno(mysql), fp_mysql_error(mysql) );
1491              return false;              return false;
1492          }          }
1493          if( !mysql_fetch_row(result) ){          if( !fp_mysql_fetch_row(result) ){
1494              mysql_free_result( result );              fp_mysql_free_result( result );
1495              return false;              return false;
1496          }          }
1497          mysql_free_result( result );          fp_mysql_free_result( result );
1498          return true;          return true;
1499      }else{      }else{
1500          mysql_free_result( result );          fp_mysql_free_result( result );
1501          return false;          return false;
1502      }      }
1503  }  }
# Line 1426  result_t getUid( const char* uname, user Line 1521  result_t getUid( const char* uname, user
1521      string sql;      string sql;
1522      string uname2 = addSlashes( uname );      string uname2 = addSlashes( uname );
1523      sql = "SELECT uid FROM " + dbprefix + "_users WHERE uname='" + uname2 + "';";      sql = "SELECT uid FROM " + dbprefix + "_users WHERE uname='" + uname2 + "';";
1524      if( mysql_query( mysql, sql.c_str( ) ) ){      if( fp_mysql_query( mysql, sql.c_str( ) ) ){
1525          fprintf( stderr, "%d %s\n", mysql_errno(mysql), mysql_error(mysql) );          fprintf( stderr, "%d %s\n", fp_mysql_errno(mysql), fp_mysql_error(mysql) );
1526          return RES_DB_QUERY_ERROR;          return RES_DB_QUERY_ERROR;
1527      }      }
1528      MYSQL_RES* result = mysql_store_result( mysql ) ;      MYSQL_RES* result = fp_mysql_store_result( mysql ) ;
1529      MYSQL_ROW row = mysql_fetch_row(result);      MYSQL_ROW row = fp_mysql_fetch_row(result);
1530      if( row ){      if( row ){
1531          *uid = atoi( row[0] );          *uid = atoi( row[0] != NULL ? row[0] : "" );
1532          mysql_free_result( result );          fp_mysql_free_result( result );
1533          return RES_OK;          return RES_OK;
1534      }else{      }else{
1535          mysql_free_result( result );          fp_mysql_free_result( result );
1536          return RES_NO_SUCH_USER;          return RES_NO_SUCH_USER;
1537      }      }
1538  }  }
# Line 1456  static result_t addSession( userid_t uid Line 1551  static result_t addSession( userid_t uid
1551      result_t ret;      result_t ret;
1552      string sql = "INSERT INTO " + dbprefix + "_vpaccount_session (uid) values (" +      string sql = "INSERT INTO " + dbprefix + "_vpaccount_session (uid) values (" +
1553        unsignedIntToString(uid) + ")";        unsignedIntToString(uid) + ")";
1554      if ( 0 == mysql_query( mysql, sql.c_str() ) ){      if ( 0 == fp_mysql_query( mysql, sql.c_str() ) ){
1555          *session = (int)mysql_insert_id(mysql);          *session = (int)fp_mysql_insert_id(mysql);
1556          ret = RES_OK;          ret = RES_OK;
1557      }      }
1558      else {      else {
# Line 1490  result_t loginUser(const char* uname, co Line 1585  result_t loginUser(const char* uname, co
1585      string escUname = addSlashes( uname );      string escUname = addSlashes( uname );
1586      string escPasswd = addSlashes( passwd );      string escPasswd = addSlashes( passwd );
1587      sql = "SELECT uid FROM " + dbprefix + "_users WHERE uname='" + escUname + "' and pass=md5('" + escPasswd + "')";      sql = "SELECT uid FROM " + dbprefix + "_users WHERE uname='" + escUname + "' and pass=md5('" + escPasswd + "')";
1588      if( 0 == mysql_query( mysql, sql.c_str( ) ) ){      if( 0 == fp_mysql_query( mysql, sql.c_str( ) ) ){
1589          MYSQL_RES* result = mysql_store_result( mysql );          MYSQL_RES* result = fp_mysql_store_result( mysql );
1590          if( result ){          if( result ){
1591              MYSQL_ROW row = mysql_fetch_row(result);              MYSQL_ROW row = fp_mysql_fetch_row(result);
1592              if( row ){              if( row ){
1593                  userid_t uid = atoi(row[0]);                  userid_t uid = atoi( row[0] != NULL ? row[0] : "" );
1594                  ret = addSession( uid, session );                  ret = addSession( uid, session );
1595              }else{              }else{
1596                  ret = RES_LOGIN_FAILURE;                  ret = RES_LOGIN_FAILURE;
1597              }              }
1598              mysql_free_result( result );              fp_mysql_free_result( result );
1599          }else {          }else {
1600              ret = RES_DB_QUERY_ERROR;              ret = RES_DB_QUERY_ERROR;
1601          }          }
# Line 1527  void logoutUser( sessionid_t sid ) Line 1622  void logoutUser( sessionid_t sid )
1622      string sql;      string sql;
1623            
1624      sql = "DELETE FROM " + dbprefix + "_vpaccount_session WHERE sid=" + intToString((int)sid);      sql = "DELETE FROM " + dbprefix + "_vpaccount_session WHERE sid=" + intToString((int)sid);
1625      if ( 0 == mysql_query( mysql, sql.c_str() ) ){      if ( 0 == fp_mysql_query( mysql, sql.c_str() ) ){
1626          if ( mysql_affected_rows(mysql) == 1 ){          if ( fp_mysql_affected_rows(mysql) == 1 ){
1627              // ログアウトした              // ログアウトした
1628          }          }
1629          else {          else {
# Line 1564  result_t createSession( const char* sess Line 1659  result_t createSession( const char* sess
1659            
1660      string escSess_id = addSlashes(sess_id);      string escSess_id = addSlashes(sess_id);
1661      sql = "SELECT sess_id from " + dbprefix + "_session where sess_id='" + escSess_id + "'";      sql = "SELECT sess_id from " + dbprefix + "_session where sess_id='" + escSess_id + "'";
1662      if( 0 == mysql_query( mysql, sql.c_str( ) ) ){      if( 0 == fp_mysql_query( mysql, sql.c_str( ) ) ){
1663          MYSQL_RES* result = mysql_store_result( mysql );          MYSQL_RES* result = fp_mysql_store_result( mysql );
1664          if( result ){          if( result ){
1665              MYSQL_ROW row = mysql_fetch_row(result);              MYSQL_ROW row = fp_mysql_fetch_row(result);
1666              if( row ){              if( row ){
1667                  ret = addSession( uid, session );                  ret = addSession( uid, session );
1668              }else{              }else{
1669                  ret = RES_ERROR;                  ret = RES_ERROR;
1670              }              }
1671              mysql_free_result( result );              fp_mysql_free_result( result );
1672          }else {          }else {
1673              ret = RES_DB_QUERY_ERROR;              ret = RES_DB_QUERY_ERROR;
1674          }          }
# Line 1605  result_t getSession( sessionid_t sid, co Line 1700  result_t getSession( sessionid_t sid, co
1700            
1701      sql = "SELECT sid, uid, unix_timestamp(timestamp) from " + dbprefix +      sql = "SELECT sid, uid, unix_timestamp(timestamp) from " + dbprefix +
1702        "_vpaccount_session where sid=" + unsignedIntToString((unsigned int)sid);        "_vpaccount_session where sid=" + unsignedIntToString((unsigned int)sid);
1703      if( 0 == mysql_query( mysql, sql.c_str( ) ) ){      if( 0 == fp_mysql_query( mysql, sql.c_str( ) ) ){
1704          MYSQL_RES* result = mysql_store_result( mysql );          MYSQL_RES* result = fp_mysql_store_result( mysql );
1705          if( result ){          if( result ){
1706              MYSQL_ROW row = mysql_fetch_row(result);              MYSQL_ROW row = fp_mysql_fetch_row(result);
1707              if( row ){              if( row ){
1708                  session_t *p = new session[1];                  session_t *p = new session[1];
1709                  p->setSessionID(sid);                  p->setSessionID(sid);
1710                  p->setUserID(atoi(row[1]));                  p->setUserID(atoi( row[1] != NULL ? row[1] : "" ));
1711                  p->setDate(atoi(row[2]));                  p->setDate(atoi( row[2] != NULL ? row[2] : "" ));
1712                  *ppsession = p;                  *ppsession = p;
1713                  ret = RES_OK;                  ret = RES_OK;
1714              }else{              }else{
1715                  ret = RES_NO_SUCH_SESSION;                  ret = RES_NO_SUCH_SESSION;
1716              }              }
1717              mysql_free_result( result );              fp_mysql_free_result( result );
1718          }else {          }else {
1719              ret = RES_DB_QUERY_ERROR;              ret = RES_DB_QUERY_ERROR;
1720          }          }
# Line 1643  bool isValidSessionID( sessionid_t sid ) Line 1738  bool isValidSessionID( sessionid_t sid )
1738  {  {
1739      if( mysql == NULL ) return false;      if( mysql == NULL ) return false;
1740            
1741        bool ret;
1742      string sql;      string sql;
1743      string sidstr;      string sidstr;
1744      char buf[ 12 ];      char buf[ 12 ];
1745      snprintf( buf, 12, "%d", sid );      snprintf( buf, 12, "%d", sid );
1746            
1747      sql = "SELECT * FROM " + dbprefix + "_vpaccount_session WHERE sid=" + string( buf );      sql = "SELECT * FROM " + dbprefix + "_vpaccount_session WHERE sid=" + string( buf );
1748      if( mysql_query( mysql, sql.c_str( ) ) ){      if( fp_mysql_query( mysql, sql.c_str( ) ) ){
1749          return false;          return false;
1750      }      }
1751      MYSQL_RES* result = mysql_store_result( mysql ) ;      MYSQL_RES* result = fp_mysql_store_result( mysql );
1752      MYSQL_ROW row = mysql_fetch_row(result);      if( result ){
1753      mysql_free_result( result );          MYSQL_ROW row = fp_mysql_fetch_row(result);
1754      if( row ){          if( row ){
1755          return true;              ret = true;
1756      }else{          }else{
1757          return false;              ret = false;
1758            }
1759            fp_mysql_free_result( result );
1760      }      }
1761        return ret;
1762  }  }
1763    
1764  void freeResult( const account_t* ptr ){ delete[] ( account_t* )ptr; }  void freeResult( const account_t* ptr ){ delete[] ( account_t* )ptr; }

Legend:
Removed from v.1.27  
changed lines
  Added in v.1.28

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