author | Michael Krelin <hacker@klever.net> | 2007-07-04 11:23:42 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2007-07-04 11:23:42 (UTC) |
commit | a08aff328d4393031d5ba7d622c2b05705a89d73 (patch) (unidiff) | |
tree | 8ee90d686081c52e7c69b5ce946e9b1a7d690001 /microkde/kdecore/kmdcodec.cpp | |
parent | 11edc920afe4f274c0964436633aa632c8288a40 (diff) | |
download | kdepimpi-p1.zip kdepimpi-p1.tar.gz kdepimpi-p1.tar.bz2 |
initial public commit of qt4 portp1
Diffstat (limited to 'microkde/kdecore/kmdcodec.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | microkde/kdecore/kmdcodec.cpp | 139 |
1 files changed, 69 insertions, 70 deletions
diff --git a/microkde/kdecore/kmdcodec.cpp b/microkde/kdecore/kmdcodec.cpp index bc03569..db11e52 100644 --- a/microkde/kdecore/kmdcodec.cpp +++ b/microkde/kdecore/kmdcodec.cpp | |||
@@ -30,24 +30,26 @@ | |||
30 | The quoted-printable codec as described in RFC 2045, section 6.7. is by | 30 | The quoted-printable codec as described in RFC 2045, section 6.7. is by |
31 | Rik Hemsley (C) 2001. | 31 | Rik Hemsley (C) 2001. |
32 | */ | 32 | */ |
33 | 33 | ||
34 | //US #include <config.h> | 34 | //US #include <config.h> |
35 | 35 | ||
36 | #include <stdio.h> | 36 | #include <stdio.h> |
37 | #include <string.h> | 37 | #include <string.h> |
38 | #include <stdlib.h> | 38 | #include <stdlib.h> |
39 | 39 | ||
40 | #include <kdebug.h> | 40 | #include <kdebug.h> |
41 | #include "kmdcodec.h" | 41 | #include "kmdcodec.h" |
42 | //Added by qt3to4: | ||
43 | #include <Q3CString> | ||
42 | 44 | ||
43 | #define KMD5_S11 7 | 45 | #define KMD5_S11 7 |
44 | #define KMD5_S12 12 | 46 | #define KMD5_S12 12 |
45 | #define KMD5_S13 17 | 47 | #define KMD5_S13 17 |
46 | #define KMD5_S14 22 | 48 | #define KMD5_S14 22 |
47 | #define KMD5_S21 5 | 49 | #define KMD5_S21 5 |
48 | #define KMD5_S22 9 | 50 | #define KMD5_S22 9 |
49 | #define KMD5_S23 14 | 51 | #define KMD5_S23 14 |
50 | #define KMD5_S24 20 | 52 | #define KMD5_S24 20 |
51 | #define KMD5_S31 4 | 53 | #define KMD5_S31 4 |
52 | #define KMD5_S32 11 | 54 | #define KMD5_S32 11 |
53 | #define KMD5_S33 16 | 55 | #define KMD5_S33 16 |
@@ -138,32 +140,32 @@ static int rikFindChar(register const char * _s, const char c) | |||
138 | 140 | ||
139 | while (true) | 141 | while (true) |
140 | { | 142 | { |
141 | if ((0 == *s) || (c == *s)) break; ++s; | 143 | if ((0 == *s) || (c == *s)) break; ++s; |
142 | if ((0 == *s) || (c == *s)) break; ++s; | 144 | if ((0 == *s) || (c == *s)) break; ++s; |
143 | if ((0 == *s) || (c == *s)) break; ++s; | 145 | if ((0 == *s) || (c == *s)) break; ++s; |
144 | if ((0 == *s) || (c == *s)) break; ++s; | 146 | if ((0 == *s) || (c == *s)) break; ++s; |
145 | } | 147 | } |
146 | 148 | ||
147 | return s - _s; | 149 | return s - _s; |
148 | } | 150 | } |
149 | 151 | ||
150 | QCString KCodecs::quotedPrintableEncode(const QByteArray& in, bool useCRLF) | 152 | Q3CString KCodecs::quotedPrintableEncode(const QByteArray& in, bool useCRLF) |
151 | { | 153 | { |
152 | QByteArray out; | 154 | QByteArray out; |
153 | quotedPrintableEncode (in, out, useCRLF); | 155 | quotedPrintableEncode (in, out, useCRLF); |
154 | return QCString (out.data(), out.size()+1); | 156 | return Q3CString (out.data(), out.size()+1); |
155 | } | 157 | } |
156 | 158 | ||
157 | QCString KCodecs::quotedPrintableEncode(const QCString& str, bool useCRLF) | 159 | Q3CString KCodecs::quotedPrintableEncode(const Q3CString& str, bool useCRLF) |
158 | { | 160 | { |
159 | if (str.isEmpty()) | 161 | if (str.isEmpty()) |
160 | return ""; | 162 | return ""; |
161 | 163 | ||
162 | QByteArray in (str.length()); | 164 | QByteArray in (str.length()); |
163 | memcpy (in.data(), str.data(), str.length()); | 165 | memcpy (in.data(), str.data(), str.length()); |
164 | return quotedPrintableEncode(in, useCRLF); | 166 | return quotedPrintableEncode(in, useCRLF); |
165 | } | 167 | } |
166 | 168 | ||
167 | void KCodecs::quotedPrintableEncode(const QByteArray& in, QByteArray& out, bool useCRLF) | 169 | void KCodecs::quotedPrintableEncode(const QByteArray& in, QByteArray& out, bool useCRLF) |
168 | { | 170 | { |
169 | out.resize (0); | 171 | out.resize (0); |
@@ -271,32 +273,32 @@ void KCodecs::quotedPrintableEncode(const QByteArray& in, QByteArray& out, bool | |||
271 | } else { | 273 | } else { |
272 | *cursor++ = '='; | 274 | *cursor++ = '='; |
273 | *cursor++ = '\n'; | 275 | *cursor++ = '\n'; |
274 | } | 276 | } |
275 | 277 | ||
276 | lineLength = 0; | 278 | lineLength = 0; |
277 | } | 279 | } |
278 | } | 280 | } |
279 | 281 | ||
280 | out.truncate(cursor - out.data()); | 282 | out.truncate(cursor - out.data()); |
281 | } | 283 | } |
282 | 284 | ||
283 | QCString KCodecs::quotedPrintableDecode(const QByteArray & in) | 285 | Q3CString KCodecs::quotedPrintableDecode(const QByteArray & in) |
284 | { | 286 | { |
285 | QByteArray out; | 287 | QByteArray out; |
286 | quotedPrintableDecode (in, out); | 288 | quotedPrintableDecode (in, out); |
287 | return QCString (out.data(), out.size()+1); | 289 | return Q3CString (out.data(), out.size()+1); |
288 | } | 290 | } |
289 | 291 | ||
290 | QCString KCodecs::quotedPrintableDecode(const QCString & str) | 292 | Q3CString KCodecs::quotedPrintableDecode(const Q3CString & str) |
291 | { | 293 | { |
292 | if (str.isEmpty()) | 294 | if (str.isEmpty()) |
293 | return ""; | 295 | return ""; |
294 | 296 | ||
295 | QByteArray in (str.length()); | 297 | QByteArray in (str.length()); |
296 | memcpy (in.data(), str.data(), str.length()); | 298 | memcpy (in.data(), str.data(), str.length()); |
297 | return quotedPrintableDecode (in); | 299 | return quotedPrintableDecode (in); |
298 | } | 300 | } |
299 | 301 | ||
300 | void KCodecs::quotedPrintableDecode(const QByteArray& in, QByteArray& out) | 302 | void KCodecs::quotedPrintableDecode(const QByteArray& in, QByteArray& out) |
301 | { | 303 | { |
302 | // clear out the output buffer | 304 | // clear out the output buffer |
@@ -346,39 +348,39 @@ void KCodecs::quotedPrintableDecode(const QByteArray& in, QByteArray& out) | |||
346 | } | 348 | } |
347 | } | 349 | } |
348 | } | 350 | } |
349 | else | 351 | else |
350 | { | 352 | { |
351 | *cursor++ = c; | 353 | *cursor++ = c; |
352 | } | 354 | } |
353 | } | 355 | } |
354 | 356 | ||
355 | out.truncate(cursor - out.data()); | 357 | out.truncate(cursor - out.data()); |
356 | } | 358 | } |
357 | 359 | ||
358 | QCString KCodecs::base64Encode( const QCString& str, bool insertLFs ) | 360 | Q3CString KCodecs::base64Encode( const Q3CString& str, bool insertLFs ) |
359 | { | 361 | { |
360 | if ( str.isEmpty() ) | 362 | if ( str.isEmpty() ) |
361 | return ""; | 363 | return ""; |
362 | 364 | ||
363 | QByteArray in (str.length()); | 365 | QByteArray in (str.length()); |
364 | memcpy( in.data(), str.data(), str.length() ); | 366 | memcpy( in.data(), str.data(), str.length() ); |
365 | return base64Encode( in, insertLFs ); | 367 | return base64Encode( in, insertLFs ); |
366 | } | 368 | } |
367 | 369 | ||
368 | QCString KCodecs::base64Encode( const QByteArray& in, bool insertLFs ) | 370 | Q3CString KCodecs::base64Encode( const QByteArray& in, bool insertLFs ) |
369 | { | 371 | { |
370 | QByteArray out; | 372 | QByteArray out; |
371 | base64Encode( in, out, insertLFs ); | 373 | base64Encode( in, out, insertLFs ); |
372 | return QCString( out.data(), out.size()+1 ); | 374 | return Q3CString( out.data(), out.size()+1 ); |
373 | } | 375 | } |
374 | 376 | ||
375 | void KCodecs::base64Encode( const QByteArray& in, QByteArray& out, | 377 | void KCodecs::base64Encode( const QByteArray& in, QByteArray& out, |
376 | bool insertLFs ) | 378 | bool insertLFs ) |
377 | { | 379 | { |
378 | // clear out the output buffer | 380 | // clear out the output buffer |
379 | out.resize (0); | 381 | out.resize (0); |
380 | if ( in.isEmpty() ) | 382 | if ( in.isEmpty() ) |
381 | return; | 383 | return; |
382 | 384 | ||
383 | unsigned int sidx = 0; | 385 | unsigned int sidx = 0; |
384 | unsigned int didx = 0; | 386 | unsigned int didx = 0; |
@@ -396,78 +398,75 @@ void KCodecs::base64Encode( const QByteArray& in, QByteArray& out, | |||
396 | 398 | ||
397 | int count = 0; | 399 | int count = 0; |
398 | out.resize( out_len ); | 400 | out.resize( out_len ); |
399 | 401 | ||
400 | // 3-byte to 4-byte conversion + 0-63 to ascii printable conversion | 402 | // 3-byte to 4-byte conversion + 0-63 to ascii printable conversion |
401 | if ( len > 1 ) | 403 | if ( len > 1 ) |
402 | { | 404 | { |
403 | while (sidx < len-2) | 405 | while (sidx < len-2) |
404 | { | 406 | { |
405 | if ( insertLFs ) | 407 | if ( insertLFs ) |
406 | { | 408 | { |
407 | if ( count && (count%76) == 0 ) | 409 | if ( count && (count%76) == 0 ) |
408 | out.at(didx++) = '\n'; | 410 | out[didx++] = '\n'; |
409 | count += 4; | 411 | count += 4; |
410 | } | 412 | } |
411 | out.at(didx++) = Base64EncMap[(data[sidx] >> 2) & 077]; | 413 | out[didx++] = Base64EncMap[(data[sidx] >> 2) & 077]; |
412 | out.at(didx++) = Base64EncMap[(data[sidx+1] >> 4) & 017 | | 414 | out[didx++] = Base64EncMap[(data[sidx+1] >> 4) & 017 | |
413 | (data[sidx] << 4) & 077]; | 415 | (data[sidx] << 4) & 077]; |
414 | out.at(didx++) = Base64EncMap[(data[sidx+2] >> 6) & 003 | | 416 | out[didx++] = Base64EncMap[(data[sidx+2] >> 6) & 003 | |
415 | (data[sidx+1] << 2) & 077]; | 417 | (data[sidx+1] << 2) & 077]; |
416 | out.at(didx++) = Base64EncMap[data[sidx+2] & 077]; | 418 | out[didx++] = Base64EncMap[data[sidx+2] & 077]; |
417 | sidx += 3; | 419 | sidx += 3; |
418 | } | 420 | } |
419 | } | 421 | } |
420 | 422 | ||
421 | if (sidx < len) | 423 | if (sidx < len) |
422 | { | 424 | { |
423 | if ( insertLFs && (count > 0) && (count%76) == 0 ) | 425 | if ( insertLFs && (count > 0) && (count%76) == 0 ) |
424 | out.at(didx++) = '\n'; | 426 | out[didx++] = '\n'; |
425 | 427 | ||
426 | out.at(didx++) = Base64EncMap[(data[sidx] >> 2) & 077]; | 428 | out[didx++] = Base64EncMap[(data[sidx] >> 2) & 077]; |
427 | if (sidx < len-1) | 429 | if (sidx < len-1) |
428 | { | 430 | { |
429 | out.at(didx++) = Base64EncMap[(data[sidx+1] >> 4) & 017 | | 431 | out[didx++] = Base64EncMap[(data[sidx+1] >> 4) & 017 | |
430 | (data[sidx] << 4) & 077]; | 432 | (data[sidx] << 4) & 077]; |
431 | out.at(didx++) = Base64EncMap[(data[sidx+1] << 2) & 077]; | 433 | out[didx++] = Base64EncMap[(data[sidx+1] << 2) & 077]; |
432 | } | 434 | } |
433 | else | 435 | else |
434 | { | 436 | { |
435 | out.at(didx++) = Base64EncMap[(data[sidx] << 4) & 077]; | 437 | out[didx++] = Base64EncMap[(data[sidx] << 4) & 077]; |
436 | } | 438 | } |
437 | } | 439 | } |
438 | 440 | ||
439 | // Add padding | 441 | // Add padding |
440 | while (didx < out.size()) | 442 | while (didx < out.size()) |
441 | { | 443 | out[didx++] = '='; |
442 | out.at(didx) = '='; | ||
443 | didx++; | ||
444 | } | ||
445 | } | 444 | } |
446 | 445 | ||
447 | QCString KCodecs::base64Decode( const QCString& str ) | 446 | Q3CString KCodecs::base64Decode( const Q3CString& str ) |
448 | { | 447 | { |
449 | if ( str.isEmpty() ) | 448 | if ( str.isEmpty() ) |
450 | return ""; | 449 | return ""; |
451 | 450 | ||
452 | QByteArray in( str.length() ); | 451 | QByteArray in( str.length() ); |
453 | memcpy( in.data(), str.data(), str.length() ); | 452 | memcpy( in.data(), str.data(), str.length() ); |
454 | return base64Decode( in ); | 453 | return base64Decode( in ); |
455 | } | 454 | } |
456 | 455 | ||
457 | QCString KCodecs::base64Decode( const QByteArray& in ) | 456 | Q3CString KCodecs::base64Decode( const QByteArray& in ) |
458 | { | 457 | { |
459 | QByteArray out; | 458 | QByteArray out; |
460 | base64Decode( in, out ); | 459 | base64Decode( in, out ); |
461 | return QCString( out.data(), out.size()+1 ); | 460 | return Q3CString( out.data(), out.size()+1 ); |
462 | } | 461 | } |
463 | 462 | ||
464 | void KCodecs::base64Decode( const QByteArray& in, QByteArray& out ) | 463 | void KCodecs::base64Decode( const QByteArray& in, QByteArray& out ) |
465 | { | 464 | { |
466 | out.resize(0); | 465 | out.resize(0); |
467 | if ( in.isEmpty() ) | 466 | if ( in.isEmpty() ) |
468 | return; | 467 | return; |
469 | 468 | ||
470 | unsigned int count = 0; | 469 | unsigned int count = 0; |
471 | unsigned int len = in.size(), tail = len; | 470 | unsigned int len = in.size(), tail = len; |
472 | const char* data = in.data(); | 471 | const char* data = in.data(); |
473 | 472 | ||
@@ -496,174 +495,174 @@ void KCodecs::base64Decode( const QByteArray& in, QByteArray& out ) | |||
496 | if ( data[--tail] != '=' ) len = tail; | 495 | if ( data[--tail] != '=' ) len = tail; |
497 | 496 | ||
498 | unsigned int outIdx = 0; | 497 | unsigned int outIdx = 0; |
499 | out.resize( (count=len) ); | 498 | out.resize( (count=len) ); |
500 | for (unsigned int idx = 0; idx < count; idx++) | 499 | for (unsigned int idx = 0; idx < count; idx++) |
501 | { | 500 | { |
502 | // Adhere to RFC 2045 and ignore characters | 501 | // Adhere to RFC 2045 and ignore characters |
503 | // that are not part of the encoding table. | 502 | // that are not part of the encoding table. |
504 | unsigned char ch = data[idx]; | 503 | unsigned char ch = data[idx]; |
505 | if ((ch > 47 && ch < 58) || (ch > 64 && ch < 91) || | 504 | if ((ch > 47 && ch < 58) || (ch > 64 && ch < 91) || |
506 | (ch > 96 && ch < 123) || ch == '+' || ch == '/' || ch == '=') | 505 | (ch > 96 && ch < 123) || ch == '+' || ch == '/' || ch == '=') |
507 | { | 506 | { |
508 | out.at(outIdx++) = Base64DecMap[ch]; | 507 | out[outIdx++] = Base64DecMap[ch]; |
509 | } | 508 | } |
510 | else | 509 | else |
511 | { | 510 | { |
512 | len--; | 511 | len--; |
513 | tail--; | 512 | tail--; |
514 | } | 513 | } |
515 | } | 514 | } |
516 | 515 | ||
517 | // kdDebug() << "Tail size = " << tail << ", Length size = " << len << endl; | 516 | // kdDebug() << "Tail size = " << tail << ", Length size = " << len << endl; |
518 | 517 | ||
519 | // 4-byte to 3-byte conversion | 518 | // 4-byte to 3-byte conversion |
520 | len = (tail>(len/4)) ? tail-(len/4) : 0; | 519 | len = (tail>(len/4)) ? tail-(len/4) : 0; |
521 | unsigned int sidx = 0, didx = 0; | 520 | unsigned int sidx = 0, didx = 0; |
522 | if ( len > 1 ) | 521 | if ( len > 1 ) |
523 | { | 522 | { |
524 | while (didx < len-2) | 523 | while (didx < len-2) |
525 | { | 524 | { |
526 | out.at(didx) = (((out.at(sidx) << 2) & 255) | ((out.at(sidx+1) >> 4) & 003)); | 525 | out[didx] = (((out[sidx] << 2) & 255) | ((out[sidx+1] >> 4) & 003)); |
527 | out.at(didx+1) = (((out.at(sidx+1) << 4) & 255) | ((out.at(sidx+2) >> 2) & 017)); | 526 | out[didx+1] = (((out[sidx+1] << 4) & 255) | ((out[sidx+2] >> 2) & 017)); |
528 | out.at(didx+2) = (((out.at(sidx+2) << 6) & 255) | (out.at(sidx+3) & 077)); | 527 | out[didx+2] = (((out[sidx+2] << 6) & 255) | (out[sidx+3] & 077)); |
529 | sidx += 4; | 528 | sidx += 4; |
530 | didx += 3; | 529 | didx += 3; |
531 | } | 530 | } |
532 | } | 531 | } |
533 | 532 | ||
534 | if (didx < len) | 533 | if (didx < len) |
535 | out.at(didx) = (((out.at(sidx) << 2) & 255) | ((out.at(sidx+1) >> 4) & 003)); | 534 | out[didx] = (((out[sidx] << 2) & 255) | ((out[sidx+1] >> 4) & 003)); |
536 | 535 | ||
537 | if (++didx < len ) | 536 | if (++didx < len ) |
538 | out.at(didx) = (((out.at(sidx+1) << 4) & 255) | ((out.at(sidx+2) >> 2) & 017)); | 537 | out[didx] = (((out[sidx+1] << 4) & 255) | ((out[sidx+2] >> 2) & 017)); |
539 | 538 | ||
540 | // Resize the output buffer | 539 | // Resize the output buffer |
541 | if ( len == 0 || len < out.size() ) | 540 | if ( len == 0 || len < out.size() ) |
542 | out.resize(len); | 541 | out.resize(len); |
543 | } | 542 | } |
544 | 543 | ||
545 | QCString KCodecs::uuencode( const QCString& str ) | 544 | Q3CString KCodecs::uuencode( const Q3CString& str ) |
546 | { | 545 | { |
547 | if ( str.isEmpty() ) | 546 | if ( str.isEmpty() ) |
548 | return ""; | 547 | return ""; |
549 | 548 | ||
550 | QByteArray in; | 549 | QByteArray in; |
551 | in.resize( str.length() ); | 550 | in.resize( str.length() ); |
552 | memcpy( in.data(), str.data(), str.length() ); | 551 | memcpy( in.data(), str.data(), str.length() ); |
553 | return uuencode( in ); | 552 | return uuencode( in ); |
554 | } | 553 | } |
555 | 554 | ||
556 | QCString KCodecs::uuencode( const QByteArray& in ) | 555 | Q3CString KCodecs::uuencode( const QByteArray& in ) |
557 | { | 556 | { |
558 | QByteArray out; | 557 | QByteArray out; |
559 | uuencode( in, out ); | 558 | uuencode( in, out ); |
560 | return QCString( out.data(), out.size()+1 ); | 559 | return Q3CString( out.data(), out.size()+1 ); |
561 | } | 560 | } |
562 | 561 | ||
563 | void KCodecs::uuencode( const QByteArray& in, QByteArray& out ) | 562 | void KCodecs::uuencode( const QByteArray& in, QByteArray& out ) |
564 | { | 563 | { |
565 | out.resize( 0 ); | 564 | out.resize( 0 ); |
566 | if( in.isEmpty() ) | 565 | if( in.isEmpty() ) |
567 | return; | 566 | return; |
568 | 567 | ||
569 | unsigned int sidx = 0; | 568 | unsigned int sidx = 0; |
570 | unsigned int didx = 0; | 569 | unsigned int didx = 0; |
571 | unsigned int line_len = 45; | 570 | unsigned int line_len = 45; |
572 | 571 | ||
573 | const char nl[] = "\n"; | 572 | const char nl[] = "\n"; |
574 | const char* data = in.data(); | 573 | const char* data = in.data(); |
575 | const unsigned int nl_len = strlen(nl); | 574 | const unsigned int nl_len = strlen(nl); |
576 | const unsigned int len = in.size(); | 575 | const unsigned int len = in.size(); |
577 | 576 | ||
578 | out.resize( (len+2)/3*4 + ((len+line_len-1)/line_len)*(nl_len+1) ); | 577 | out.resize( (len+2)/3*4 + ((len+line_len-1)/line_len)*(nl_len+1) ); |
579 | // split into lines, adding line-length and line terminator | 578 | // split into lines, adding line-length and line terminator |
580 | while (sidx+line_len < len) | 579 | while (sidx+line_len < len) |
581 | { | 580 | { |
582 | // line length | 581 | // line length |
583 | out.at(didx++) = UUEncMap[line_len]; | 582 | out[didx++] = UUEncMap[line_len]; |
584 | 583 | ||
585 | // 3-byte to 4-byte conversion + 0-63 to ascii printable conversion | 584 | // 3-byte to 4-byte conversion + 0-63 to ascii printable conversion |
586 | for (unsigned int end = sidx+line_len; sidx < end; sidx += 3) | 585 | for (unsigned int end = sidx+line_len; sidx < end; sidx += 3) |
587 | { | 586 | { |
588 | out.at(didx++) = UUEncMap[(data[sidx] >> 2) & 077]; | 587 | out[didx++] = UUEncMap[(data[sidx] >> 2) & 077]; |
589 | out.at(didx++) = UUEncMap[(data[sidx+1] >> 4) & 017 | | 588 | out[didx++] = UUEncMap[(data[sidx+1] >> 4) & 017 | |
590 | (data[sidx] << 4) & 077]; | 589 | (data[sidx] << 4) & 077]; |
591 | out.at(didx++) = UUEncMap[(data[sidx+2] >> 6) & 003 | | 590 | out[didx++] = UUEncMap[(data[sidx+2] >> 6) & 003 | |
592 | (data[sidx+1] << 2) & 077]; | 591 | (data[sidx+1] << 2) & 077]; |
593 | out.at(didx++) = UUEncMap[data[sidx+2] & 077]; | 592 | out[didx++] = UUEncMap[data[sidx+2] & 077]; |
594 | } | 593 | } |
595 | 594 | ||
596 | // line terminator | 595 | // line terminator |
597 | //for (unsigned int idx=0; idx < nl_len; idx++) | 596 | //for (unsigned int idx=0; idx < nl_len; idx++) |
598 | //out.at(didx++) = nl[idx]; | 597 | //out[didx++] = nl[idx]; |
599 | memcpy(out.data()+didx, nl, nl_len); | 598 | memcpy(out.data()+didx, nl, nl_len); |
600 | didx += nl_len; | 599 | didx += nl_len; |
601 | } | 600 | } |
602 | 601 | ||
603 | // line length | 602 | // line length |
604 | out.at(didx++) = UUEncMap[len-sidx]; | 603 | out[didx++] = UUEncMap[len-sidx]; |
605 | // 3-byte to 4-byte conversion + 0-63 to ascii printable conversion | 604 | // 3-byte to 4-byte conversion + 0-63 to ascii printable conversion |
606 | while (sidx+2 < len) | 605 | while (sidx+2 < len) |
607 | { | 606 | { |
608 | out.at(didx++) = UUEncMap[(data[sidx] >> 2) & 077]; | 607 | out[didx++] = UUEncMap[(data[sidx] >> 2) & 077]; |
609 | out.at(didx++) = UUEncMap[(data[sidx+1] >> 4) & 017 | | 608 | out[didx++] = UUEncMap[(data[sidx+1] >> 4) & 017 | |
610 | (data[sidx] << 4) & 077]; | 609 | (data[sidx] << 4) & 077]; |
611 | out.at(didx++) = UUEncMap[(data[sidx+2] >> 6) & 003 | | 610 | out[didx++] = UUEncMap[(data[sidx+2] >> 6) & 003 | |
612 | (data[sidx+1] << 2) & 077]; | 611 | (data[sidx+1] << 2) & 077]; |
613 | out.at(didx++) = UUEncMap[data[sidx+2] & 077]; | 612 | out[didx++] = UUEncMap[data[sidx+2] & 077]; |
614 | sidx += 3; | 613 | sidx += 3; |
615 | } | 614 | } |
616 | 615 | ||
617 | if (sidx < len-1) | 616 | if (sidx < len-1) |
618 | { | 617 | { |
619 | out.at(didx++) = UUEncMap[(data[sidx] >> 2) & 077]; | 618 | out[didx++] = UUEncMap[(data[sidx] >> 2) & 077]; |
620 | out.at(didx++) = UUEncMap[(data[sidx+1] >> 4) & 017 | | 619 | out[didx++] = UUEncMap[(data[sidx+1] >> 4) & 017 | |
621 | (data[sidx] << 4) & 077]; | 620 | (data[sidx] << 4) & 077]; |
622 | out.at(didx++) = UUEncMap[(data[sidx+1] << 2) & 077]; | 621 | out[didx++] = UUEncMap[(data[sidx+1] << 2) & 077]; |
623 | out.at(didx++) = UUEncMap[0]; | 622 | out[didx++] = UUEncMap[0]; |
624 | } | 623 | } |
625 | else if (sidx < len) | 624 | else if (sidx < len) |
626 | { | 625 | { |
627 | out.at(didx++) = UUEncMap[(data[sidx] >> 2) & 077]; | 626 | out[didx++] = UUEncMap[(data[sidx] >> 2) & 077]; |
628 | out.at(didx++) = UUEncMap[(data[sidx] << 4) & 077]; | 627 | out[didx++] = UUEncMap[(data[sidx] << 4) & 077]; |
629 | out.at(didx++) = UUEncMap[0]; | 628 | out[didx++] = UUEncMap[0]; |
630 | out.at(didx++) = UUEncMap[0]; | 629 | out[didx++] = UUEncMap[0]; |
631 | } | 630 | } |
632 | 631 | ||
633 | // line terminator | 632 | // line terminator |
634 | memcpy(out.data()+didx, nl, nl_len); | 633 | memcpy(out.data()+didx, nl, nl_len); |
635 | didx += nl_len; | 634 | didx += nl_len; |
636 | 635 | ||
637 | // sanity check | 636 | // sanity check |
638 | if ( didx != out.size() ) | 637 | if ( didx != out.size() ) |
639 | out.resize( 0 ); | 638 | out.resize( 0 ); |
640 | } | 639 | } |
641 | 640 | ||
642 | QCString KCodecs::uudecode( const QCString& str ) | 641 | Q3CString KCodecs::uudecode( const Q3CString& str ) |
643 | { | 642 | { |
644 | if ( str.isEmpty() ) | 643 | if ( str.isEmpty() ) |
645 | return ""; | 644 | return ""; |
646 | 645 | ||
647 | QByteArray in; | 646 | QByteArray in; |
648 | in.resize( str.length() ); | 647 | in.resize( str.length() ); |
649 | memcpy( in.data(), str.data(), str.length() ); | 648 | memcpy( in.data(), str.data(), str.length() ); |
650 | return uudecode( in ); | 649 | return uudecode( in ); |
651 | } | 650 | } |
652 | 651 | ||
653 | QCString KCodecs::uudecode( const QByteArray& in ) | 652 | Q3CString KCodecs::uudecode( const QByteArray& in ) |
654 | { | 653 | { |
655 | QByteArray out; | 654 | QByteArray out; |
656 | uudecode( in, out ); | 655 | uudecode( in, out ); |
657 | return QCString( out.data(), out.size()+1 ); | 656 | return Q3CString( out.data(), out.size()+1 ); |
658 | } | 657 | } |
659 | 658 | ||
660 | void KCodecs::uudecode( const QByteArray& in, QByteArray& out ) | 659 | void KCodecs::uudecode( const QByteArray& in, QByteArray& out ) |
661 | { | 660 | { |
662 | out.resize( 0 ); | 661 | out.resize( 0 ); |
663 | if( in.isEmpty() ) | 662 | if( in.isEmpty() ) |
664 | return; | 663 | return; |
665 | 664 | ||
666 | unsigned int sidx = 0; | 665 | unsigned int sidx = 0; |
667 | unsigned int didx = 0; | 666 | unsigned int didx = 0; |
668 | unsigned int len = in.size(); | 667 | unsigned int len = in.size(); |
669 | unsigned int line_len, end; | 668 | unsigned int line_len, end; |
@@ -696,43 +695,43 @@ void KCodecs::uudecode( const QByteArray& in, QByteArray& out ) | |||
696 | // get line length (in number of encoded octets) | 695 | // get line length (in number of encoded octets) |
697 | line_len = UUDecMap[ (unsigned char) data[sidx++]]; | 696 | line_len = UUDecMap[ (unsigned char) data[sidx++]]; |
698 | // ascii printable to 0-63 and 4-byte to 3-byte conversion | 697 | // ascii printable to 0-63 and 4-byte to 3-byte conversion |
699 | end = didx+line_len; | 698 | end = didx+line_len; |
700 | char A, B, C, D; | 699 | char A, B, C, D; |
701 | if (end > 2) { | 700 | if (end > 2) { |
702 | while (didx < end-2) | 701 | while (didx < end-2) |
703 | { | 702 | { |
704 | A = UUDecMap[(unsigned char) data[sidx]]; | 703 | A = UUDecMap[(unsigned char) data[sidx]]; |
705 | B = UUDecMap[(unsigned char) data[sidx+1]]; | 704 | B = UUDecMap[(unsigned char) data[sidx+1]]; |
706 | C = UUDecMap[(unsigned char) data[sidx+2]]; | 705 | C = UUDecMap[(unsigned char) data[sidx+2]]; |
707 | D = UUDecMap[(unsigned char) data[sidx+3]]; | 706 | D = UUDecMap[(unsigned char) data[sidx+3]]; |
708 | out.at(didx++) = ( ((A << 2) & 255) | ((B >> 4) & 003) ); | 707 | out[didx++] = ( ((A << 2) & 255) | ((B >> 4) & 003) ); |
709 | out.at(didx++) = ( ((B << 4) & 255) | ((C >> 2) & 017) ); | 708 | out[didx++] = ( ((B << 4) & 255) | ((C >> 2) & 017) ); |
710 | out.at(didx++) = ( ((C << 6) & 255) | (D & 077) ); | 709 | out[didx++] = ( ((C << 6) & 255) | (D & 077) ); |
711 | sidx += 4; | 710 | sidx += 4; |
712 | } | 711 | } |
713 | } | 712 | } |
714 | 713 | ||
715 | if (didx < end) | 714 | if (didx < end) |
716 | { | 715 | { |
717 | A = UUDecMap[(unsigned char) data[sidx]]; | 716 | A = UUDecMap[(unsigned char) data[sidx]]; |
718 | B = UUDecMap[(unsigned char) data[sidx+1]]; | 717 | B = UUDecMap[(unsigned char) data[sidx+1]]; |
719 | out.at(didx++) = ( ((A << 2) & 255) | ((B >> 4) & 003) ); | 718 | out[didx++] = ( ((A << 2) & 255) | ((B >> 4) & 003) ); |
720 | } | 719 | } |
721 | 720 | ||
722 | if (didx < end) | 721 | if (didx < end) |
723 | { | 722 | { |
724 | B = UUDecMap[(unsigned char) data[sidx+1]]; | 723 | B = UUDecMap[(unsigned char) data[sidx+1]]; |
725 | C = UUDecMap[(unsigned char) data[sidx+2]]; | 724 | C = UUDecMap[(unsigned char) data[sidx+2]]; |
726 | out.at(didx++) = ( ((B << 4) & 255) | ((C >> 2) & 017) ); | 725 | out[didx++] = ( ((B << 4) & 255) | ((C >> 2) & 017) ); |
727 | } | 726 | } |
728 | 727 | ||
729 | // skip padding | 728 | // skip padding |
730 | while (sidx < len && data[sidx] != '\n' && data[sidx] != '\r') | 729 | while (sidx < len && data[sidx] != '\n' && data[sidx] != '\r') |
731 | sidx++; | 730 | sidx++; |
732 | 731 | ||
733 | // skip end of line | 732 | // skip end of line |
734 | while (sidx < len && (data[sidx] == '\n' || data[sidx] == '\r')) | 733 | while (sidx < len && (data[sidx] == '\n' || data[sidx] == '\r')) |
735 | sidx++; | 734 | sidx++; |
736 | 735 | ||
737 | // skip the "END" separator when present. | 736 | // skip the "END" separator when present. |
738 | if ( hasLF && QString( data+sidx).left(3).lower() == "end" ) | 737 | if ( hasLF && QString( data+sidx).left(3).lower() == "end" ) |
@@ -752,36 +751,36 @@ KMD5::KMD5() | |||
752 | KMD5::KMD5(const char *in, int len) | 751 | KMD5::KMD5(const char *in, int len) |
753 | { | 752 | { |
754 | init(); | 753 | init(); |
755 | update(in, len); | 754 | update(in, len); |
756 | } | 755 | } |
757 | 756 | ||
758 | KMD5::KMD5(const QByteArray& in) | 757 | KMD5::KMD5(const QByteArray& in) |
759 | { | 758 | { |
760 | init(); | 759 | init(); |
761 | update( in ); | 760 | update( in ); |
762 | } | 761 | } |
763 | 762 | ||
764 | KMD5::KMD5(const QCString& in) | 763 | KMD5::KMD5(const Q3CString& in) |
765 | { | 764 | { |
766 | init(); | 765 | init(); |
767 | update( in ); | 766 | update( in ); |
768 | } | 767 | } |
769 | 768 | ||
770 | void KMD5::update(const QByteArray& in) | 769 | void KMD5::update(const QByteArray& in) |
771 | { | 770 | { |
772 | update(in.data(), int(in.size())); | 771 | update(in.data(), int(in.size())); |
773 | } | 772 | } |
774 | 773 | ||
775 | void KMD5::update(const QCString& in) | 774 | void KMD5::update(const Q3CString& in) |
776 | { | 775 | { |
777 | update(in.data(), int(in.length())); | 776 | update(in.data(), int(in.length())); |
778 | } | 777 | } |
779 | 778 | ||
780 | void KMD5::update(const unsigned char* in, int len) | 779 | void KMD5::update(const unsigned char* in, int len) |
781 | { | 780 | { |
782 | if (len < 0) | 781 | if (len < 0) |
783 | len = qstrlen(reinterpret_cast<const char*>(in)); | 782 | len = qstrlen(reinterpret_cast<const char*>(in)); |
784 | 783 | ||
785 | if (!len) | 784 | if (!len) |
786 | return; | 785 | return; |
787 | 786 | ||
@@ -864,67 +863,67 @@ void KMD5::finalize () | |||
864 | memset ( (void *)m_buffer, 0, sizeof(*m_buffer)); | 863 | memset ( (void *)m_buffer, 0, sizeof(*m_buffer)); |
865 | 864 | ||
866 | m_finalized = true; | 865 | m_finalized = true; |
867 | } | 866 | } |
868 | 867 | ||
869 | 868 | ||
870 | bool KMD5::verify( const KMD5::Digest& digest) | 869 | bool KMD5::verify( const KMD5::Digest& digest) |
871 | { | 870 | { |
872 | finalize(); | 871 | finalize(); |
873 | return (0 == memcmp(rawDigest(), digest, sizeof(KMD5::Digest))); | 872 | return (0 == memcmp(rawDigest(), digest, sizeof(KMD5::Digest))); |
874 | } | 873 | } |
875 | 874 | ||
876 | bool KMD5::verify( const QCString& hexdigest) | 875 | bool KMD5::verify( const Q3CString& hexdigest) |
877 | { | 876 | { |
878 | finalize(); | 877 | finalize(); |
879 | return (0 == strcmp(hexDigest().data(), hexdigest)); | 878 | return (0 == strcmp(hexDigest().data(), hexdigest)); |
880 | } | 879 | } |
881 | 880 | ||
882 | const KMD5::Digest& KMD5::rawDigest() | 881 | const KMD5::Digest& KMD5::rawDigest() |
883 | { | 882 | { |
884 | finalize(); | 883 | finalize(); |
885 | return m_digest; | 884 | return m_digest; |
886 | } | 885 | } |
887 | 886 | ||
888 | void KMD5::rawDigest( KMD5::Digest& bin ) | 887 | void KMD5::rawDigest( KMD5::Digest& bin ) |
889 | { | 888 | { |
890 | finalize(); | 889 | finalize(); |
891 | memcpy( bin, m_digest, 16 ); | 890 | memcpy( bin, m_digest, 16 ); |
892 | } | 891 | } |
893 | 892 | ||
894 | 893 | ||
895 | QCString KMD5::hexDigest() | 894 | Q3CString KMD5::hexDigest() |
896 | { | 895 | { |
897 | QCString s(33); | 896 | Q3CString s(33); |
898 | 897 | ||
899 | finalize(); | 898 | finalize(); |
900 | sprintf(s.data(), "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", | 899 | sprintf(s.data(), "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", |
901 | m_digest[0], m_digest[1], m_digest[2], m_digest[3], m_digest[4], m_digest[5], | 900 | m_digest[0], m_digest[1], m_digest[2], m_digest[3], m_digest[4], m_digest[5], |
902 | m_digest[6], m_digest[7], m_digest[8], m_digest[9], m_digest[10], m_digest[11], | 901 | m_digest[6], m_digest[7], m_digest[8], m_digest[9], m_digest[10], m_digest[11], |
903 | m_digest[12], m_digest[13], m_digest[14], m_digest[15]); | 902 | m_digest[12], m_digest[13], m_digest[14], m_digest[15]); |
904 | 903 | ||
905 | return s; | 904 | return s; |
906 | } | 905 | } |
907 | 906 | ||
908 | void KMD5::hexDigest(QCString& s) | 907 | void KMD5::hexDigest(Q3CString& s) |
909 | { | 908 | { |
910 | finalize(); | 909 | finalize(); |
911 | s.resize(33); | 910 | s.resize(33); |
912 | sprintf(s.data(), "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", | 911 | sprintf(s.data(), "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", |
913 | m_digest[0], m_digest[1], m_digest[2], m_digest[3], m_digest[4], m_digest[5], | 912 | m_digest[0], m_digest[1], m_digest[2], m_digest[3], m_digest[4], m_digest[5], |
914 | m_digest[6], m_digest[7], m_digest[8], m_digest[9], m_digest[10], m_digest[11], | 913 | m_digest[6], m_digest[7], m_digest[8], m_digest[9], m_digest[10], m_digest[11], |
915 | m_digest[12], m_digest[13], m_digest[14], m_digest[15]); | 914 | m_digest[12], m_digest[13], m_digest[14], m_digest[15]); |
916 | } | 915 | } |
917 | 916 | ||
918 | QCString KMD5::base64Digest() | 917 | Q3CString KMD5::base64Digest() |
919 | { | 918 | { |
920 | QByteArray ba(16); | 919 | QByteArray ba(16); |
921 | 920 | ||
922 | finalize(); | 921 | finalize(); |
923 | memcpy(ba.data(), m_digest, 16); | 922 | memcpy(ba.data(), m_digest, 16); |
924 | return KCodecs::base64Encode(ba); | 923 | return KCodecs::base64Encode(ba); |
925 | } | 924 | } |
926 | 925 | ||
927 | 926 | ||
928 | void KMD5::init() | 927 | void KMD5::init() |
929 | { | 928 | { |
930 | d = 0; | 929 | d = 0; |
@@ -947,25 +946,25 @@ void KMD5::reset() | |||
947 | memset ( m_digest, 0, sizeof(*m_digest)); | 946 | memset ( m_digest, 0, sizeof(*m_digest)); |
948 | } | 947 | } |
949 | 948 | ||
950 | void KMD5::transform( const unsigned char block[64] ) | 949 | void KMD5::transform( const unsigned char block[64] ) |
951 | { | 950 | { |
952 | 951 | ||
953 | Q_UINT32 a = m_state[0], b = m_state[1], c = m_state[2], d = m_state[3], x[16]; | 952 | Q_UINT32 a = m_state[0], b = m_state[1], c = m_state[2], d = m_state[3], x[16]; |
954 | 953 | ||
955 | decode (x, block, 64); | 954 | decode (x, block, 64); |
956 | //memcpy( x, block, 64 ); | 955 | //memcpy( x, block, 64 ); |
957 | 956 | ||
958 | //US Q_ASSERT(!m_finalized); // not just a user error, since the method is private | 957 | //US Q_ASSERT(!m_finalized); // not just a user error, since the method is private |
959 | ASSERT(!m_finalized); // not just a user error, since the method is private | 958 | Q_ASSERT(!m_finalized); // not just a user error, since the method is private |
960 | 959 | ||
961 | /* Round 1 */ | 960 | /* Round 1 */ |
962 | FF (a, b, c, d, x[ 0], KMD5_S11, 0xd76aa478); /* 1 */ | 961 | FF (a, b, c, d, x[ 0], KMD5_S11, 0xd76aa478); /* 1 */ |
963 | FF (d, a, b, c, x[ 1], KMD5_S12, 0xe8c7b756); /* 2 */ | 962 | FF (d, a, b, c, x[ 1], KMD5_S12, 0xe8c7b756); /* 2 */ |
964 | FF (c, d, a, b, x[ 2], KMD5_S13, 0x242070db); /* 3 */ | 963 | FF (c, d, a, b, x[ 2], KMD5_S13, 0x242070db); /* 3 */ |
965 | FF (b, c, d, a, x[ 3], KMD5_S14, 0xc1bdceee); /* 4 */ | 964 | FF (b, c, d, a, x[ 3], KMD5_S14, 0xc1bdceee); /* 4 */ |
966 | FF (a, b, c, d, x[ 4], KMD5_S11, 0xf57c0faf); /* 5 */ | 965 | FF (a, b, c, d, x[ 4], KMD5_S11, 0xf57c0faf); /* 5 */ |
967 | FF (d, a, b, c, x[ 5], KMD5_S12, 0x4787c62a); /* 6 */ | 966 | FF (d, a, b, c, x[ 5], KMD5_S12, 0x4787c62a); /* 6 */ |
968 | FF (c, d, a, b, x[ 6], KMD5_S13, 0xa8304613); /* 7 */ | 967 | FF (c, d, a, b, x[ 6], KMD5_S13, 0xa8304613); /* 7 */ |
969 | FF (b, c, d, a, x[ 7], KMD5_S14, 0xfd469501); /* 8 */ | 968 | FF (b, c, d, a, x[ 7], KMD5_S14, 0xfd469501); /* 8 */ |
970 | FF (a, b, c, d, x[ 8], KMD5_S11, 0x698098d8); /* 9 */ | 969 | FF (a, b, c, d, x[ 8], KMD5_S11, 0x698098d8); /* 9 */ |
971 | FF (d, a, b, c, x[ 9], KMD5_S12, 0x8b44f7af); /* 10 */ | 970 | FF (d, a, b, c, x[ 9], KMD5_S12, 0x8b44f7af); /* 10 */ |