GDBMS 1.0
|
00001 #include "maininclude.h" 00002 #include "listi.h" 00003 #include "settings.h" 00004 #include "hash_table.h" 00005 #include "tr_twin_ht.h" 00006 #include "file_semaphore.h" 00007 #include "some_functions.h" 00008 #include "initial_mode_commands.h" 00009 #include "session_mode_commands.h" 00010 #include "transaction_mode_commands.h" 00011 #include "transaction_mode_commands_types.h" 00012 #include "transaction_mode_commands_nodes.h" 00013 #include "transaction_mode_commands_edges.h" 00014 #include "transaction_mode_commands_find.h" 00015 00016 using namespace std; 00017 int initial_mode_commands::Connect(std::string user, std::string pass, ns1__ConnectResponse& _param_1) 00018 { 00019 hash_table conn("users", "admin/users", 4, "id;name;pass;gr_id", "id;name;gr_id", "id"); 00020 char *real_password; 00021 if(!(real_password=conn.FindRecord("name", user.c_str(), "pass"))){ 00022 //nqma takyf potrebitel 00023 _param_1.retvalue=1; 00024 00025 return 0; 00026 00027 00028 } 00029 if(strstr(real_password, pass.c_str())){ 00030 //nqma syvpadenie s parolata 00031 _param_1.retvalue=2; 00032 return 0; 00033 00034 } 00035 //vsi4ko e OK 00036 _param_1.retvalue=0; 00037 delete real_password; 00038 char *buf=conn.FindRecord("name", user.c_str(), "id"); 00039 _param_1.user_USCOREid=strtoint(buf); 00040 delete buf; 00041 return 0; 00042 } 00043 int initial_mode_commands::GetSessionId(int user_USCOREid, ns1__GetSessionIdResponse& _param_2) 00044 { 00045 hash_table ses("sessions", "admin/sessions", "id;user_id;time_started", "id;user_id", "id"); 00046 char *buf; 00047 if(buf=ses.FindRecord("user_id", inttostr(user_USCOREid), "id")){ 00048 //ima sesiq na tozi potrebitel i ne moje da se syzdade 00049 _param_2.retvalue=1; 00050 delete buf; 00051 return 0; 00052 00053 00054 00055 } 00056 //nqma sesiq na tozi potrebitel 00057 _param_2.retvalue=0; 00058 if(settings::is_admin(user_USCOREid)){ 00059 _param_2.options=1; 00060 00061 00062 }else{ 00063 _param_2.options=0; 00064 00065 } 00066 file_semaphore sem("admin/sessions/ssem"); 00067 buf=new char[200]; 00068 char *buf1=new char[100]; 00069 buf[0]=0; 00070 buf1[0]=0; 00071 00072 00073 sem.getResource(); 00074 int id=ses.getMAXID()+1; 00075 buf=strcat(buf, inttostr(id)); 00076 buf=strcat(buf, ";"); 00077 buf=strcat(buf, inttostr(user_USCOREid)); 00078 buf=strcat(buf, ";"); 00079 buf=strcat(buf, current_moment()); 00080 ses.AddRecord("id;user_id;time_started", buf); 00081 sem.freeResource(); 00082 _param_2.session_USCOREid=id; 00083 delete buf; 00084 delete buf1; 00085 return 0; 00086 } 00087 int initial_mode_commands::InitiateTransactionStop(std::string user, std::string pass, ns1__InitiateTransactionStopResponse& _param_30) 00088 { 00089 ns1__ConnectResponse cr1; 00090 if(!initial_mode_commands::Connect(user, pass, cr1)){ 00091 _param_30.user_USCOREid=cr1.user_USCOREid; 00092 if(settings::is_admin(cr1.user_USCOREid)){ 00093 /*tuka se spirat vsi4ki tranzakcii*/ 00094 file_semaphore ssem("admin/transactions/ssem"); 00095 ssem.getResource(); 00096 hash_table trn("transactions", "admin/transactions", "id;user_id;graph_id;time_started", "id;user_id;graph_id", "id"); 00097 int ni=trn.getRealMaxId(); 00098 int i; 00099 for(i=1; i<=ni; i++){ 00100 char *i_str=inttostr(i); 00101 if(i_str){ 00102 char *grphid=trn.FindRecord("id", i_str, "graph_id"); 00103 if(grphid){ 00104 00105 string trfolder; 00106 trfolder+=MAINFOLDER; 00107 trfolder+=grphid; 00108 trfolder+="/"; 00109 trfolder+=i_str; 00110 string cmd; 00111 cmd+="rm -r "; 00112 cmd+=trfolder; 00113 system(cmd.c_str()); 00114 00115 00116 trn.DeleteRecord("id", i_str); 00117 00118 delete grphid; 00119 } 00120 delete i_str; 00121 } 00122 00123 ssem.freeResource(); 00124 } 00125 00126 }else{ 00127 /*potrebitelqt ne e administrator*/ 00128 _param_30.user_USCOREid=0; 00129 _param_30.retvalue=3; 00130 00131 } 00132 00133 00134 00135 }else{ 00136 /*Neuspe6na vryzka s connect*/ 00137 _param_30.user_USCOREid=0; 00138 _param_30.retvalue=2; 00139 00140 } 00141 return 0; 00142 }