Modified version of NetServices. Fixes an issue where connections failed should the HTTP response status line be received in a packet on its own prior to any further headers. Changes are made to the HTTPClient.cpp file's readHeaders method.

Committer:
andrewbonney
Date:
Fri Apr 08 14:39:41 2011 +0000
Revision:
0:ec559500a63f

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
andrewbonney 0:ec559500a63f 1 /* Copyright (C) 2007 MySQL AB & Michael Widenius
andrewbonney 0:ec559500a63f 2
andrewbonney 0:ec559500a63f 3 This program is free software; you can redistribute it and/or modify
andrewbonney 0:ec559500a63f 4 it under the terms of the GNU General Public License as published by
andrewbonney 0:ec559500a63f 5 the Free Software Foundation; version 2 of the License.
andrewbonney 0:ec559500a63f 6
andrewbonney 0:ec559500a63f 7 This program is distributed in the hope that it will be useful,
andrewbonney 0:ec559500a63f 8 but WITHOUT ANY WARRANTY; without even the implied warranty of
andrewbonney 0:ec559500a63f 9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
andrewbonney 0:ec559500a63f 10 GNU General Public License for more details.
andrewbonney 0:ec559500a63f 11
andrewbonney 0:ec559500a63f 12 You should have received a copy of the GNU General Public License
andrewbonney 0:ec559500a63f 13 along with this program; if not, write to the Free Software
andrewbonney 0:ec559500a63f 14 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
andrewbonney 0:ec559500a63f 15
andrewbonney 0:ec559500a63f 16 #define SCRAMBLE_LENGTH_323 8
andrewbonney 0:ec559500a63f 17
andrewbonney 0:ec559500a63f 18 #include <string.h>
andrewbonney 0:ec559500a63f 19 #include <math.h>
andrewbonney 0:ec559500a63f 20
andrewbonney 0:ec559500a63f 21 typedef unsigned int uint;
andrewbonney 0:ec559500a63f 22 typedef unsigned long ulong;
andrewbonney 0:ec559500a63f 23 typedef unsigned char uchar;
andrewbonney 0:ec559500a63f 24
andrewbonney 0:ec559500a63f 25 struct my_rnd_struct {
andrewbonney 0:ec559500a63f 26 unsigned long seed1,seed2,max_value;
andrewbonney 0:ec559500a63f 27 double max_value_dbl;
andrewbonney 0:ec559500a63f 28 };
andrewbonney 0:ec559500a63f 29
andrewbonney 0:ec559500a63f 30 static void my_rnd_init(struct my_rnd_struct *rand_st, ulong seed1, ulong seed2);
andrewbonney 0:ec559500a63f 31 static double my_rnd(struct my_rnd_struct *rand_st);
andrewbonney 0:ec559500a63f 32 static void hash_password(ulong *result, const char *password, uint password_len);
andrewbonney 0:ec559500a63f 33
andrewbonney 0:ec559500a63f 34 /*
andrewbonney 0:ec559500a63f 35 Initialize random generator
andrewbonney 0:ec559500a63f 36
andrewbonney 0:ec559500a63f 37 NOTES
andrewbonney 0:ec559500a63f 38 MySQL's password checks depends on this, so don't do any changes
andrewbonney 0:ec559500a63f 39 that changes the random numbers that are generated!
andrewbonney 0:ec559500a63f 40 */
andrewbonney 0:ec559500a63f 41
andrewbonney 0:ec559500a63f 42 static void my_rnd_init(struct my_rnd_struct *rand_st, ulong seed1, ulong seed2)
andrewbonney 0:ec559500a63f 43 {
andrewbonney 0:ec559500a63f 44 rand_st->max_value= 0x3FFFFFFFL;
andrewbonney 0:ec559500a63f 45 rand_st->max_value_dbl=(double) rand_st->max_value;
andrewbonney 0:ec559500a63f 46 rand_st->seed1=seed1%rand_st->max_value ;
andrewbonney 0:ec559500a63f 47 rand_st->seed2=seed2%rand_st->max_value;
andrewbonney 0:ec559500a63f 48 }
andrewbonney 0:ec559500a63f 49
andrewbonney 0:ec559500a63f 50 /*
andrewbonney 0:ec559500a63f 51 Generate random number.
andrewbonney 0:ec559500a63f 52
andrewbonney 0:ec559500a63f 53 SYNOPSIS
andrewbonney 0:ec559500a63f 54 my_rnd()
andrewbonney 0:ec559500a63f 55 rand_st INOUT Structure used for number generation
andrewbonney 0:ec559500a63f 56
andrewbonney 0:ec559500a63f 57 RETURN VALUE
andrewbonney 0:ec559500a63f 58 generated pseudo random number
andrewbonney 0:ec559500a63f 59 */
andrewbonney 0:ec559500a63f 60
andrewbonney 0:ec559500a63f 61 static double my_rnd(struct my_rnd_struct *rand_st)
andrewbonney 0:ec559500a63f 62 {
andrewbonney 0:ec559500a63f 63 rand_st->seed1=(rand_st->seed1*3+rand_st->seed2) % rand_st->max_value;
andrewbonney 0:ec559500a63f 64 rand_st->seed2=(rand_st->seed1+rand_st->seed2+33) % rand_st->max_value;
andrewbonney 0:ec559500a63f 65 return (((double) rand_st->seed1)/rand_st->max_value_dbl);
andrewbonney 0:ec559500a63f 66 }
andrewbonney 0:ec559500a63f 67
andrewbonney 0:ec559500a63f 68 /*
andrewbonney 0:ec559500a63f 69 Generate binary hash from raw text string
andrewbonney 0:ec559500a63f 70 Used for Pre-4.1 password handling
andrewbonney 0:ec559500a63f 71 SYNOPSIS
andrewbonney 0:ec559500a63f 72 hash_password()
andrewbonney 0:ec559500a63f 73 result OUT store hash in this location
andrewbonney 0:ec559500a63f 74 password IN plain text password to build hash
andrewbonney 0:ec559500a63f 75 password_len IN password length (password may be not null-terminated)
andrewbonney 0:ec559500a63f 76 */
andrewbonney 0:ec559500a63f 77
andrewbonney 0:ec559500a63f 78 static void hash_password(ulong *result, const char *password, uint password_len)
andrewbonney 0:ec559500a63f 79 {
andrewbonney 0:ec559500a63f 80 register ulong nr=1345345333L, add=7, nr2=0x12345671L;
andrewbonney 0:ec559500a63f 81 ulong tmp;
andrewbonney 0:ec559500a63f 82 const char *password_end= password + password_len;
andrewbonney 0:ec559500a63f 83 for (; password < password_end; password++)
andrewbonney 0:ec559500a63f 84 {
andrewbonney 0:ec559500a63f 85 if (*password == ' ' || *password == '\t')
andrewbonney 0:ec559500a63f 86 continue; /* skip space in password */
andrewbonney 0:ec559500a63f 87 tmp= (ulong) (uchar) *password;
andrewbonney 0:ec559500a63f 88 nr^= (((nr & 63)+add)*tmp)+ (nr << 8);
andrewbonney 0:ec559500a63f 89 nr2+=(nr2 << 8) ^ nr;
andrewbonney 0:ec559500a63f 90 add+=tmp;
andrewbonney 0:ec559500a63f 91 }
andrewbonney 0:ec559500a63f 92 result[0]=nr & (((ulong) 1L << 31) -1L); /* Don't use sign bit (str2int) */;
andrewbonney 0:ec559500a63f 93 result[1]=nr2 & (((ulong) 1L << 31) -1L);
andrewbonney 0:ec559500a63f 94 }
andrewbonney 0:ec559500a63f 95
andrewbonney 0:ec559500a63f 96
andrewbonney 0:ec559500a63f 97
andrewbonney 0:ec559500a63f 98 /*
andrewbonney 0:ec559500a63f 99 Scramble string with password.
andrewbonney 0:ec559500a63f 100 Used in pre 4.1 authentication phase.
andrewbonney 0:ec559500a63f 101 SYNOPSIS
andrewbonney 0:ec559500a63f 102 scramble_323()
andrewbonney 0:ec559500a63f 103 to OUT Store scrambled message here. Buffer must be at least
andrewbonney 0:ec559500a63f 104 SCRAMBLE_LENGTH_323+1 bytes long
andrewbonney 0:ec559500a63f 105 message IN Message to scramble. Message must be at least
andrewbonney 0:ec559500a63f 106 SRAMBLE_LENGTH_323 bytes long.
andrewbonney 0:ec559500a63f 107 password IN Password to use while scrambling
andrewbonney 0:ec559500a63f 108 */
andrewbonney 0:ec559500a63f 109
andrewbonney 0:ec559500a63f 110 void scramble_323(char *to, const char *message, const char *password)
andrewbonney 0:ec559500a63f 111 {
andrewbonney 0:ec559500a63f 112 struct my_rnd_struct rand_st;
andrewbonney 0:ec559500a63f 113 ulong hash_pass[2], hash_message[2];
andrewbonney 0:ec559500a63f 114
andrewbonney 0:ec559500a63f 115 if (password && password[0])
andrewbonney 0:ec559500a63f 116 {
andrewbonney 0:ec559500a63f 117 char extra, *to_start=to;
andrewbonney 0:ec559500a63f 118 const char *message_end= message + SCRAMBLE_LENGTH_323;
andrewbonney 0:ec559500a63f 119 hash_password(hash_pass,password, (uint) strlen(password));
andrewbonney 0:ec559500a63f 120 hash_password(hash_message, message, SCRAMBLE_LENGTH_323);
andrewbonney 0:ec559500a63f 121 my_rnd_init(&rand_st,hash_pass[0] ^ hash_message[0],
andrewbonney 0:ec559500a63f 122 hash_pass[1] ^ hash_message[1]);
andrewbonney 0:ec559500a63f 123 for (; message < message_end; message++)
andrewbonney 0:ec559500a63f 124 *to++= (char) (floor(my_rnd(&rand_st)*31)+64);
andrewbonney 0:ec559500a63f 125 extra=(char) (floor(my_rnd(&rand_st)*31));
andrewbonney 0:ec559500a63f 126 while (to_start != to)
andrewbonney 0:ec559500a63f 127 *(to_start++)^=extra;
andrewbonney 0:ec559500a63f 128 }
andrewbonney 0:ec559500a63f 129 *to= 0;
andrewbonney 0:ec559500a63f 130 }
andrewbonney 0:ec559500a63f 131