Tadashi Okoshi
slash****@users*****
2005年 6月 30日 (木) 02:00:06 JST
Index: affelio/lib/Affelio/SNS/FriendManager.pm diff -u affelio/lib/Affelio/SNS/FriendManager.pm:1.5 affelio/lib/Affelio/SNS/FriendManager.pm:1.6 --- affelio/lib/Affelio/SNS/FriendManager.pm:1.5 Sun Jun 26 23:20:39 2005 +++ affelio/lib/Affelio/SNS/FriendManager.pm Thu Jun 30 02:00:05 2005 @@ -4,7 +4,7 @@ # http://affelio.jp/ (Japan) # http://affelio.jp/ (USA and other area) # -# $Id: FriendManager.pm,v 1.5 2005/06/26 14:20:39 slash5234 Exp $ +# $Id: FriendManager.pm,v 1.6 2005/06/29 17:00:05 slash5234 Exp $ package Affelio::SNS::FriendManager; { @@ -18,6 +18,7 @@ use Affelio::misc::Debug qw(debug_print); use Affelio::misc::Time; use Affelio::misc::DBroutines qw(db_value_replace); + use Affelio::exception::DBException; ######################################################################## #Constructor @@ -64,17 +65,27 @@ #We have to update his information. # $query = "SELECT * FROM AFuser_CORE_friends WHERE af_id = '$af_id'"; - $sth = $af->{db}->prepare($query) or die $af->{db}->errstr; - $sth->execute() or die $af->{db}->errstr; + eval{ + $sth = $af->{db}->prepare($query); + $sth->execute(); + }; + if($@){ + throw Affelio::exception::DBException($af->{db}->errstr); + } + @row = $sth->fetchrow_array; if(@row && @row!=() ){ Affelio::misc::Debug::debug_print("FM::add_friend: Already my friend!"); $query = "update AFuser_CORE_friends set timestamp = '$timestamp', password = '$password' where af_id = '$af_id'"; - $sth = $af->{db}->prepare($query) or die $af->{db}->errstr; - $sth->execute() or die $af->{db}->errstr; - + eval{ + $sth = $af->{db}->prepare($query); + $sth->execute(); + }; + if($@){ + throw Affelio::exception::DBException($af->{db}->errstr); + } Affelio::misc::Debug::debug_print("FM::add_friend:\tUpdated an existing friend."); Affelio::misc::Debug::debug_print("FM::add_friend: end($row[0])."); ################ @@ -85,8 +96,13 @@ ############################## #Get existing max ID $query = 'SELECT max(uid) FROM AFuser_CORE_friends'; - $sth = $af->{db}->prepare($query) or die $af->{db}->errstr; - $sth->execute() or die $af->{db}->errstr; + eval{ + $sth = $af->{db}->prepare($query); + $sth->execute(); + }; + if($@){ + throw Affelio::exception::DBException($af->{db}->errstr); + } @row = $sth->fetchrow_array; $maxid = $row[0]; if(defined($row[0])){ @@ -101,25 +117,36 @@ #Is $af_id already in F2 table? #If so, we have to move it from F2 table to F1 table. $query = "SELECT * FROM AFuser_CORE_friendsfriends WHERE af_id = '$af_id'"; - $sth = $af->{db}->prepare($query) or die $af->{db}->errstr; - $sth->execute() or die $af->{db}->errstr; + eval{ + $sth = $af->{db}->prepare($query); + $sth->execute(); + }; + if($@){ + throw Affelio::exception::DBException($af->{db}->errstr); + } + @row = $sth->fetchrow_array; if(@row && @row !=() ){ ############################################ #I found the record in F2 table. #Let's move it to the F1 table. - Affelio::misc::Debug::debug_print("FM::add_friend:\t [@row]"); + Affelio::misnc::Debug::debug_print("FM::add_friend:\t [@row]"); Affelio::misc::Debug::debug_print("FM::add_friend:\tHe is my friends' friend."); Affelio::misc::Debug::debug_print("FM::add_friend:\tLet's move him."); - + #Backup data $old_uid_in_f2tbl = $row[0]; $old_f1list_in_f2tbl = $row[4]; #Delete the record in the F2 table. $query = "DELETE FROM AFuser_CORE_friendsfriends WHERE uid = $old_uid_in_f2tbl"; - $sth = $af->{db}->prepare($query) or die $af->{db}->errstr; - $sth->execute() or die $af->{db}->errstr; + eval{ + $sth = $af->{db}->prepare($query); + $sth->execute(); + }; + if($@){ + throw Affelio::exception::DBException($af->{db}->errstr); + } Affelio::misc::Debug::debug_print("FM::add_friend:\tRecord($old_uid_in_f2tbl) in F2 tbl deleted."); #Update all other F1 and F2 entries' "flist" column @@ -148,8 +175,13 @@ ############################## #Insert a new record into my F1 list. $query = "insert into AFuser_CORE_friends(uid, af_id, nickname, timestamp, password, intro, option_pid,lastupdated,f2list) values ($newid, '$af_id', '$nickname', $timestamp, '$password', ' ', -1, 0, '$old_f1list_in_f2tbl')"; - $sth = $af->{db}->prepare($query) or die $af->{db}->errstr; - $sth->execute() or die $af->{db}->errstr; + eval{ + $sth = $af->{db}->prepare($query); + $sth->execute(); + }; + if($@){ + throw Affelio::exception::DBException($af->{db}->errstr); + } Affelio::misc::Debug::debug_print("FM::add_friend:\tInserted a new record."); Affelio::misc::Debug::debug_print("FM::add_friend: end($newid)."); @@ -169,8 +201,14 @@ #Remove entry(uid) from AFuser_CORE_friends my $q1 = "DELETE FROM AFuser_CORE_friends WHERE uid = $uid"; - my $s1 = $af->{db}->prepare($q1) or die $af->{db}->errstr; - $s1->execute() or die $af->{db}->errstr; + my $s1; + eval{ + $s1 = $af->{db}->prepare($q1); + $s1->execute(); + }; + if($@){ + throw Affelio::exception::DBException($af->{db}->errstr); + } undef($q1); undef($s1); Affelio::misc::Debug::debug_print("FM::remove_friend:\t removed entry($uid) from F1 DB"); @@ -261,8 +299,14 @@ #The guy with F2_AF_ID is in the Friend table? $query = "SELECT * FROM AFuser_CORE_friends WHERE af_id = '$f2_af_id'"; - $sth = $af->{db}->prepare($query) or die $af->{db}->errstr; - $sth->execute() or die $af->{db}->errstr; + eval{ + $sth = $af->{db}->prepare($query); + $sth->execute(); + }; + if($@){ + throw Affelio::exception::DBException($af->{db}->errstr); + } + @row_in_f1table = $sth->fetchrow_array; undef($sth); undef($query); @@ -284,8 +328,14 @@ $new_f1_f2list = $f1_f2list . $f2_uid . ","; Affelio::misc::Debug::debug_print("FM::save_F2List: \tnew_f1_f2list=[$new_f1_f2list]"); $query2 = "update AFuser_CORE_friends set f2list = '$new_f1_f2list' where uid = '$f1_uid'"; - $sth2 = $af->{db}->prepare($query2) or die $af->{db}->errstr; - $sth2->execute() or die $af->{db}->errstr; + eval{ + $sth2 = $af->{db}->prepare($query2); + $sth2->execute(); + }; + if($@){ + throw Affelio::exception::DBException($af->{db}->errstr); + } + Affelio::misc::Debug::debug_print("FM::save_F2list: New F1($f1_uid)'s F2list = [$new_f1_f2list]"); #Modify "Friend" table @@ -293,8 +343,13 @@ $new_f2_f1list = $f2_f1list . $f1_uid . ","; Affelio::misc::Debug::debug_print("FM::save_F2List: \tnew_f2_f1list=[$new_f2_f1list]"); $query2 = "update AFuser_CORE_friends set f2list = '$new_f2_f1list' where uid = $f2_uid"; - $sth2 = $af->{db}->prepare($query2) or die $af->{db}->errstr; - $sth2->execute() or die $af->{db}->errstr; + eval{ + $sth2 = $af->{db}->prepare($query2); + $sth2->execute(); + }; + if($@){ + throw Affelio::exception::DBException($af->{db}->errstr); + } Affelio::misc::Debug::debug_print("FM::save_F2list: New F2($f2_uid)'s F1list = [$new_f2_f1list]"); }else{ @@ -303,8 +358,14 @@ #The guy with F2_AF_ID is in the FriendsFriends table? $query2 = "SELECT * FROM AFuser_CORE_friendsfriends WHERE af_id = '$f2_af_id'"; - $sth2 = $af->{db}->prepare($query2) or die $af->{db}->errstr; - $sth2->execute() or die $af->{db}->errstr; + eval{ + $sth2 = $af->{db}->prepare($query2); + $sth2->execute(); + }; + if($@){ + throw Affelio::exception::DBException($af->{db}->errstr); + } + @row_in_f2table = $sth2->fetchrow_array; if(!@row_in_f2table || @row_in_f2table==()){ @@ -318,8 +379,14 @@ ############################## #Get existing min ID $query3 = 'SELECT min(uid) FROM AFuser_CORE_friendsfriends'; - $sth3 = $af->{db}->prepare($query3) or die $af->{db}->errstr; - $sth3->execute() or die $af->{db}->errstr; + eval{ + $sth3 = $af->{db}->prepare($query3); + $sth3->execute(); + }; + if($@){ + throw Affelio::exception::DBException($af->{db}->errstr); + } + @row = $sth3->fetchrow_array; my $minid = $row[0]; if(defined($row[0])){ @@ -332,8 +399,14 @@ #Insert a new record my $tmpnewid = $minid-1; $query3 = "insert into AFuser_CORE_friendsfriends (uid, af_id, nickname, timestamp, f1list) values ('$tmpnewid', '$f2_af_id', '$nickname', $timestamp, ',')"; - $sth3 = $af->{db}->prepare($query3) or die $af->{db}->errstr; - $sth3->execute() or die $af->{db}->errstr; + eval{ + $sth3 = $af->{db}->prepare($query3); + $sth3->execute(); + }; + if($@){ + throw Affelio::exception::DBException($af->{db}->errstr); + } + $f2_uid = $minid - 1; #F2 UID is negative! $f2_f1list = ","; Affelio::misc::Debug::debug_print("FM::save_F2List:\tCreated F2 entry id=$f2_uid"); @@ -353,16 +426,26 @@ $new_f1_f2list = $f1_f2list . $f2_uid . ","; Affelio::misc::Debug::debug_print("FM::save_F2List:\tnew_f1_f2list=[$new_f1_f2list]"); $query2 = "update AFuser_CORE_friends set f2list = '$new_f1_f2list' where uid = $f1_uid"; - $sth2 = $af->{db}->prepare($query2) or die $af->{db}->errstr; - $sth2->execute() or die $af->{db}->errstr; + eval{ + $sth2 = $af->{db}->prepare($query2); + $sth2->execute(); + }; + if($@){ + throw Affelio::exception::DBException($af->{db}->errstr); + } #Modify "FriendsFriends" table #Add $f1_af_id into $f2_uid's F1list $new_f2_f1list = $f2_f1list . $f1_uid . ","; Affelio::misc::Debug::debug_print("FM::save_F2List:\tnew_f2_f1list=[$new_f2_f1list]"); $query2 = "update AFuser_CORE_friendsfriends set f1list = '$new_f2_f1list' where uid = $f2_uid"; - $sth2 = $af->{db}->prepare($query2) or die $af->{db}->errstr; - $sth2->execute() or die $af->{db}->errstr; + eval{ + $sth2 = $af->{db}->prepare($query2); + $sth2->execute(); + }; + if($@){ + throw Affelio::exception::DBException($af->{db}->errstr); + } }#if Affelio::misc::Debug::debug_print("FM::save_F2List: [$method] DONE."); @@ -402,8 +485,14 @@ ############################## #retrieve a friend record from DB my $query = "SELECT af_id, timestamp, nickname FROM AFuser_CORE_friends WHERE timestamp > " . $req_timestamp; - my $sth = $af->{db}->prepare($query) or die $af->{db}->errstr; - $sth->execute() or die $af->{db}->errstr; + my $sth; + eval{ + $sth = $af->{db}->prepare($query); + $sth->execute(); + }; + if($@){ + throw Affelio::exception::DBException($af->{db}->errstr); + } my $retmsg=""; my @row=(); @@ -437,8 +526,14 @@ ############################## #retrieve all friend records from DB my $query = 'SELECT * FROM AFuser_CORE_friends order by uid desc'; - my $sth = $af->{db}->prepare($query) or die $af->{db}->errstr; - $sth->execute() or die $af->{db}->errstr; + my $sth; + eval{ + $sth = $af->{db}->prepare($query); + $sth->execute(); + }; + if($@){ + throw Affelio::exception::DBException($af->{db}->errstr); + } return($sth); } @@ -459,8 +554,14 @@ ############################## #retrieve a friend record from DB my $query = "SELECT * FROM AFuser_CORE_friends WHERE uid = $uid"; - my $sth = $af->{db}->prepare($query) or die $af->{db}->errstr; - $sth->execute() or die $af->{db}->errstr; + my $sth; + eval{ + $sth = $af->{db}->prepare($query); + $sth->execute(); + }; + if($@){ + throw Affelio::exception::DBException($af->{db}->errstr); + } my @row = $sth->fetchrow_array; if(@row==()) {undef @row}; return(@row); @@ -482,8 +583,15 @@ ############################## #retrieve a friend record from DB my $query = "SELECT * FROM AFuser_CORE_friends WHERE af_id = '$af_id'"; - my $sth = $af->{db}->prepare($query) or die $af->{db}->errstr; - $sth->execute() or die $af->{db}->errstr; + my $sth; + eval{ + $sth = $af->{db}->prepare($query); + $sth->execute(); + }; + if($@){ + throw Affelio::exception::DBException($af->{db}->errstr); + } + my @row = $sth->fetchrow_array; if(@row==()) {undef @row}; return(@row); @@ -504,15 +612,16 @@ #retrieve a friend record from DB Affelio::misc::Debug::debug_print("FM::get_attr_by_uid(uid=$uid, attr=$attr)"); my $query = "SELECT $attr FROM AFuser_CORE_friends WHERE uid = '$uid'"; - my $sth = $af->{db}->prepare($query); + my $sth; + eval{ + $sth = $af->{db}->prepare($query); + $sth->execute(); + }; if($@){ - Affelio::misc::Debug::debug_print("FM::add_friend:\t"); - die $af->{db}->errstr; - } + throw Affelio::exception::DBException($af->{db}->errstr); + } - $sth->execute(); my @row = $sth->fetchrow_array; - return($row[0]); } @@ -530,8 +639,14 @@ ############################## #retrieve a friend record from DB my $query = "SELECT $attr FROM AFuser_CORE_friendsfriends WHERE uid = $uid"; - my $sth = $af->{db}->prepare($query) or die $af->{db}->errstr; - $sth->execute() or die $af->{db}->errstr; + my $sth; + eval{ + $sth = $af->{db}->prepare($query); + $sth->execute(); + }; + if($@){ + throw Affelio::exception::DBException($af->{db}->errstr); + } my @row = $sth->fetchrow_array; return($row[0]); } @@ -551,8 +666,14 @@ #retrieve a friend record from DB my $query = "SELECT $attr FROM AFuser_CORE_friends WHERE af_id = $af_id"; - my $sth = $af->{db}->prepare($query) or die $af->{db}->errstr; - $sth->execute or die $af->{db}->errstr; + my $sth; + eval{ + $sth = $af->{db}->prepare($query); + $sth->execute; + }; + if($@){ + throw Affelio::exception::DBException($af->{db}->errstr); + } my @row = $sth->fetchrow_array; my $size = @row; @@ -579,8 +700,15 @@ ############################## #set value into DB my $query = "update AFuser_CORE_friends set $attr = '$value' where uid = $uid"; - my $sth = $af->{db}->prepare($query) or die $af->{db}->errstr; - $sth->execute or die $af->{db}->errstr; + my $sth; + eval{ + $sth = $af->{db}->prepare($query); + $sth->execute; + }; + if($@){ + throw Affelio::exception::DBException($af->{db}->errstr); + } + } Index: affelio/lib/Affelio/SNS/Handshaker_c.pm diff -u affelio/lib/Affelio/SNS/Handshaker_c.pm:1.8 affelio/lib/Affelio/SNS/Handshaker_c.pm:1.9 --- affelio/lib/Affelio/SNS/Handshaker_c.pm:1.8 Tue Jun 28 23:07:46 2005 +++ affelio/lib/Affelio/SNS/Handshaker_c.pm Thu Jun 30 02:00:05 2005 @@ -4,7 +4,7 @@ # http://affelio.jp/ (Japan) # http://affelio.jp/ (USA and other area) # -# $Id: Handshaker_c.pm,v 1.8 2005/06/28 14:07:46 slash5234 Exp $ +# $Id: Handshaker_c.pm,v 1.9 2005/06/29 17:00:05 slash5234 Exp $ package Affelio::SNS::Handshaker_c; { @@ -21,6 +21,7 @@ use Affelio::misc::MyCrypt; use Affelio::misc::Time; use Affelio::exception::Exception; + use Affelio::exception::InvalidInputException; use Affelio::exception::IOException; use Affelio::exception::NetworkException; @@ -69,10 +70,6 @@ </message> <src>$src</src> EOT - debug_print("C::post_Message: =============================\n"); - debug_print($XMLbody); - debug_print("C::post_Message: =============================\n"); - ############################ #Encryption ############################ @@ -104,7 +101,7 @@ throw Affelio::exception::NetworkException($@); } if($result->{flerror} ne "0"){ - throw Affelio::exception::NetworkException($result->{message}); + throw Affelio::exception::NetworkException("XML-RPC Error: " . $result->{message}); } debug_print("post_Message: OK : $result->{message}\n"); @@ -126,7 +123,7 @@ debug_print("get_F2List: $dest_uri $proto_ver $timestamp"); if ($dest_uri !~ /^http/) { - throw Affelio::exception::Exception("Invalid URL."); + throw Affelio::exception::InvalidInputException("dest_url"); } my $result = eval { @@ -177,15 +174,13 @@ debug_print("send_HandShake: size=[" . length($my_mesg)); debug_print("send_HandShake: size=[" . length($MIMed_mesg)); - - debug_print("send_HandShake: [$dest_uri $proto_ver $timestamp $my_domain $my_nickname $my_AFID $my_DH_pub_key_str $my_mesg]"); ################################# #Arg check ################################# if ($dest_uri !~ /^http/) { - throw Affelio::exception::Exception("Invalid URL."); + throw Affelio::exception::InvalidInputException("dest_url"); } ################################# @@ -244,7 +239,7 @@ #Arg check ################################# if ($dest_uri !~ /^http/) { - throw Affelio::exception::Exception("Invalid URL."); + throw Affelio::exception::InvalidInputException("dest_url"); } ################################# Index: affelio/lib/Affelio/SNS/Handshaker_s.pm diff -u affelio/lib/Affelio/SNS/Handshaker_s.pm:1.13 affelio/lib/Affelio/SNS/Handshaker_s.pm:1.14 --- affelio/lib/Affelio/SNS/Handshaker_s.pm:1.13 Tue Jun 28 23:09:27 2005 +++ affelio/lib/Affelio/SNS/Handshaker_s.pm Thu Jun 30 02:00:05 2005 @@ -4,7 +4,7 @@ # http://affelio.jp/ (Japan) # http://affelio.jp/ (USA and other area) # -# $Id: Handshaker_s.pm,v 1.13 2005/06/28 14:09:27 slash5234 Exp $ +# $Id: Handshaker_s.pm,v 1.14 2005/06/29 17:00:05 slash5234 Exp $ use strict; use lib("../../../extlib/"); @@ -15,7 +15,6 @@ use MIME::Base64::Perl; use lib("../../"); use Affelio; -use Affelio::SNS::MailAck; use Affelio::SNS::FriendManager; use Affelio::SNS::Handshaker_c qw(get_F2List); use Affelio::Managing::MessageManager; @@ -57,7 +56,6 @@ my ($proto_ver, $req_timestamp) = @_; my $af = Affelio::SNS::Handshaker_s::Util::af_new(); - $Affelio::SNS::MailAck::AF_DIR = $AF_DIR; $req_timestamp = Affelio::misc::Sanitizer::sanitize_number($req_timestamp); @@ -116,9 +114,6 @@ ################################################## my $rc5 = Crypt::RC5->new($passAB, 12 ); my $plain = $rc5->decrypt($encrypted); - Affelio::misc::Debug::debug_print("server.postMesg: ================"); - Affelio::misc::Debug::debug_print($plain); - Affelio::misc::Debug::debug_print("server.postMesg: ================"); ################################################## #Parse XML @@ -171,7 +166,7 @@ if($src ne $peer_afid){ return { flerror => XMLRPC::Data->type('boolean', 1), - message => "ERR: Invalid Encryption." + message => "ERR:101 Invalid Encryption." }; } @@ -230,7 +225,7 @@ if($proto_ver > 1.1){ return { flerror => XMLRPC::Data->type('boolean', 1), - message => "ERR: UnsupportedProtoVer 1.1" + message => "ERR:102 UnsupportedProtoVer 1.1" }; } @@ -298,7 +293,7 @@ if($proto_ver > 1.1){ return { flerror => XMLRPC::Data->type('boolean', 1), - message => "ERR: UnsupportedProtoVer 1.1" + message => "ERR:102 UnsupportedProtoVer 1.1" }; } @@ -326,7 +321,7 @@ Affelio::misc::Debug::debug_print("server.HandShakeReply: sent-Handshake session NOT Found!\n"); return { flerror => XMLRPC::Data->type('boolean', 1), - message => "Your HandShakeReply cannot be accepted." + message => "ERR:103 HandShakeReply denied." }; }else{ ($dummy1, $dummy2, $dummy3, $dummy4, $my_DH_pri_key_str) = @ret; @@ -387,7 +382,7 @@ ########################################### return { flerror => XMLRPC::Data->type('boolean', 0), - message => "Thanks for your HandShakeReply." + message => "OK: Thanks for your HandShakeReply." }; } Index: affelio/lib/Affelio/SNS/MailAck.pm diff -u affelio/lib/Affelio/SNS/MailAck.pm:1.2 affelio/lib/Affelio/SNS/MailAck.pm:removed --- affelio/lib/Affelio/SNS/MailAck.pm:1.2 Sat Jun 25 21:14:07 2005 +++ affelio/lib/Affelio/SNS/MailAck.pm Thu Jun 30 02:00:06 2005 @@ -1,54 +0,0 @@ -# Affelio: Open social networking software -# Copyright 2004-2005 Fish Grove -# For more information, please refer following web site. -# http://affelio.jp/ (Japan) -# http://affelio.jp/ (USA and other area) -# -# $Id: MailAck.pm,v 1.2 2005/06/25 12:14:07 slash5234 Exp $ - -package Affelio::SNS::MailAck; -{ - use strict; - - use lib("../../../lib"); - use Affelio::misc::Debug qw(debug_print); - use Affelio::SNS::Handshaker_tmpDB; - - use Exporter; - @Affelio::SNS::MailAck::ISA = "Exporter"; - @Affelio::SNS::MailAck::EXPORT = qw (send_mail_ack); - use vars qw( $AF_DIR); - - ######################################################################### - sub send_mail_ack{ - my ($af, $receiver_n_family, $receiver_n_given, - $receiver_email, $sessionid, - $peer_nickname, $peer_URL) = @_; - - ########################################### - #Send message - debug_print("send_mail_ack: start.\n"); - debug_print("send_mail_ack: $receiver_n_family, $receiver_n_given, $receiver_email, $sessionid, $peer_nickname, $peer_URL\n"); - - my $URL_to_click = "$af->{site__web_root}/bin/recv_mail_ack.cgi?id=$sessionid"; - - debug_print("send_mail_ack: session_ID= $sessionid\n"); - debug_print("send_mail_ack: url= $URL_to_click\n"); - debug_print("send_mail_ack: command= $af->{cmd__nkf} -j | $af->{cmd__sendmail} -t\n"); - #Sendmail - open(MAIL, " | $af->{cmd__nkf} -j | $af->{cmd__sendmail} -t "); - print MAIL "To: $receiver_email\n"; - print MAIL "From: <$peer_nickname> $receiver_email\n"; - print MAIL "Subject: [Affelio] Invite from $peer_nickname\n\n"; - print MAIL "Hi $receiver_n_given,\n"; - print MAIL "You've got a handshake request from $peer_nickname.\n"; - print MAIL "Please click following URL if you accept the request.\n"; - print MAIL "\n"; - print MAIL " $URL_to_click\n"; - close(MAIL); - - }#method - -}#package - -1;