~drizzle-trunk/drizzle/development

390.1.4 by Monty Taylor
More copyright header file fixes.
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
 */
1 by brian
clean slate
19
383.1.44 by Monty Taylor
Renamed drizzle.h to libdrizzle.h.
20
#include "libdrizzle.h"
390.1.6 by Monty Taylor
Oh dear god the changes. The changes. I'd tell you what they are, but I'd just be making stuff up. Suffice it to day it's mostly all around splitting files in libdrizzle into different files and removing interdepends. And whatever else I happened to see...
21
#include <stdint.h>
1 by brian
clean slate
22
23
/* Get the length of next field. Change parameter to point at fieldstart */
390.1.6 by Monty Taylor
Oh dear god the changes. The changes. I'd tell you what they are, but I'd just be making stuff up. Suffice it to day it's mostly all around splitting files in libdrizzle into different files and removing interdepends. And whatever else I happened to see...
24
uint32_t net_field_length(unsigned char **packet)
1 by brian
clean slate
25
{
390.1.6 by Monty Taylor
Oh dear god the changes. The changes. I'd tell you what they are, but I'd just be making stuff up. Suffice it to day it's mostly all around splitting files in libdrizzle into different files and removing interdepends. And whatever else I happened to see...
26
  register unsigned char *pos= (unsigned char *)*packet;
1 by brian
clean slate
27
  if (*pos < 251)
28
  {
29
    (*packet)++;
294 by Brian Aker
libdrizzle has ulong removed.
30
    return (uint32_t) *pos;
1 by brian
clean slate
31
  }
32
  if (*pos == 251)
33
  {
34
    (*packet)++;
35
    return NULL_LENGTH;
36
  }
37
  if (*pos == 252)
38
  {
39
    (*packet)+=3;
294 by Brian Aker
libdrizzle has ulong removed.
40
    return (uint32_t) uint2korr(pos+1);
1 by brian
clean slate
41
  }
42
  if (*pos == 253)
43
  {
44
    (*packet)+=4;
294 by Brian Aker
libdrizzle has ulong removed.
45
    return (uint32_t) uint3korr(pos+1);
1 by brian
clean slate
46
  }
206.3.1 by Patrick Galbraith
Most everything working with client rename
47
  (*packet)+=9;          /* Must be 254 when here */
294 by Brian Aker
libdrizzle has ulong removed.
48
  return (uint32_t) uint4korr(pos+1);
1 by brian
clean slate
49
}
50
152 by Brian Aker
longlong replacement
51
/* The same as above but returns int64_t */
390.1.6 by Monty Taylor
Oh dear god the changes. The changes. I'd tell you what they are, but I'd just be making stuff up. Suffice it to day it's mostly all around splitting files in libdrizzle into different files and removing interdepends. And whatever else I happened to see...
52
uint64_t net_field_length_ll(unsigned char **packet)
1 by brian
clean slate
53
{
390.1.6 by Monty Taylor
Oh dear god the changes. The changes. I'd tell you what they are, but I'd just be making stuff up. Suffice it to day it's mostly all around splitting files in libdrizzle into different files and removing interdepends. And whatever else I happened to see...
54
  register unsigned char *pos= *packet;
1 by brian
clean slate
55
  if (*pos < 251)
56
  {
57
    (*packet)++;
155 by Brian Aker
Removing a few "additional" ways of saying uint64_t
58
    return (uint64_t) *pos;
1 by brian
clean slate
59
  }
60
  if (*pos == 251)
61
  {
62
    (*packet)++;
155 by Brian Aker
Removing a few "additional" ways of saying uint64_t
63
    return (uint64_t) NULL_LENGTH;
1 by brian
clean slate
64
  }
65
  if (*pos == 252)
66
  {
67
    (*packet)+=3;
155 by Brian Aker
Removing a few "additional" ways of saying uint64_t
68
    return (uint64_t) uint2korr(pos+1);
1 by brian
clean slate
69
  }
70
  if (*pos == 253)
71
  {
72
    (*packet)+=4;
155 by Brian Aker
Removing a few "additional" ways of saying uint64_t
73
    return (uint64_t) uint3korr(pos+1);
1 by brian
clean slate
74
  }
206.3.1 by Patrick Galbraith
Most everything working with client rename
75
  (*packet)+=9;          /* Must be 254 when here */
1 by brian
clean slate
76
#ifdef NO_CLIENT_LONGLONG
155 by Brian Aker
Removing a few "additional" ways of saying uint64_t
77
  return (uint64_t) uint4korr(pos+1);
1 by brian
clean slate
78
#else
155 by Brian Aker
Removing a few "additional" ways of saying uint64_t
79
  return (uint64_t) uint8korr(pos+1);
1 by brian
clean slate
80
#endif
81
}
82
83
/*
84
  Store an integer with simple packing into a output package
85
86
  SYNOPSIS
87
    net_store_length()
206.3.1 by Patrick Galbraith
Most everything working with client rename
88
    pkg      Store the packed integer here
89
    length    integers to store
1 by brian
clean slate
90
91
  NOTES
92
    This is mostly used to store lengths of strings.
93
    We have to cast the result for the LL() becasue of a bug in Forte CC
94
    compiler.
95
96
  RETURN
97
   Position in 'pkg' after the packed length
98
*/
99
390.1.6 by Monty Taylor
Oh dear god the changes. The changes. I'd tell you what they are, but I'd just be making stuff up. Suffice it to day it's mostly all around splitting files in libdrizzle into different files and removing interdepends. And whatever else I happened to see...
100
unsigned char *net_store_length(unsigned char *packet, uint64_t length)
1 by brian
clean slate
101
{
151 by Brian Aker
Ulonglong to uint64_t
102
  if (length < (uint64_t) 251LL)
1 by brian
clean slate
103
  {
390.1.6 by Monty Taylor
Oh dear god the changes. The changes. I'd tell you what they are, but I'd just be making stuff up. Suffice it to day it's mostly all around splitting files in libdrizzle into different files and removing interdepends. And whatever else I happened to see...
104
    *packet=(unsigned char) length;
1 by brian
clean slate
105
    return packet+1;
106
  }
107
  /* 251 is reserved for NULL */
151 by Brian Aker
Ulonglong to uint64_t
108
  if (length < (uint64_t) 65536LL)
1 by brian
clean slate
109
  {
110
    *packet++=252;
395 by Brian Aker
Fixed uint/ushort issue in libdrizzle
111
    int2store(packet,(uint32_t) length);
1 by brian
clean slate
112
    return packet+2;
113
  }
151 by Brian Aker
Ulonglong to uint64_t
114
  if (length < (uint64_t) 16777216LL)
1 by brian
clean slate
115
  {
116
    *packet++=253;
294 by Brian Aker
libdrizzle has ulong removed.
117
    int3store(packet,(uint32_t) length);
1 by brian
clean slate
118
    return packet+3;
119
  }
120
  *packet++=254;
121
  int8store(packet,length);
122
  return packet+8;
123
}
124