#ifndef _COC_H_
#define _COC_H_

#include <netinet/in.h>
#include "str_buf.h"

int CocCreateSockAdr(
    struct sockaddr_in *sockaddrPtr,    /* Socket address */
    const char *host,                   /* Host.  NULL implies INADDR_ANY */
    int port);                          /* Port number */
int CocRecv(int fd, Str_Buf *buf);

typedef struct { void *next; char name[32]; void *var; int *flag; int type; void *strucType; } CocVar;

extern int CocRD;
extern int CocWR;
CocVar *serverVarList;

CocVar *CocDefVar(const char *name, void *var, int type, int *flag);
void CocDefVarS(const char *name, const char *tname, void *var, int type);
void CocVarList(CocVar **varlist);
void CocFreeVarList(CocVar **varList);
CocVar *CocFindVar(CocVar *varList, const char *name, void **adr);
int CocPutVar(CocVar *varList, Str_Buf *buf, const char *name, int secure);
int CocGetVar(CocVar *varList, Str_Buf *buf, const char *name, int secure);

#define COC_INT -1
#define COC_FLT -2
#define COC_PTR -3
#define COC_STRUCT -4
#define COC_TYPE -5
#define COC_ALIAS -6
#define CocDefInt(V,F)      CocDefVar(#V,&V,COC_INT,&F)
#define CocDefFlt(V,F)      CocDefVar(#V,&V,COC_FLT,&F)
#define CocDefStr(V,F)      CocDefVar(#V,V,sizeof(V),&F)
#define CocDefPtr(V,S)      CocDefVarS(#V,#S,&V,COC_PTR*(V!=(S *)NULL));
#define CocDefStruct(V,S)   CocDefVarS(#V,#S,&V,COC_STRUCT*(&V!=(S *)NULL));
#define CocIntFld(S,V,F)    CocDefVar(#S":"#V,&((S *)NULL)->V,COC_INT,&F);
#define CocFltFld(S,V,F)    CocDefVar(#S":"#V,&((S *)NULL)->V,COC_FLT,&F);
#define CocStrFld(S,V,F)    CocDefVar(#S":"#V,((S *)NULL)->V,sizeof(((S *)NULL)->V),&F);
#define CocDefCmd(V)        CocDefVar("$",V,sizeof(V),&CocWR)
#define CocDefStrPtr(V,S,F) CocDefVar(#V,V,S,&F)
#define CocAlias(A,V)       CocDefVar(#A, #V, COC_ALIAS, &CocRD);

void CocDelay(int msec);

#endif /* _COC_H_ */
