aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/MySQL/MySQLAuthenticationData.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Data/MySQL/MySQLAuthenticationData.cs')
-rw-r--r--OpenSim/Data/MySQL/MySQLAuthenticationData.cs165
1 files changed, 82 insertions, 83 deletions
diff --git a/OpenSim/Data/MySQL/MySQLAuthenticationData.cs b/OpenSim/Data/MySQL/MySQLAuthenticationData.cs
index 664ce84..7627497 100644
--- a/OpenSim/Data/MySQL/MySQLAuthenticationData.cs
+++ b/OpenSim/Data/MySQL/MySQLAuthenticationData.cs
@@ -70,30 +70,34 @@ namespace OpenSim.Data.MySQL
70 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) 70 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
71 { 71 {
72 dbcon.Open(); 72 dbcon.Open();
73 MySqlCommand cmd = new MySqlCommand("select * from `" + m_Realm + "` where UUID = ?principalID", dbcon);
74 cmd.Parameters.AddWithValue("?principalID", principalID.ToString());
75
76 IDataReader result = cmd.ExecuteReader();
77 73
78 if (result.Read()) 74 using (MySqlCommand cmd
75 = new MySqlCommand("select * from `" + m_Realm + "` where UUID = ?principalID", dbcon))
79 { 76 {
80 ret.PrincipalID = principalID; 77 cmd.Parameters.AddWithValue("?principalID", principalID.ToString());
81
82 CheckColumnNames(result);
83 78
84 foreach (string s in m_ColumnNames) 79 IDataReader result = cmd.ExecuteReader();
80
81 if (result.Read())
85 { 82 {
86 if (s == "UUID") 83 ret.PrincipalID = principalID;
87 continue; 84
88 85 CheckColumnNames(result);
89 ret.Data[s] = result[s].ToString(); 86
87 foreach (string s in m_ColumnNames)
88 {
89 if (s == "UUID")
90 continue;
91
92 ret.Data[s] = result[s].ToString();
93 }
94
95 return ret;
96 }
97 else
98 {
99 return null;
90 } 100 }
91
92 return ret;
93 }
94 else
95 {
96 return null;
97 } 101 }
98 } 102 }
99 } 103 }
@@ -119,57 +123,53 @@ namespace OpenSim.Data.MySQL
119 123
120 string[] fields = new List<string>(data.Data.Keys).ToArray(); 124 string[] fields = new List<string>(data.Data.Keys).ToArray();
121 125
122 MySqlCommand cmd = new MySqlCommand(); 126 using (MySqlCommand cmd = new MySqlCommand())
123
124 string update = "update `"+m_Realm+"` set ";
125 bool first = true;
126 foreach (string field in fields)
127 { 127 {
128 if (!first) 128 string update = "update `"+m_Realm+"` set ";
129 update += ", "; 129 bool first = true;
130 update += "`" + field + "` = ?"+field; 130 foreach (string field in fields)
131 131 {
132 first = false; 132 if (!first)
133 133 update += ", ";
134 cmd.Parameters.AddWithValue("?"+field, data.Data[field]); 134 update += "`" + field + "` = ?"+field;
135 } 135
136 136 first = false;
137 update += " where UUID = ?principalID"; 137
138 138 cmd.Parameters.AddWithValue("?"+field, data.Data[field]);
139 cmd.CommandText = update; 139 }
140 cmd.Parameters.AddWithValue("?principalID", data.PrincipalID.ToString()); 140
141 141 update += " where UUID = ?principalID";
142 if (ExecuteNonQuery(cmd) < 1) 142
143 { 143 cmd.CommandText = update;
144 string insert = "insert into `" + m_Realm + "` (`UUID`, `" + 144 cmd.Parameters.AddWithValue("?principalID", data.PrincipalID.ToString());
145 String.Join("`, `", fields) + 145
146 "`) values (?principalID, ?" + String.Join(", ?", fields) + ")";
147
148 cmd.CommandText = insert;
149
150 if (ExecuteNonQuery(cmd) < 1) 146 if (ExecuteNonQuery(cmd) < 1)
151 { 147 {
152 cmd.Dispose(); 148 string insert = "insert into `" + m_Realm + "` (`UUID`, `" +
153 return false; 149 String.Join("`, `", fields) +
150 "`) values (?principalID, ?" + String.Join(", ?", fields) + ")";
151
152 cmd.CommandText = insert;
153
154 if (ExecuteNonQuery(cmd) < 1)
155 return false;
154 } 156 }
155 } 157 }
156 158
157 cmd.Dispose();
158
159 return true; 159 return true;
160 } 160 }
161 161
162 public bool SetDataItem(UUID principalID, string item, string value) 162 public bool SetDataItem(UUID principalID, string item, string value)
163 { 163 {
164 MySqlCommand cmd = new MySqlCommand("update `" + m_Realm + 164 using (MySqlCommand cmd
165 "` set `" + item + "` = ?" + item + " where UUID = ?UUID"); 165 = new MySqlCommand("update `" + m_Realm + "` set `" + item + "` = ?" + item + " where UUID = ?UUID"))
166 166 {
167 167 cmd.Parameters.AddWithValue("?"+item, value);
168 cmd.Parameters.AddWithValue("?"+item, value); 168 cmd.Parameters.AddWithValue("?UUID", principalID.ToString());
169 cmd.Parameters.AddWithValue("?UUID", principalID.ToString()); 169
170 170 if (ExecuteNonQuery(cmd) > 0)
171 if (ExecuteNonQuery(cmd) > 0) 171 return true;
172 return true; 172 }
173 173
174 return false; 174 return false;
175 } 175 }
@@ -179,18 +179,18 @@ namespace OpenSim.Data.MySQL
179 if (System.Environment.TickCount - m_LastExpire > 30000) 179 if (System.Environment.TickCount - m_LastExpire > 30000)
180 DoExpire(); 180 DoExpire();
181 181
182 MySqlCommand cmd = new MySqlCommand("insert into tokens (UUID, token, validity) values (?principalID, ?token, date_add(now(), interval ?lifetime minute))"); 182 using (MySqlCommand cmd
183 cmd.Parameters.AddWithValue("?principalID", principalID.ToString()); 183 = new MySqlCommand(
184 cmd.Parameters.AddWithValue("?token", token); 184 "insert into tokens (UUID, token, validity) values (?principalID, ?token, date_add(now(), interval ?lifetime minute))"))
185 cmd.Parameters.AddWithValue("?lifetime", lifetime.ToString());
186
187 if (ExecuteNonQuery(cmd) > 0)
188 { 185 {
189 cmd.Dispose(); 186 cmd.Parameters.AddWithValue("?principalID", principalID.ToString());
190 return true; 187 cmd.Parameters.AddWithValue("?token", token);
188 cmd.Parameters.AddWithValue("?lifetime", lifetime.ToString());
189
190 if (ExecuteNonQuery(cmd) > 0)
191 return true;
191 } 192 }
192 193
193 cmd.Dispose();
194 return false; 194 return false;
195 } 195 }
196 196
@@ -199,30 +199,29 @@ namespace OpenSim.Data.MySQL
199 if (System.Environment.TickCount - m_LastExpire > 30000) 199 if (System.Environment.TickCount - m_LastExpire > 30000)
200 DoExpire(); 200 DoExpire();
201 201
202 MySqlCommand cmd = new MySqlCommand("update tokens set validity = date_add(now(), interval ?lifetime minute) where UUID = ?principalID and token = ?token and validity > now()"); 202 using (MySqlCommand cmd
203 cmd.Parameters.AddWithValue("?principalID", principalID.ToString()); 203 = new MySqlCommand(
204 cmd.Parameters.AddWithValue("?token", token); 204 "update tokens set validity = date_add(now(), interval ?lifetime minute) where UUID = ?principalID and token = ?token and validity > now()"))
205 cmd.Parameters.AddWithValue("?lifetime", lifetime.ToString());
206
207 if (ExecuteNonQuery(cmd) > 0)
208 { 205 {
209 cmd.Dispose(); 206 cmd.Parameters.AddWithValue("?principalID", principalID.ToString());
210 return true; 207 cmd.Parameters.AddWithValue("?token", token);
211 } 208 cmd.Parameters.AddWithValue("?lifetime", lifetime.ToString());
212 209
213 cmd.Dispose(); 210 if (ExecuteNonQuery(cmd) > 0)
211 return true;
212 }
214 213
215 return false; 214 return false;
216 } 215 }
217 216
218 private void DoExpire() 217 private void DoExpire()
219 { 218 {
220 MySqlCommand cmd = new MySqlCommand("delete from tokens where validity < now()"); 219 using (MySqlCommand cmd = new MySqlCommand("delete from tokens where validity < now()"))
221 ExecuteNonQuery(cmd); 220 {
222 221 ExecuteNonQuery(cmd);
223 cmd.Dispose(); 222 }
224 223
225 m_LastExpire = System.Environment.TickCount; 224 m_LastExpire = System.Environment.TickCount;
226 } 225 }
227 } 226 }
228} 227} \ No newline at end of file