~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to libdrizzle/pack.c

  • Committer: Stewart Smith
  • Date: 2008-07-13 06:56:15 UTC
  • mto: (210.1.1 drizzle)
  • mto: This revision was merged to the branch mainline in revision 211.
  • Revision ID: stewart@flamingspork.com-20080713065615-vzok75kgnnviokl9
Move MD5() into a UDF

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
5
 
 *
6
 
 *  This program is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; version 2 of the License.
9
 
 *
10
 
 *  This program is distributed in the hope that it will be useful,
11
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *  GNU General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU General Public License
16
 
 *  along with this program; if not, write to the Free Software
17
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 
 */
19
 
 
20
 
#include "config.h"
21
 
#include <drizzled/korr.h>
22
 
 
23
 
#include <stdint.h>
24
 
 
25
 
#include "pack.h"
26
 
 
27
 
namespace drizzle_protocol
28
 
{
 
1
/* Copyright (C) 2000-2003 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
 
16
#include <my_global.h>
 
17
#include <drizzle.h>
29
18
 
30
19
/* Get the length of next field. Change parameter to point at fieldstart */
31
 
uint32_t drizzleclient_net_field_length(unsigned char **packet)
 
20
ulong STDCALL net_field_length(uchar **packet)
32
21
{
33
 
  register unsigned char *pos= (unsigned char *)*packet;
 
22
  register uchar *pos= (uchar *)*packet;
34
23
  if (*pos < 251)
35
24
  {
36
25
    (*packet)++;
37
 
    return (uint32_t) *pos;
 
26
    return (ulong) *pos;
38
27
  }
39
28
  if (*pos == 251)
40
29
  {
44
33
  if (*pos == 252)
45
34
  {
46
35
    (*packet)+=3;
47
 
    return (uint32_t) uint2korr(pos+1);
 
36
    return (ulong) uint2korr(pos+1);
48
37
  }
49
38
  if (*pos == 253)
50
39
  {
51
40
    (*packet)+=4;
52
 
    return (uint32_t) uint3korr(pos+1);
 
41
    return (ulong) uint3korr(pos+1);
53
42
  }
54
 
  (*packet)+=9;          /* Must be 254 when here */
55
 
  return (uint32_t) uint4korr(pos+1);
 
43
  (*packet)+=9;                                 /* Must be 254 when here */
 
44
  return (ulong) uint4korr(pos+1);
56
45
}
57
46
 
58
 
/* The same as above but returns int64_t */
59
 
uint64_t drizzleclient_drizzleclient_net_field_length_ll(unsigned char **packet)
 
47
/* The same as above but returns longlong */
 
48
my_ulonglong net_field_length_ll(uchar **packet)
60
49
{
61
 
  register unsigned char *pos= *packet;
 
50
  register uchar *pos= *packet;
62
51
  if (*pos < 251)
63
52
  {
64
53
    (*packet)++;
65
 
    return (uint64_t) *pos;
 
54
    return (my_ulonglong) *pos;
66
55
  }
67
56
  if (*pos == 251)
68
57
  {
69
58
    (*packet)++;
70
 
    return (uint64_t) NULL_LENGTH;
 
59
    return (my_ulonglong) NULL_LENGTH;
71
60
  }
72
61
  if (*pos == 252)
73
62
  {
74
63
    (*packet)+=3;
75
 
    return (uint64_t) uint2korr(pos+1);
 
64
    return (my_ulonglong) uint2korr(pos+1);
76
65
  }
77
66
  if (*pos == 253)
78
67
  {
79
68
    (*packet)+=4;
80
 
    return (uint64_t) uint3korr(pos+1);
 
69
    return (my_ulonglong) uint3korr(pos+1);
81
70
  }
82
 
  (*packet)+=9;          /* Must be 254 when here */
 
71
  (*packet)+=9;                                 /* Must be 254 when here */
83
72
#ifdef NO_CLIENT_LONGLONG
84
 
  return (uint64_t) uint4korr(pos+1);
 
73
  return (my_ulonglong) uint4korr(pos+1);
85
74
#else
86
 
  return (uint64_t) uint8korr(pos+1);
 
75
  return (my_ulonglong) uint8korr(pos+1);
87
76
#endif
88
77
}
89
78
 
91
80
  Store an integer with simple packing into a output package
92
81
 
93
82
  SYNOPSIS
94
 
    drizzleclient_net_store_length()
95
 
    pkg      Store the packed integer here
96
 
    length    integers to store
 
83
    net_store_length()
 
84
    pkg                 Store the packed integer here
 
85
    length              integers to store
97
86
 
98
87
  NOTES
99
88
    This is mostly used to store lengths of strings.
104
93
   Position in 'pkg' after the packed length
105
94
*/
106
95
 
107
 
unsigned char *drizzleclient_net_store_length(unsigned char *packet, uint64_t length)
 
96
uchar *net_store_length(uchar *packet, ulonglong length)
108
97
{
109
 
  if (length < (uint64_t) 251LL)
 
98
  if (length < (ulonglong) 251LL)
110
99
  {
111
 
    *packet=(unsigned char) length;
 
100
    *packet=(uchar) length;
112
101
    return packet+1;
113
102
  }
114
103
  /* 251 is reserved for NULL */
115
 
  if (length < (uint64_t) 65536LL)
 
104
  if (length < (ulonglong) 65536LL)
116
105
  {
117
106
    *packet++=252;
118
 
    int2store(packet,(uint32_t) length);
 
107
    int2store(packet,(uint) length);
119
108
    return packet+2;
120
109
  }
121
 
  if (length < (uint64_t) 16777216LL)
 
110
  if (length < (ulonglong) 16777216LL)
122
111
  {
123
112
    *packet++=253;
124
 
    int3store(packet,(uint32_t) length);
 
113
    int3store(packet,(ulong) length);
125
114
    return packet+3;
126
115
  }
127
116
  *packet++=254;
129
118
  return packet+8;
130
119
}
131
120
 
132
 
} /* namespace drizzle_protocol */