#include <stdio.h>
#include <sys/types.h>
#include <stdint.h>
#include "dazuko_transport.h"
Go to the source code of this file.
Defines | |
#define | LINUX |
#define | int_ptr_t int32_t |
Functions | |
static int | getbyte (unsigned char **p, int *b) |
static int | getinteger (unsigned char **p, int *b, int count) |
int | dazuko_reqstream_chunksize (unsigned char *ll, int *size) |
static int | getpointer (unsigned char **p, char **b, int count) |
static int | putbyte (unsigned char **p, int b) |
static int | putinteger (unsigned char **p, int b, int count) |
static int | putpointer (unsigned char **p, char *b, int count) |
static int | skipinteger (unsigned char **p, int count) |
static int | skippointer (unsigned char **p, int count) |
int | dazuko_reqstream_dim_chunk0 (int size_chr, int size_int, int size_ptr) |
int | dazuko_reqstream_hl2ll (struct dazuko_request *req, unsigned char *ll) |
int | dazuko_reqstream_ll2hl (unsigned char *ll, struct dazuko_request *req, int strict) |
int | dazuko_reqstream_updll (struct dazuko_request *req, unsigned char *ll) |
|
Definition at line 118 of file dazuko_transport.c. Referenced by getpointer(), and putpointer(). |
|
Definition at line 59 of file dazuko_transport.c. |
|
Definition at line 170 of file dazuko_transport.c. References getinteger(). Referenced by dazuko_handle_user_request(). 00171 { 00172 /* this is a wrapper to getinteger that does NOT 00173 * increment the buffer pointer */ 00174 00175 unsigned char *p = ll; 00176 00177 return getinteger(&p, size, 4); 00178 }
|
|
Definition at line 304 of file dazuko_transport.c. Referenced by dazuko_reqstream_hl2ll(), dazuko_reqstream_ll2hl(), dazuko_reqstream_updll(), and process_request(). 00305 { 00306 /* 00307 * a request consists of: 00308 * chunk0 length (as 4-byte integer) 00309 * used flag, sizeof char/int/void* (as single bytes) 00310 * type, in size, out size, out used (as integers) 00311 * in buff, out buff (as pointers) 00312 */ 00313 return (4 + (4 * size_chr) + (4 * size_int) + (2 * size_ptr)); 00314 }
|
|
Definition at line 320 of file dazuko_transport.c. References dazuko_reqstream_dim_chunk0(), putbyte(), putinteger(), and putpointer(). Referenced by process_request(). 00321 { 00322 unsigned char *wrptr; 00323 int size_chr; 00324 int size_int; 00325 int size_ptr; 00326 int size_req; 00327 int type_as_int; 00328 00329 wrptr = ll; 00330 00331 /* prepare to write */ 00332 size_chr = sizeof(char); 00333 size_int = sizeof(int); 00334 size_ptr = sizeof(void *); 00335 size_req = dazuko_reqstream_dim_chunk0(size_chr, size_int, size_ptr); 00336 00337 /* 00338 * we do not support multi byte characters 00339 * and we assume maximum int and ptr sizes 00340 */ 00341 /* 00342 * XXX how to check these at compile time? 00343 * #if (sizeof int < 4) 00344 * etc did not work :( 00345 */ 00346 if (size_chr != 1) 00347 return -1; 00348 00349 /* convert everything to base types */ 00350 type_as_int = (req->type[0] << 8) + (req->type[1] << 0); 00351 00352 /* stream out */ 00353 if (putinteger(&wrptr, size_req, 4) != 0) return -1; 00354 if (putbyte(&wrptr, 0) != 0) return -1; 00355 if (putbyte(&wrptr, size_chr) != 0) return -1; 00356 if (putbyte(&wrptr, size_int) != 0) return -1; 00357 if (putbyte(&wrptr, size_ptr) != 0) return -1; 00358 if (putinteger(&wrptr, type_as_int, size_int) != 0) return -1; 00359 if (putinteger(&wrptr, req->buffer_size, size_int) != 0) return -1; 00360 if (putpointer(&wrptr, req->buffer, size_ptr) != 0) return -1; 00361 if (putinteger(&wrptr, req->reply_buffer_size, size_int) != 0) return -1; 00362 if (putpointer(&wrptr, req->reply_buffer, size_ptr) != 0) return -1; 00363 if (putinteger(&wrptr, req->reply_buffer_size_used, size_int) != 0) return -1; 00364 00365 /* done */ 00366 return 0; 00367 }
|
|
Definition at line 373 of file dazuko_transport.c. References dazuko_request::buffer, dazuko_request::buffer_size, dazuko_reqstream_dim_chunk0(), getbyte(), getinteger(), getpointer(), dazuko_request::reply_buffer, dazuko_request::reply_buffer_size, dazuko_request::reply_buffer_size_used, and dazuko_request::type. Referenced by dazuko_handle_user_request(), and process_request(). 00374 { 00375 unsigned char *rdptr; 00376 int size_req; 00377 int req_used; 00378 int size_chr; 00379 int size_int; 00380 int size_ptr; 00381 int type_as_int; 00382 00383 rdptr = (unsigned char *)ll; 00384 00385 /* only accept streams with our own layout (length part) */ 00386 if (getinteger(&rdptr, &size_req, 4) != 0) return -1; 00387 if (strict) 00388 { 00389 if (size_req != dazuko_reqstream_dim_chunk0(sizeof(char), sizeof(int), sizeof(void *))) 00390 return -1; 00391 } 00392 00393 /* the kernel MUST have updated the stream, otherwise it's invalid */ 00394 if (getbyte(&rdptr, &req_used) != 0) return -1; 00395 if (strict) 00396 { 00397 if (!req_used) 00398 return -1; 00399 } 00400 00401 /* only accept streams with our own layout (type width part) */ 00402 if (getbyte(&rdptr, &size_chr) != 0) return -1; 00403 if (getbyte(&rdptr, &size_int) != 0) return -1; 00404 if (getbyte(&rdptr, &size_ptr) != 0) return -1; 00405 if (strict) 00406 { 00407 if ((size_chr != sizeof(char)) || (size_int != sizeof(int)) || (size_ptr != sizeof(void *))) 00408 return -1; 00409 } 00410 if (size_req != dazuko_reqstream_dim_chunk0(size_chr, size_int, size_ptr)) 00411 return -1; 00412 00413 /* stream in values */ 00414 if (getinteger(&rdptr, &type_as_int, size_int) != 0) return -1; 00415 if (getinteger(&rdptr, &req->buffer_size, size_int) != 0) return -1; 00416 if (getpointer(&rdptr, &req->buffer, size_ptr) != 0) return -1; 00417 if (getinteger(&rdptr, &req->reply_buffer_size, size_int) != 0) return -1; 00418 if (getpointer(&rdptr, &req->reply_buffer, size_ptr) != 0) return -1; 00419 if (getinteger(&rdptr, &req->reply_buffer_size_used, size_int) != 0) return -1; 00420 00421 /* post convert to req */ 00422 req->type[0] = (type_as_int >> 8) & 0xFF; 00423 req->type[1] = (type_as_int >> 0) & 0xFF; 00424 00425 /* done */ 00426 return 0; 00427 }
|
|
Definition at line 433 of file dazuko_transport.c. References dazuko_reqstream_dim_chunk0(), getbyte(), getinteger(), putbyte(), putinteger(), dazuko_request::reply_buffer_size_used, skipinteger(), and skippointer(). Referenced by dazuko_handle_user_request(). 00434 { 00435 unsigned char *wrptr; 00436 int size_chr; 00437 int size_int; 00438 int size_ptr; 00439 int size_req; 00440 00441 wrptr = ll; 00442 00443 /* fetch the complete length spec to check it later */ 00444 if (getinteger(&wrptr, &size_req, 4) != 0) return -1; 00445 00446 /* rather aux a test for minimum length */ 00447 if (size_req < dazuko_reqstream_dim_chunk0(1, 4, 4)) 00448 return -1; 00449 00450 /* set the "used" flag */ 00451 /* 00452 * XXX delay this to a later point in time??? OTOH the update routine 00453 * will return an error when later steps fail and the stream will not 00454 * get passed back to the application, so this seems OK 00455 */ 00456 if (putbyte(&wrptr, 1) != 0) return -1; 00457 00458 /* fetch the data width fields to check them */ 00459 if (getbyte(&wrptr, &size_chr) != 0) return -1; 00460 if (getbyte(&wrptr, &size_int) != 0) return -1; 00461 if (getbyte(&wrptr, &size_ptr) != 0) return -1; 00462 if (size_chr != 1) 00463 return -1; 00464 if (size_req != dazuko_reqstream_dim_chunk0(size_chr, size_int, size_ptr)) 00465 return -1; 00466 00467 /* skip over the fields not of interest, only write back the 00468 * "reply_buffer_size_used" component */ 00469 if (skipinteger(&wrptr, size_int) != 0) return -1; 00470 if (skipinteger(&wrptr, size_int) != 0) return -1; 00471 if (skippointer(&wrptr, size_ptr) != 0) return -1; 00472 if (skipinteger(&wrptr, size_int) != 0) return -1; 00473 if (skippointer(&wrptr, size_ptr) != 0) return -1; 00474 if (putinteger(&wrptr, req->reply_buffer_size_used, size_int) != 0) return -1; 00475 00476 /* done */ 00477 return 0; 00478 }
|
|
Definition at line 125 of file dazuko_transport.c. References NULL. Referenced by dazuko_reqstream_ll2hl(), and dazuko_reqstream_updll(). 00126 { 00127 if (p == NULL) 00128 return -1; 00129 00130 if (*p == NULL) 00131 return -1; 00132 00133 if (b == NULL) 00134 return -1; 00135 00136 *b = **p; 00137 (*p)++; 00138 00139 return 0; 00140 }
|
|
Definition at line 144 of file dazuko_transport.c. References NULL. Referenced by dazuko_reqstream_chunksize(), dazuko_reqstream_ll2hl(), and dazuko_reqstream_updll(). 00145 { 00146 int res; 00147 int idx; 00148 00149 if (p == NULL) 00150 return -1; 00151 00152 if (*p == NULL) 00153 return -1; 00154 00155 if (b == NULL) 00156 return -1; 00157 00158 res = 0; 00159 for (idx=0 ; idx<count ; idx++) 00160 { 00161 res <<= 8; 00162 res += **p; 00163 (*p)++; 00164 } 00165 *b = res; 00166 00167 return 0; 00168 }
|
|
Definition at line 182 of file dazuko_transport.c. References int_ptr_t, and NULL. Referenced by dazuko_reqstream_ll2hl(). 00183 { 00184 int_ptr_t res; 00185 int idx; 00186 00187 if (p == NULL) 00188 return -1; 00189 00190 if (*p == NULL) 00191 return -1; 00192 00193 if (b == NULL) 00194 return -1; 00195 00196 res = 0; 00197 for (idx = 0; idx<count ; idx++) 00198 { 00199 res <<= 8; 00200 res += **p; 00201 (*p)++; 00202 } 00203 00204 *b = (void *)res; 00205 00206 return 0; 00207 }
|
|
Definition at line 211 of file dazuko_transport.c. References NULL. Referenced by dazuko_reqstream_hl2ll(), and dazuko_reqstream_updll(). 00212 { 00213 if (p == NULL) 00214 return -1; 00215 00216 if (*p == NULL) 00217 return -1; 00218 00219 **p = b; 00220 (*p)++; 00221 00222 return 0; 00223 }
|
|
Definition at line 227 of file dazuko_transport.c. References NULL. Referenced by dazuko_reqstream_hl2ll(), and dazuko_reqstream_updll(). 00228 { 00229 int val; 00230 int idx; 00231 00232 if (p == NULL) 00233 return -1; 00234 00235 if (*p == NULL) 00236 return -1; 00237 00238 val = b; 00239 for (idx=1 ; idx<=count ; idx++) 00240 { 00241 *(*p + count - idx) = (val & 0xFF); 00242 val >>= 8; 00243 } 00244 *p += count; 00245 00246 return 0; 00247 }
|
|
Definition at line 251 of file dazuko_transport.c. References int_ptr_t, and NULL. Referenced by dazuko_reqstream_hl2ll(). 00252 { 00253 int_ptr_t val; 00254 int idx; 00255 00256 if (p == NULL) 00257 return -1; 00258 00259 if (*p == NULL) 00260 return -1; 00261 00262 val = (int_ptr_t)b; 00263 for (idx=1 ; idx<=count ; idx++) 00264 { 00265 *(*p + count - idx) = (val & 0xFF); 00266 val >>= 8; 00267 } 00268 *p += count; 00269 00270 return(0); 00271 }
|
|
Definition at line 275 of file dazuko_transport.c. References NULL. Referenced by dazuko_reqstream_updll(). 00276 { 00277 if (p == NULL) 00278 return -1; 00279 00280 if (*p == NULL) 00281 return -1; 00282 00283 (*p) += count; 00284 00285 return 0; 00286 }
|
|
Definition at line 288 of file dazuko_transport.c. References NULL. Referenced by dazuko_reqstream_updll(). 00289 { 00290 if (p == NULL) 00291 return -1; 00292 00293 if (*p == NULL) 00294 return -1; 00295 00296 (*p) += count; 00297 00298 return(0); 00299 }
|