this will attempt to be a hybrid doc/log.

PDLIB aims to be a c lib for persistence and distributed processing type stuff.
it will handle managing structure typing and managing the store (ie: the ability to save/restore structures reachable from a set of roots), and will allow one to later fetch type info associated with the structures. it will try to impose as little on the c programming experience as possible.

for now I will focus on message passing and rpc style net stuff. shared memory is another possibility.


Type Notation

DEF = TYPE [':' NAME] ';' | TYPE '+' [':' NAME ';']
TYPE = TypeName | SHAPE TypeName | '*' TypeName | SHAPE '*' TypeName
SHAPE = Int | Int ',' SHAPE

single words will flag inlined types.
'*type' will indicate a pointer to the type.
'type+' will indicate a terminal array of that type.
'*type+' will be a terminal array of pointers to type.

'sbyte': 8 bit signed int;
'byte': 8 bit unsigned int;
'short': 16 bit signed int;
'ushort': 16 bit unsigned int;
'int': 32 bit signed int;
'uint': 32 bit unsigned int;

'float': 32 bit float;
'double': 64 bit double;

'string': string, pointer to an externally defined string;
'*struct': reference to a struct.

at present including defined types within type strings will be disallowed (this does not count for pointer types).

Type Functions

int ObjType_FormSize(char *form);
tells the size (excluding terminal arrays) of a struct type string.

PDLIB_ObjType *ObjType_NewType(char *name, char *form);
will declare a type, name is the name of the new type and form is the definition string.
see headers for PDLIB_ObjType.

PDLIB_ObjType *ObjType_FindType(char *type);
fetches the type definition for a given type name.

void *ObjType_New(char *type, int size);
create a new object of the given type. at present this only allows defined types (excluding primitive types: 'byte', 'int', 'string', ...).
p points to the start of the object body.
size is either 0 (for the size associated with the base definition), or the complete size (the size of the base structure + the size of the terminal array).

PDLIB_ObjType *ObjType_GetType(void *p);
gets the type definition associated with a given object pointer.

char *ObjType_GetTypeName(void *p);
gets the type name associated with the given object pointer.

int ObjType_GetSize(void *p);
gets the size associated with the given object pointer (this is either the base size or the size passed via ObjType_New).

int ObjType_Init();
init func, to be called before anything else is used.

Image Functions

int PDLIB_Image_NameObj(char *name, void *ptr);
associates a name with a given object, the name will be used as a root for the store/load facility.

void *PDLIB_Image_FetchName(char *name);
fetches the object associated with the given name.

int PDLIB_StoreImage(char *name);
stores reachable objects in the image identified with name.

int PDLIB_LoadImage(char *name);
loads objects from the image associated with name.

void *kalloc(int size);
allocates via the pdlib mm.

int kfree(void *p);
free via the pdlib mm.

found within kfunc, mostly serving as specialized replacements for ansi functions.


vfile is an io api. it serves as a general replacement for the stdio api, and provides for various types of special purpose io which behave like files/strings (eg: the net code). it also allows for creation of customized file-like objects.
most basic calls are nearly identical to the stdio calls, except with a 'v' prefix, eg:
vfread(void *buf, int n, int m, VFILE *fd);

VFILE is a structure full of callbacks with some values, the 'buffer' field is provided for callback specific data.
'vfnew' can create a dummy vfile which can be set up with handlers and such.

'vffopen' is the fopen equivalent function.

int vfsread(void *buf, u4 pos, int len, VFILE *fd, vf_int_cb *cb, void *data);
int vfswrite(void *buf, u4 pos, int len, VFILE *fd, vf_int_cb *cb, void *data);
int vfreads(void *buf, u4 pos, int len, VFILE *fd);
int vfwrites(void *buf, u4 pos, int len, VFILE *fd);
int vflread(void *buf, u8 pos, int len, VFILE *fd, vf_int_cb *cb, void *data);
int vflwrite(void *buf, u8 pos, int len, VFILE *fd, vf_int_cb *cb, void *data);

int vfread(void *buf, int s1, int s2, VFILE *fd);
int vfwrite(void *buf, int s1, int s2, VFILE *fd);
int vfseek(VFILE *fd, int pos, int rel);
int vflseek(VFILE *fd, s8 pos, s8 ret, int rel);
int vftell(VFILE *fd);
int vfgetc(VFILE *fd);
int vfputc(int v, VFILE *fd);
int vfclose(VFILE *fd);
int vfeof(VFILE *fd);
int vfflush(VFILE *fd);
int vfinready(VFILE *fd);
char *vfgets(char *s, int n, VFILE *fd);

int vfioctls(VFILE *fd, ...);
void *vfmmap(void *addr, int length, int prot, int flags, VFILE *fd, int offs);

VFILE *vffopen(char *name, char *access);
byte *vf_bufferin(VFILE *fd);
VFILE *vf_clip(VFILE *fd, u8 start, u8 length);

VFILE *vfnew();
int vfdestroy(VFILE *fd);

int vfsend(VFILE *sock, VADDR *target, void *msg, int len, int flags);
int vfget(void *buf, int sz, VADDR *from, VFILE *sock);



allows setting/fetching string based variables.

int Var_Init();
PDLIB_Var *Var_Lookup(char *name);
PDLIB_Var *Var_Create(char *name);
PDLIB_Var *Var_SetString(char *name, char *value);
char *Var_GetString(char *name);
float Var_GetValue(char *name);
fetches the numeric value of a var, assuming it is syntactically a number.

