aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llcommon/lluuid.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--linden/indra/llcommon/lluuid.cpp (renamed from linden/indra/llmath/lluuid.cpp)110
1 files changed, 55 insertions, 55 deletions
diff --git a/linden/indra/llmath/lluuid.cpp b/linden/indra/llcommon/lluuid.cpp
index d835cbc..7e4eb50 100644
--- a/linden/indra/llmath/lluuid.cpp
+++ b/linden/indra/llcommon/lluuid.cpp
@@ -149,9 +149,9 @@ U32 janky_fast_random_seeded_bytes(U32 seed, U32 val)
149#endif 149#endif
150 150
151// Common to all UUID implementations 151// Common to all UUID implementations
152void LLUUID::toString(char *out) const 152void LLUUID::toString(std::string& out) const
153{ 153{
154 sprintf(out, 154 out = llformat(
155 "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", 155 "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
156 (U8)(mData[0]), 156 (U8)(mData[0]),
157 (U8)(mData[1]), 157 (U8)(mData[1]),
@@ -171,6 +171,23 @@ void LLUUID::toString(char *out) const
171 (U8)(mData[15])); 171 (U8)(mData[15]));
172} 172}
173 173
174// *TODO: deprecate
175void LLUUID::toString(char *out) const
176{
177 std::string buffer;
178 toString(buffer);
179 strcpy(out,buffer.c_str()); /* Flawfinder: ignore */
180}
181
182void LLUUID::toCompressedString(std::string& out) const
183{
184 char bytes[UUID_BYTES+1];
185 memcpy(bytes, mData, UUID_BYTES); /* Flawfinder: ignore */
186 bytes[UUID_BYTES] = '\0';
187 out.assign(bytes, UUID_BYTES);
188}
189
190// *TODO: deprecate
174void LLUUID::toCompressedString(char *out) const 191void LLUUID::toCompressedString(char *out) const
175{ 192{
176 memcpy(out, mData, UUID_BYTES); /* Flawfinder: ignore */ 193 memcpy(out, mData, UUID_BYTES); /* Flawfinder: ignore */
@@ -184,38 +201,32 @@ std::string LLUUID::getString() const
184 201
185std::string LLUUID::asString() const 202std::string LLUUID::asString() const
186{ 203{
187 char str[UUID_STR_SIZE]; /* Flawfinder: ignore */ 204 std::string str;
188 toString(str); 205 toString(str);
189 return std::string(str); 206 return str;
190} 207}
191 208
192BOOL LLUUID::set(const std::string& in_string, BOOL emit) 209BOOL LLUUID::set(const char* in_string, BOOL emit)
193{ 210{
194 return set(in_string.c_str(), emit); 211 return set(ll_safe_string(in_string));
195} 212}
196 213
197BOOL LLUUID::set(const char *in_string, BOOL emit) 214BOOL LLUUID::set(const std::string& in_string, BOOL emit)
198{ 215{
199 BOOL broken_format = FALSE; 216 BOOL broken_format = FALSE;
200 if (!in_string)
201 {
202 llerrs << "No string pointer in LLUUID::set!" << llendl;
203 setNull();
204 return FALSE;
205 }
206 217
207 // empty strings should make NULL uuid 218 // empty strings should make NULL uuid
208 if (!in_string[0]) 219 if (in_string.empty())
209 { 220 {
210 setNull(); 221 setNull();
211 return TRUE; 222 return TRUE;
212 } 223 }
213 224
214 if (strlen(in_string) != (UUID_STR_LENGTH - 1)) /* Flawfinder: ignore */ 225 if (in_string.length() != (UUID_STR_LENGTH - 1)) /* Flawfinder: ignore */
215 { 226 {
216 // I'm a moron. First implementation didn't have the right UUID format. 227 // I'm a moron. First implementation didn't have the right UUID format.
217 // Shouldn't see any of these any more 228 // Shouldn't see any of these any more
218 if (strlen(in_string) == (UUID_STR_LENGTH - 2)) /* Flawfinder: ignore */ 229 if (in_string.length() == (UUID_STR_LENGTH - 2)) /* Flawfinder: ignore */
219 { 230 {
220 if(emit) 231 if(emit)
221 { 232 {
@@ -251,17 +262,17 @@ BOOL LLUUID::set(const char *in_string, BOOL emit)
251 262
252 mData[i] = 0; 263 mData[i] = 0;
253 264
254 if ((*(in_string + cur_pos) >= '0') && (*(in_string+cur_pos) <= '9')) 265 if ((in_string[cur_pos] >= '0') && (in_string[cur_pos] <= '9'))
255 { 266 {
256 mData[i] += (U8)(*(in_string + cur_pos) - '0'); 267 mData[i] += (U8)(in_string[cur_pos] - '0');
257 } 268 }
258 else if ((*(in_string + cur_pos) >= 'a') && (*(in_string+cur_pos) <='f')) 269 else if ((in_string[cur_pos] >= 'a') && (in_string[cur_pos] <='f'))
259 { 270 {
260 mData[i] += (U8)(10 + *(in_string + cur_pos) - 'a'); 271 mData[i] += (U8)(10 + in_string[cur_pos] - 'a');
261 } 272 }
262 else if ((*(in_string + cur_pos) >= 'A') && (*(in_string+cur_pos) <='F')) 273 else if ((in_string[cur_pos] >= 'A') && (in_string[cur_pos] <='F'))
263 { 274 {
264 mData[i] += (U8)(10 + *(in_string + cur_pos) - 'A'); 275 mData[i] += (U8)(10 + in_string[cur_pos] - 'A');
265 } 276 }
266 else 277 else
267 { 278 {
@@ -276,17 +287,17 @@ BOOL LLUUID::set(const char *in_string, BOOL emit)
276 mData[i] = mData[i] << 4; 287 mData[i] = mData[i] << 4;
277 cur_pos++; 288 cur_pos++;
278 289
279 if ((*(in_string + cur_pos) >= '0') && (*(in_string+cur_pos) <= '9')) 290 if ((in_string[cur_pos] >= '0') && (in_string[cur_pos] <= '9'))
280 { 291 {
281 mData[i] += (U8)(*(in_string + cur_pos) - '0'); 292 mData[i] += (U8)(in_string[cur_pos] - '0');
282 } 293 }
283 else if ((*(in_string + cur_pos) >= 'a') && (*(in_string+cur_pos) <='f')) 294 else if ((in_string[cur_pos] >= 'a') && (in_string[cur_pos] <='f'))
284 { 295 {
285 mData[i] += (U8)(10 + *(in_string + cur_pos) - 'a'); 296 mData[i] += (U8)(10 + in_string[cur_pos] - 'a');
286 } 297 }
287 else if ((*(in_string + cur_pos) >= 'A') && (*(in_string+cur_pos) <='F')) 298 else if ((in_string[cur_pos] >= 'A') && (in_string[cur_pos] <='F'))
288 { 299 {
289 mData[i] += (U8)(10 + *(in_string + cur_pos) - 'A'); 300 mData[i] += (U8)(10 + in_string[cur_pos] - 'A');
290 } 301 }
291 else 302 else
292 { 303 {
@@ -305,20 +316,11 @@ BOOL LLUUID::set(const char *in_string, BOOL emit)
305 316
306BOOL LLUUID::validate(const std::string& in_string) 317BOOL LLUUID::validate(const std::string& in_string)
307{ 318{
308 return validate(in_string.c_str());
309}
310
311BOOL LLUUID::validate(const char *in_string)
312{
313 BOOL broken_format = FALSE; 319 BOOL broken_format = FALSE;
314 if (!in_string) 320 if (in_string.length() != (UUID_STR_LENGTH - 1)) /* Flawfinder: ignore */
315 {
316 return FALSE;
317 }
318 if (strlen(in_string) != (UUID_STR_LENGTH - 1)) /* Flawfinder: ignore */
319 { 321 {
320 // I'm a moron. First implementation didn't have the right UUID format. 322 // I'm a moron. First implementation didn't have the right UUID format.
321 if (strlen(in_string) == (UUID_STR_LENGTH - 2)) /* Flawfinder: ignore */ 323 if (in_string.length() == (UUID_STR_LENGTH - 2)) /* Flawfinder: ignore */
322 { 324 {
323 broken_format = TRUE; 325 broken_format = TRUE;
324 } 326 }
@@ -329,8 +331,7 @@ BOOL LLUUID::validate(const char *in_string)
329 } 331 }
330 332
331 U8 cur_pos = 0; 333 U8 cur_pos = 0;
332 U32 i; 334 for (U32 i = 0; i < 16; i++)
333 for (i = 0; i < 16; i++)
334 { 335 {
335 if ((i == 4) || (i == 6) || (i == 8) || (i == 10)) 336 if ((i == 4) || (i == 6) || (i == 8) || (i == 10))
336 { 337 {
@@ -342,13 +343,13 @@ BOOL LLUUID::validate(const char *in_string)
342 } 343 }
343 } 344 }
344 345
345 if ((*(in_string + cur_pos) >= '0') && (*(in_string+cur_pos) <= '9')) 346 if ((in_string[cur_pos] >= '0') && (in_string[cur_pos] <= '9'))
346 { 347 {
347 } 348 }
348 else if ((*(in_string + cur_pos) >= 'a') && (*(in_string+cur_pos) <='f')) 349 else if ((in_string[cur_pos] >= 'a') && (in_string[cur_pos] <='f'))
349 { 350 {
350 } 351 }
351 else if ((*(in_string + cur_pos) >= 'A') && (*(in_string+cur_pos) <='F')) 352 else if ((in_string[cur_pos] >= 'A') && (in_string[cur_pos] <='F'))
352 { 353 {
353 } 354 }
354 else 355 else
@@ -358,13 +359,13 @@ BOOL LLUUID::validate(const char *in_string)
358 359
359 cur_pos++; 360 cur_pos++;
360 361
361 if ((*(in_string + cur_pos) >= '0') && (*(in_string+cur_pos) <= '9')) 362 if ((in_string[cur_pos] >= '0') && (in_string[cur_pos] <= '9'))
362 { 363 {
363 } 364 }
364 else if ((*(in_string + cur_pos) >= 'a') && (*(in_string+cur_pos) <='f')) 365 else if ((in_string[cur_pos] >= 'a') && (in_string[cur_pos] <='f'))
365 { 366 {
366 } 367 }
367 else if ((*(in_string + cur_pos) >= 'A') && (*(in_string+cur_pos) <='F')) 368 else if ((in_string[cur_pos] >= 'A') && (in_string[cur_pos] <='F'))
368 { 369 {
369 } 370 }
370 else 371 else
@@ -412,8 +413,7 @@ LLUUID LLUUID::combine(const LLUUID &other) const
412 413
413std::ostream& operator<<(std::ostream& s, const LLUUID &uuid) 414std::ostream& operator<<(std::ostream& s, const LLUUID &uuid)
414{ 415{
415 char uuid_str[UUID_STR_LENGTH]; 416 std::string uuid_str;
416
417 uuid.toString(uuid_str); 417 uuid.toString(uuid_str);
418 s << uuid_str; 418 s << uuid_str;
419 return s; 419 return s;
@@ -428,7 +428,7 @@ std::istream& operator>>(std::istream &s, LLUUID &uuid)
428 s >> uuid_str[i]; 428 s >> uuid_str[i];
429 } 429 }
430 uuid_str[i] = '\0'; 430 uuid_str[i] = '\0';
431 uuid.set(uuid_str); 431 uuid.set(std::string(uuid_str));
432 return s; 432 return s;
433} 433}
434 434
@@ -867,7 +867,7 @@ void LLUUID::generate()
867 time_last = timestamp; 867 time_last = timestamp;
868} 868}
869 869
870void LLUUID::generate(std::string hash_string) 870void LLUUID::generate(const std::string& hash_string)
871{ 871{
872 LLMD5 md5_uuid((U8*)hash_string.c_str()); 872 LLMD5 md5_uuid((U8*)hash_string.c_str());
873 md5_uuid.raw_digest(mData); 873 md5_uuid.raw_digest(mData);
@@ -891,15 +891,15 @@ U32 LLUUID::getRandomSeed()
891 return(*(U32 *)seed); 891 return(*(U32 *)seed);
892} 892}
893 893
894BOOL LLUUID::parseUUID(const char* buf, LLUUID* value) 894BOOL LLUUID::parseUUID(const std::string& buf, LLUUID* value)
895{ 895{
896 if( buf == NULL || buf[0] == '\0' || value == NULL) 896 if( buf.empty() || value == NULL)
897 { 897 {
898 return FALSE; 898 return FALSE;
899 } 899 }
900 900
901 LLString temp( buf ); 901 std::string temp( buf );
902 LLString::trim(temp); 902 LLStringUtil::trim(temp);
903 if( LLUUID::validate( temp ) ) 903 if( LLUUID::validate( temp ) )
904 { 904 {
905 value->set( temp ); 905 value->set( temp );