2016-11-09 12:42:29 +00:00
|
|
|
|
|
|
|
/*
|
2017-07-06 11:44:19 +00:00
|
|
|
* Shapito.
|
2016-11-09 12:42:29 +00:00
|
|
|
*
|
|
|
|
* Protocol-level PostgreSQL client library.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
2017-07-06 11:29:52 +00:00
|
|
|
#include "sources/macro.h"
|
|
|
|
#include "sources/stream.h"
|
|
|
|
#include "sources/header.h"
|
|
|
|
#include "sources/key.h"
|
|
|
|
#include "sources/read.h"
|
2016-11-09 12:42:29 +00:00
|
|
|
|
2017-07-04 12:54:33 +00:00
|
|
|
int so_read_startup(uint32_t *len, char **data, uint32_t *size)
|
2016-11-09 13:08:10 +00:00
|
|
|
{
|
|
|
|
if (*size < sizeof(uint32_t))
|
|
|
|
return sizeof(uint32_t) - *size;
|
|
|
|
/* len */
|
|
|
|
uint32_t pos_size = *size;
|
2017-07-04 12:54:33 +00:00
|
|
|
char *pos = *data;
|
2016-11-09 13:08:10 +00:00
|
|
|
so_stream_read32(len, &pos, &pos_size);
|
|
|
|
uint32_t len_to_read;
|
|
|
|
len_to_read = *len - *size;
|
|
|
|
if (len_to_read > 0)
|
|
|
|
return len_to_read;
|
|
|
|
/* advance data stream */
|
|
|
|
*data += *len;
|
|
|
|
*size -= *len;
|
|
|
|
/* set actual data size */
|
|
|
|
*len -= sizeof(uint32_t);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-07-04 12:54:33 +00:00
|
|
|
int so_read(uint32_t *len, char **data, uint32_t *size)
|
2016-11-09 12:42:29 +00:00
|
|
|
{
|
2016-11-29 12:28:33 +00:00
|
|
|
if (*size < sizeof(so_header_t))
|
|
|
|
return sizeof(so_header_t) - *size;
|
2016-11-09 12:42:29 +00:00
|
|
|
uint32_t pos_size = *size - sizeof(uint8_t);
|
2017-07-04 12:54:33 +00:00
|
|
|
char *pos = *data + sizeof(uint8_t);
|
2016-11-09 12:42:29 +00:00
|
|
|
/* type */
|
2016-11-09 12:53:44 +00:00
|
|
|
so_stream_read32(len, &pos, &pos_size);
|
2016-11-09 12:42:29 +00:00
|
|
|
uint32_t len_to_read;
|
2017-07-04 12:54:33 +00:00
|
|
|
len_to_read = (*len + sizeof(char)) - *size;
|
2016-11-09 12:42:29 +00:00
|
|
|
if (len_to_read > 0)
|
|
|
|
return len_to_read;
|
|
|
|
/* advance data stream */
|
|
|
|
*data += sizeof(uint8_t) + *len;
|
|
|
|
*size -= sizeof(uint8_t) + *len;
|
2016-11-09 13:08:10 +00:00
|
|
|
/* set actual data size */
|
2016-11-09 12:42:29 +00:00
|
|
|
*len -= sizeof(uint32_t);
|
|
|
|
return 0;
|
|
|
|
}
|