<|start_filename|>callbacks.c<|end_filename|>
﻿/* ------------------------------------------------------------- */
/* Program . . . : Node.RPG - main interface                     */
/* Date  . . . . : 02.06.2018                                    */
/* Design  . . . : <NAME>                                */
/* Function  . . : Main Socket server                            */
/*                                                               */
/* By     Date       PTF     Description                         */
/* NL     02.06.2018         New program                         */
/* ------------------------------------------------------------- */
#define _MULTI_THREADED

// max number of concurrent users
#define FD_SETSIZE 4096

#include <os2.h>
#include <pthread.h>

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <decimal.h>
#include <fcntl.h>


/* in qsysinc library */
#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <ssl.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <errno.h>
#include <unistd.h>
#include <spawn.h>


#include "ostypes.h"
#include "sysdef.h"
#include "strUtil.h"
#include "varchar.h"


/* --------------------------------------------------------------------------- */
void node_write (PRESPONSE pResponse, PVARCHAR buf)
{
    putHeader (pResponse);
    putChunk (pResponse, buf->String, buf->Length);         
}




<|start_filename|>strUtil.h<|end_filename|>
﻿#ifndef STRUTIL_H
#define STRUTIL_H

int     strIcmp (PUCHAR s1, PUCHAR s2);
int     memIcmp (PUCHAR s1, PUCHAR s2 , int len);
SHORT  memicmpascii(PUCHAR m1  , PUCHAR m2 , LONG len );
UCHAR  toLower(UCHAR c);
UCHAR  toUpper(UCHAR c);
UCHAR  toupperascii(UCHAR c);
UCHAR  tolowerascii(UCHAR c);
LONG   strTrimLen(PUCHAR str);
LONG   strtrim(PUCHAR str);
PUCHAR strchrreplace(PUCHAR out , PUCHAR in , PUCHAR from , PUCHAR to );
LONG   memstrreplace(PUCHAR buf , LONG len , PUCHAR from , PUCHAR to );
PUCHAR fmtPacked(PUCHAR out , PUCHAR in , SHORT len , SHORT prec, UCHAR decPoint);
PUCHAR fmtZoned(PUCHAR out , PUCHAR in , SHORT len , SHORT prec, UCHAR decPoint);
PUCHAR stripLeadingZeros(PUCHAR out, PUCHAR input);
PUCHAR str2lower(PUCHAR out , PUCHAR in);
PUCHAR str2upper(PUCHAR out , PUCHAR in);
PUCHAR subword (PUCHAR out , PUCHAR in , LONG ix, PUCHAR delimiters);
LONG   subwords (PUCHAR in , PUCHAR  delimiters);
// LONG   subwords (PVARCHAR inputStr, PUCHAR  delimiters);
PUCHAR stristr(PUCHAR base, PUCHAR key );
PUCHAR strlastchr(PUCHAR base, UCHAR c );
PUCHAR memstr(PUCHAR base, PUCHAR key , LONG len);
PUCHAR memistr(PUCHAR base, PUCHAR key , LONG len);
PUCHAR strtrimncpy(PUCHAR out , PUCHAR in , LONG maxlen);
PUCHAR strtrimcpy(PUCHAR out , PUCHAR in);
PUCHAR strrighttrimcpy(PUCHAR dst, PUCHAR src);
PUCHAR strrighttrimncpy(PUCHAR dst, PUCHAR src, LONG len);

int cpy  (PUCHAR out , PUCHAR in);
PUCHAR trim(PUCHAR in);
PUCHAR firstnonblank(PUCHAR in);
PUCHAR lastnonblank(PUCHAR in);
PUCHAR righttrim(PUCHAR in);
PUCHAR righttrimlen(PUCHAR in , LONG size);
LONG   lenrighttrimlen(PUCHAR in , LONG size);
PUCHAR substr(PUCHAR out , PUCHAR in , LONG len);
PUCHAR padncpy(PUCHAR dst, PUCHAR src, SHORT dstlen);
#define padcpy(a,b) padncpy(a,b,sizeof(a))
PUCHAR pad(PUCHAR s , LONG l);
PUCHAR blob2str   (PBLOB blob);
ULONG hexstr2int (PUCHAR s);
UCHAR hexchar2int (UCHAR c);
PUCHAR binMem2Hex (PUCHAR out , PUCHAR in , LONG len);
PUCHAR hex2BinMem (PUCHAR out , PUCHAR in , LONG len);
FIXEDDEC str2dec(PUCHAR str, UCHAR decPoint);
LONG packedMem2Int(PUCHAR buf, SHORT bytes);


#endif


<|start_filename|>sysdef.h<|end_filename|>
﻿#ifndef SYSDEF_H
#define  SYSDEF_H

#include "ostypes.h"

typedef void(OS_CALL) ();
#pragma linkage (OS_CALL, OS)


#pragma enum     (1)
typedef enum _IPC_TYPE  {
    IPC_INPUT         = 'I',
    IPC_OUTPUT        = 'O'
} IPC_TYPE , *PIPC_TYPE ;
#pragma enum     (pop)



typedef _Packed struct _APIRTN  {
    LONG    ApiSize;
    LONG    ApiAvail;
    UCHAR   ApiMsgId[8];
    UCHAR   ApiMsgData[512];
} APIRTN   , *PAPIRTN;



typedef _Packed struct _CONFIG  {
    UCHAR interface [64];
    int   port;
    UCHAR filler[1024];
    int   mainSocket;
    int   clientSocket;
    UCHAR rmtHost [32];
    ULONG rmtTcpIp;
    int   rmtPort;
    
} CONFIG,  *PCONFIG;


typedef _Packed struct _REQUEST  {
    PCONFIG pConfig;
    UCHAR   contentType  [128];
} REQUEST , *PREQUEST;

typedef _Packed struct _RESPONSE  {
    PCONFIG pConfig;
    SHORT   status;
    UCHAR   statusText  [128];
    UCHAR   contentType [128];
    UCHAR   charset     [32];
    // private
    UCHAR   filler      [512];
    BOOL    firstWrite;  
} RESPONSE , *PRESPONSE;

/* function pointers */
typedef  void (* SERVLET) (PREQUEST pRequest, PRESPONSE pResponse);

typedef _Packed struct _INSTANCE  {
   CONFIG  config;
   SERVLET servlet;
} INSTANCE,  *PINSTANCE;



/* ------------------------------------------------------------- */
/* Prototypes -------------------------------------------------- */
/* ------------------------------------------------------------- */
void putChunk (PRESPONSE pResponse, PUCHAR buf, int len);   
void putHeader (PRESPONSE pResponse);
      

#endif
