Experimental HTTPClient with proxy support

Committer:
igorsk
Date:
Wed Jun 29 16:01:58 2011 +0000
Revision:
0:b56b6a05cad4

        

Who changed what in which revision?

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