Compare commits
No commits in common. "master" and "REL_10_0" have entirely different histories.
43
decode.c
43
decode.c
@ -9,11 +9,8 @@
|
|||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <sys/socket.h>
|
|
||||||
|
|
||||||
#define ATTRTYPES_STR_MAX_LEN (1024-1)
|
#define ATTRTYPES_STR_MAX_LEN (1024-1)
|
||||||
#define PGSQL_AF_INET (AF_INET + 0)
|
|
||||||
#define PGSQL_AF_INET6 (AF_INET + 1)
|
|
||||||
|
|
||||||
typedef int (*decode_callback_t)(const char* buffer, unsigned int buff_size,
|
typedef int (*decode_callback_t)(const char* buffer, unsigned int buff_size,
|
||||||
unsigned int* out_size);
|
unsigned int* out_size);
|
||||||
@ -63,9 +60,6 @@ decode_char(const char* buffer, unsigned int buff_size, unsigned int* out_size);
|
|||||||
static int
|
static int
|
||||||
decode_name(const char* buffer, unsigned int buff_size, unsigned int* out_size);
|
decode_name(const char* buffer, unsigned int buff_size, unsigned int* out_size);
|
||||||
|
|
||||||
static int
|
|
||||||
decode_inet(const char* buffer, unsigned int buff_size, unsigned int* out_size);
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
decode_ignore(const char* buffer, unsigned int buff_size, unsigned int* out_size);
|
decode_ignore(const char* buffer, unsigned int buff_size, unsigned int* out_size);
|
||||||
|
|
||||||
@ -99,7 +93,6 @@ static ParseCallbackTableItem callback_table[] = {
|
|||||||
{ "macaddr", &decode_macaddr },
|
{ "macaddr", &decode_macaddr },
|
||||||
{ "name", &decode_name },
|
{ "name", &decode_name },
|
||||||
{ "char", &decode_char },
|
{ "char", &decode_char },
|
||||||
{ "inet", &decode_inet },
|
|
||||||
{ "~", &decode_ignore },
|
{ "~", &decode_ignore },
|
||||||
|
|
||||||
/* internally all string types are stored the same way */
|
/* internally all string types are stored the same way */
|
||||||
@ -154,7 +147,7 @@ CopyAppend(const char* str)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if(copyString.data[0] != '\0')
|
if(copyString.data[0] != '\0')
|
||||||
appendStringInfoString(©String, ",");
|
appendStringInfoString(©String, "\t");
|
||||||
|
|
||||||
appendStringInfoString(©String, str);
|
appendStringInfoString(©String, str);
|
||||||
}
|
}
|
||||||
@ -264,7 +257,7 @@ CopyFlush(void)
|
|||||||
/* Make sure init is done */
|
/* Make sure init is done */
|
||||||
CopyAppend(NULL);
|
CopyAppend(NULL);
|
||||||
|
|
||||||
fprintf(stderr, "%s\n", copyString.data);
|
printf("COPY: %s\n", copyString.data);
|
||||||
CopyClear();
|
CopyClear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -665,38 +658,6 @@ decode_macaddr(const char* buffer, unsigned int buff_size, unsigned int* out_siz
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Decode a inet type */
|
|
||||||
static int
|
|
||||||
decode_inet(const char* buffer, unsigned int buff_size, unsigned int* out_size)
|
|
||||||
{
|
|
||||||
struct __attribute__((packed)) inet_t // FIXME: Only AF_INET is supported for now
|
|
||||||
{
|
|
||||||
unsigned char varlen;
|
|
||||||
unsigned char family;
|
|
||||||
unsigned char bits;
|
|
||||||
unsigned char ipaddr[4];
|
|
||||||
} inet;
|
|
||||||
|
|
||||||
if(buff_size < sizeof(inet))
|
|
||||||
return -2;
|
|
||||||
|
|
||||||
memcpy(&inet, buffer, sizeof(inet));
|
|
||||||
if (inet.family == PGSQL_AF_INET) {
|
|
||||||
CopyAppendFmt("%d.%d.%d.%d",
|
|
||||||
inet.ipaddr[0], inet.ipaddr[1], inet.ipaddr[2], inet.ipaddr[3]
|
|
||||||
);
|
|
||||||
*out_size = sizeof(inet);
|
|
||||||
return 0;
|
|
||||||
} else { // This basically dumps the stuff, now decodes them (perhaps AF_INET6)
|
|
||||||
CopyAppendFmt("[%d.%d.%d.%d.%d.%d.%d]",
|
|
||||||
inet.varlen, inet.family, inet.bits,
|
|
||||||
inet.ipaddr[0], inet.ipaddr[1], inet.ipaddr[2], inet.ipaddr[3]
|
|
||||||
);
|
|
||||||
*out_size = sizeof(inet);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Decode a bool type */
|
/* Decode a bool type */
|
||||||
static int
|
static int
|
||||||
decode_bool(const char* buffer, unsigned int buff_size, unsigned int* out_size)
|
decode_bool(const char* buffer, unsigned int buff_size, unsigned int* out_size)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user