bottleneck testcase based on rubbos
[bottlenecks.git] / rubbos / app / tomcat-connectors-1.2.32-src / native / common / jk_msg_buff.h
1 /*
2  *  Licensed to the Apache Software Foundation (ASF) under one or more
3  *  contributor license agreements.  See the NOTICE file distributed with
4  *  this work for additional information regarding copyright ownership.
5  *  The ASF licenses this file to You under the Apache License, Version 2.0
6  *  (the "License"); you may not use this file except in compliance with
7  *  the License.  You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  */
17
18 /***************************************************************************
19  * Description: Data marshaling. XDR like                                  *
20  * Author:      Costin <costin@costin.dnt.ro>                              *
21  * Author:      Gal Shachor <shachor@il.ibm.com>                           *
22  * Version:     $Revision: 530674 $                                           *
23  ***************************************************************************/
24
25 #ifndef JK_MSG_BUF_H
26 #define JK_MSG_BUF_H
27
28
29 #ifdef __cplusplus
30 extern "C"
31 {
32 #endif                          /* __cplusplus */
33
34 #define DEF_BUFFER_SZ (8 * 1024)
35
36 /* XXX replace all return values with error codes */
37 #define ERR_BAD_PACKET -5
38
39 /*
40 RPC details:
41
42   - one parameter  - use a structure for more. The method
43     is encoded as part of the request
44   - one or no result
45   -
46
47
48
49  */
50
51 typedef struct jk_msg_buf_t jk_msg_buf_t;
52 struct jk_msg_buf_t
53 {
54     jk_pool_t *pool;
55     unsigned char *buf;
56     int pos;
57     int len;
58     int maxlen;
59 };
60
61
62 /* -------------------- Setup routines -------------------- */
63
64 /** Allocate a buffer.
65  */
66 jk_msg_buf_t *jk_b_new(jk_pool_t *p);
67
68 /** Set up a buffer with an existing buffer
69  */
70 int jk_b_set_buffer(jk_msg_buf_t *msg, unsigned char *data, int buffSize);
71
72 /*
73  * Set up a buffer with a new buffer of buffSize
74  */
75 int jk_b_set_buffer_size(jk_msg_buf_t *msg, int buffSize);
76
77 /*
78  * Finalize the buffer before sending - set length fields, etc
79  */
80 void jk_b_end(jk_msg_buf_t *msg, int protoh);
81
82 /*
83  * Recycle the buffer - z for a new invocation
84  */
85 void jk_b_reset(jk_msg_buf_t *msg);
86
87 /* -------------------- Real encoding -------------------- */
88
89 int jk_b_append_byte(jk_msg_buf_t *msg, unsigned char val);
90
91 int jk_b_append_bytes(jk_msg_buf_t *msg,
92                       const unsigned char *param, int len);
93
94 int jk_b_append_int(jk_msg_buf_t *msg, unsigned short val);
95
96 int jk_b_append_long(jk_msg_buf_t *msg, unsigned long val);
97
98 int jk_b_append_string(jk_msg_buf_t *msg, const char *param);
99
100 #if defined(AS400) && !defined(AS400_UTF8)
101 int jk_b_append_asciistring(jk_msg_buf_t *msg, const char *param);
102 #endif
103
104 int jk_b_append_bytes(jk_msg_buf_t *msg,
105                       const unsigned char *param, int len);
106
107 /* -------------------- Decoding -------------------- */
108
109 /** Get a byte from the current position
110  */
111 unsigned char jk_b_get_byte(jk_msg_buf_t *msg);
112
113 /** Get an int from the current position
114  */
115 unsigned short jk_b_get_int(jk_msg_buf_t *msg);
116
117 /** Get a long from the current position
118  */
119 unsigned long jk_b_get_long(jk_msg_buf_t *msg);
120
121 /** Get a String from the current position
122  */
123 unsigned char *jk_b_get_string(jk_msg_buf_t *msg);
124
125 /** Get Bytes from the current position
126  */
127 int jk_b_get_bytes(jk_msg_buf_t *msg, unsigned char *buf, int len);
128
129 /** Get a byte from an arbitrary position
130  */
131 unsigned char jk_b_pget_byte(jk_msg_buf_t *msg, int pos);
132
133 /** Get an int from an arbitrary position
134  */
135 unsigned short jk_b_pget_int(jk_msg_buf_t *msg, int pos);
136
137 /** Get a long from an arbitrary position
138  */
139 unsigned long jk_b_pget_long(jk_msg_buf_t *msg, int pos);
140
141 /* --------------------- Help ------------------------ */
142 void jk_dump_buff(jk_logger_t *l,
143                   const char *file,
144                   int line, const char *funcname,
145                   int level, char *what, jk_msg_buf_t *msg);
146
147 /** Copy a msg buf into another one
148   */
149 int jk_b_copy(jk_msg_buf_t *smsg, jk_msg_buf_t *dmsg);
150
151 #ifdef __cplusplus
152 }
153 #endif    /* __cplusplus */
154 #endif    /* JK_MSG_BUF_H */