int Var_ParseConfig(VFILE *fd);
int Var_LoadConfig(char *name);
loads config from the file indicated by name.
at present config is a set of lines with the notation:
'<var> <val>'
blank lines and those beginning with '#' or ';' are ignored.


a facility for parsing/printing textual tree structures.

NetParse_Node *NetParse_NewNode();
makes new, empty node.

NetParse_Node *NetParse_AddNodeEnd(NetParse_Node *first, NetParse_Node *node);
adds a node to the end of a list of nodes. returns node if first is null, otherwise returns first.

int NetParse_FreeAttr(NetParse_Attr *attr);
frees attruibutes. this is recursive.

int NetParse_FreeNode(NetParse_Node *node);
frees nodes, this is recursive and also frees attributes.

NetParse_Node *NetParse_FindKey(NetParse_Node *first, char *key);
find a node with a given key in a list of nodes.

NetParse_Node *NetParse_SX_ParseExpr(char **s);
char *NetParse_SX_PrintExpr(char *s, NetParse_Node *exp);
these handle parsing and printing the sx syntax (a stripped down form of untyped s-expressions).

NetParse_Node *NetParse_XML_ParseExpr(char **s);
char *NetParse_XML_PrintExpr(char *s, NetParse_Node *exp);
handle parsing and printing of xml.


manages the dynamic typing used within the rpc subsystem (based on ObjType).

void *NetVal_WrapInt(int i);
void *NetVal_WrapStr(char *s);
void *NetVal_WrapFloat(double f);
void *NetVal_WrapArray(void *a);
int NetVal_Init();

types are:
struct with a single int value.
actually a double.
an integer, 0 false, 1 true.
array of char.
a be short for the year, followed by bytes: month;day;hour;minute;second
byte array containing data.
array of pointers, terminated by NULL.
dynamic array, contains a pointer to an array.
contains a pointer to an array of names, followed by one of values.

Net Api

int NET_AddrEqual(VADDR *a, VADDR *b);
compares 2 addresses, returns a nonzero value if they are equal.

int NET_Poll();
polls protocols for data/new connections.

int NET_Init();
main init func for basic net subsystem.

int NET_ExportFunc(char *name, void *(*func)());
exports func for use in incomming rpc calls.

NET_Interface *NET_CreateInterface(char *name);
creates an 'interface'. name is used to refer to it, and serves as the prefix for decoding urls and such.

NET_Interface *NET_FindInterface(char *name);
NET_Export *NET_FindExport(char *name);
NET_Reference *NET_DecodeURL(char *url);
char *NET_EncodeURL(NET_Reference *ref);

void *NET_CallReference(NET_Reference *ref, void **args);
this calls a function defined by a reference (which is gotten, ie, by decoding a url).

void *NET_CallExport(char *name, void **args);
calls an exported function, this is used, ie: on the incomming end of protocols.


int NET_CreateGuid(VGUID *buf);
int NET_GuidEqualP(VGUID *a, VGUID *b);
char *NET_Guid2String(VGUID *guid);
char *NET_String2Guid(VGUID *guid, char *s);

char *NET_Addr2Str(VADDR *addr);
VADDR *NET_Str2Addr(char *str, int proto);
int NET_InitLow (void);
VADDR *NET_LookupHost(char *name);
VADDR *NET_LookupHost2(char *name, char *serv, int proto);

int TCP_GetSocketAddr(int socket, VADDR *addrbuf);
VFILE *TCP_WrapSocket(int sock);
VFILE *TCP_OpenSocket(int port);
VFILE *TCP_OpenListen(int port);
VFILE *TCP_OpenListen_IPv6(int port);
VFILE *TCP_OpenConnect(VADDR *targ);

int UDP_GetSocketAddr(int socket, VADDR *addrbuf);
VFILE *UDP_OpenSocket(int port);


Meta0_Con *Meta0_NewCon();
Meta0_PortInfo *Meta0_NewPortInfo();
Meta0_Con *Meta0_Connect(VADDR *addr);
Meta0_Con *Meta0_FindCon(VADDR *addr);
int Meta0_HandleConnection(Meta0_Con *con);
int Meta0_PollPort(Meta0_PortInfo *inf);
int Meta0_Poll();
Meta0_PortInfo *Meta0_CreatePort(int port);
int Meta0_Init();


HTTP_Con *HttpNode_NewCon();
int HttpNode_SendContents(HTTP_Con *con, byte *type, byte *msg, int len);
char *HttpNode_CodeName(int code);
int HttpNode_SendContentsCode(HTTP_Con *con, int code, byte *type, byte *msg, int len);
int HttpNode_SendPage(HTTP_Con *con);
int HttpNode_SendPageHead(HTTP_Con *con);
int HttpNode_Send404(HTTP_Con *con, byte *type, byte *msg, int len);
int HttpNode_HandleLine(HTTP_Con *con, char *lb);
int HttpNode_HandleMessage(HTTP_Con *con, char *msg, int len);
int HttpNode_HandleConnection(HTTP_Con *con);
HTTP_Resource *HttpNode_NewResource(char *base);
int HttpNode_Poll();
int HttpNode_Init();

int HttpNode_EncodeMime(byte *o, byte *i, int sz);
int HttpNode_DecodeMime(byte *o, byte *i, int sz);
char *HttpNode_MimeFromExt(char *ext);
char *HttpNode_MimeFromName(char *name);
int HttpNode_MimeInit();