diff --git a/.gitignore b/.gitignore index 08ba2b884..d014b41cb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,3 @@ buildroot/output/ buildroot/*.config* -build/* -!build/tpi app/board/* diff --git a/app/bmc/Makefile b/app/bmc/Makefile deleted file mode 100755 index 10edb8ef4..000000000 --- a/app/bmc/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -CPPFLAGS += -LDLIBS += -L./lib/ -lpthread -lgo -lcjson -ltpi_rs -ldl -lm -lrt -lusb-1.0 - -all: bmc - -bmc: bmc.o comm_gpio.o param.o webserver.o comm_device_serial.o - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS) - #cp $@ ~/tftpboot/ - -clean: - rm -f *.o bmc - -.PHONY: all clean diff --git a/app/bmc/bmc.c b/app/bmc/bmc.c deleted file mode 100755 index c19f39dc1..000000000 --- a/app/bmc/bmc.c +++ /dev/null @@ -1,229 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "comm_gpio.h" -#include "t113_gpio.h" - -#include "webserver.h" -#include "param.h" -#include "bmc.h" - -#include "version.h" - -#include "comm_device_serial.h" - -#include - -char nodeType[4][128] = {"unknown", "unknown", "unknown", "unknown"}; - -NODE_CTX_t g_node_ctx[4]; - -/** - * @brief 0- unknown - * 1- raspberry - * 2- jetson - * 3- - */ - -char *allNodeType[] = - { - "unknown", - "raspberry pi", - "jetson"}; - -char *serail_path[4] = {"/dev/ttyS2", "/dev/ttyS1", "/dev/ttyS4", "/dev/ttyS5"}; - -char *dev_keys[] = {"raspberry", "ttyTHS"}; - -int analysis_nodeType_proc(char *data, int num) -{ - int ret; - char *tmp = NULL; - char buff[256]; - memset(buff, 0, sizeof(buff)); - strcpy(buff,data); - if (strstr(buff, dev_keys[0])) - { - sprintf(nodeType[num], "[raspberry pi]"); - printf("get raspberry dev\n"); - } - if ((tmp = strstr(buff, dev_keys[1]))) - { - *tmp = 0; - sprintf(nodeType[num], "[jetson]-%s", buff); - printf("get jetson dev\n"); - } - return 0; -} - -int add_buff(NODE_BUFF_CTX_t* bctx,char* data) -{ - int len = 0; - if(NULL==bctx||NULL==data) - return -1; - len = strlen(data); - pthread_mutex_lock(&bctx->lock); - if(bctx->offset+len >= BUFF_MAX_SIZE) - { - memset(bctx->buff,0,BUFF_MAX_SIZE); - bctx->offset = 0; - } - strcpy(&bctx->buff[bctx->offset],data); - bctx->offset += len; - pthread_mutex_unlock(&bctx->lock); - return 0; -} - -int get_buff(int index,char* data,int len) -{ - int ret = 0; - if(index<0||index>3) - return -1; - NODE_BUFF_CTX_t* bctx = &g_node_ctx[index].data; - if(NULL==bctx||NULL==data||len<10) - return -1; - pthread_mutex_lock(&bctx->lock); - if(bctx->offsetbuff); - memset(bctx->buff,0,bctx->offset); - ret = bctx->offset; - bctx->offset = 0; - - } - else - { - strncpy(data,bctx->buff,len-1); - data[len-1] = 0; - memset(bctx->buff,0,bctx->offset); - bctx->offset = 0; - ret = len-1; - } - pthread_mutex_unlock(&bctx->lock); - return ret; -} - - -int uart_write(int index,char *data,int len) -{ - char* enter = "\r\n"; - int ret = 0; - if(index<0||index>3) - return -1; - if(NULL==data||len<0) - return -2; - int fd = g_node_ctx[index].fd; - if(fd<0) - { - printf("uart_write fd < 0\n"); - return -1; - } - ret = write(fd,data,len); - write(fd,enter,strlen(enter)); - return ret; -} - -void *sigle_uart_thread_proc(void *arg) -{ - pthread_detach(pthread_self()); - - int nodenum = *(int *)arg; - // printf("arg = %d\n",nodenum); - printf("start uart thread node num = %d----\n", nodenum); - - fd_set sfd; - int i; - char buff[1024]; - int fd = g_node_ctx[nodenum].fd; - if(fd<0) - { - printf("fd < 0\n"); - return NULL; - } - int ret = 0; - sleep(1); - while (true) - { - // get uart enable - FD_ZERO(&sfd); - FD_SET(fd, &sfd); - struct timeval tt; - tt.tv_sec = 1; - tt.tv_usec = 0; - ret = select(fd + 1, &sfd, NULL, NULL, &tt); - if (ret > 0) - { - if (FD_ISSET(fd, &sfd)) - { - memset(buff,0,sizeof(buff)); - ret = read(fd, buff, sizeof(buff)); - add_buff(&g_node_ctx[nodenum].data,buff); - // printf("recv num:%d,len:%d,buff=%s\n", nodenum, ret, buff); - analysis_nodeType_proc(buff, nodenum); - } - } - } - return NULL; -} - -char *get_nodeType(int num) -{ - return nodeType[num]; -} - -void node_uart_init() -{ - int i; - int fd = -1; - for (i = 0; i < 4; ++i) - { - memset(&g_node_ctx[i], 0, sizeof(NODE_CTX_t)); - fd = -1; - g_node_ctx[i].index = i; - strncpy(g_node_ctx[i].path, serail_path[i], sizeof(g_node_ctx[i].path)); - if (0 != common_device_UartOpen(&fd, serail_path[i])) - { - fd = -1; - g_node_ctx[i].fd = fd; - printf("open %s faild\n", serail_path[i]); - // return ; - continue; - } - common_device_UartSetAttr(fd, 115200, 8, 'n', 1); - g_node_ctx[i].fd = fd; - pthread_mutex_init(&g_node_ctx[i].data.lock, NULL); - } -} - -int main(int argc, char *argv[]) -{ - printf("Hello bmc start build time = %s-%s\n", __TIME__, __DATE__); - printf("bmc version:v%s\n", BMCVERSION); - - tpi_initialize(); - - int ret = -1; - int i; - pthread_t pid, piduart; - init_env(); - - node_uart_init(); - - - int chn[4] = {0, 1, 2, 3}; - for (i = 0; i < 4; ++i) - { - ret = pthread_create(&piduart, NULL, sigle_uart_thread_proc, &chn[i]); - } - - printf("pthread end\n"); - webstart(); - return 0; -} diff --git a/app/bmc/bmc.h b/app/bmc/bmc.h deleted file mode 100644 index fe2b56a8e..000000000 --- a/app/bmc/bmc.h +++ /dev/null @@ -1,43 +0,0 @@ -/** - * @file bmc.h - * @author wenyi (wenyi0421@163.com) - * @brief - * @version 0.1 - * @date 2022-09-09 - * - * @copyright Copyright (c) 2022 - * - */ - - -#ifndef __BMC_H__ -#define __BMC_H__ - -#include - - -#define BUFF_MAX_SIZE (64*1024) - -typedef struct _NODE_BUFF_CTX_t -{ - pthread_mutex_t lock; - int offset; - char buff[BUFF_MAX_SIZE]; -}NODE_BUFF_CTX_t; - - -typedef struct _NODE_CTX_t -{ - int index; - int fd; - char path[64]; - NODE_BUFF_CTX_t data; -}NODE_CTX_t; - -char* get_nodeType(int num); - -int get_buff(int index,char* data,int len); - -int uart_write(int index,char *data,int len); - -#endif // !__BMC_H__ diff --git a/app/bmc/comm_device_serial.c b/app/bmc/comm_device_serial.c deleted file mode 100644 index fb86fc601..000000000 --- a/app/bmc/comm_device_serial.c +++ /dev/null @@ -1,195 +0,0 @@ -/******************************************************************************** -* File : -* Intro : -* Author : -* Version : v1.0 -* Notes : -* Change History : -Date Version Changed By Changes -* -------------------------------------------------------------------------------- -2018-12-20 v0.1 create - -* Copyright(c) -*******************************************************************************/ -#include -#include -#include -#include -#include - -#include "comm_device_serial.h" - -/************************************************************************* -* Function implementation * -**************************************************************************/ -/************************************************************** -**Describe: 打开串口节结 -**Input: int *fd:打开的设备节点的文件描述符 ; - char *dev:设备节点的名称 -**Ouput: -**Return: 0:success -1 :Fail -*************************************************************************/ -char common_device_UartOpen(int *fd,char *dev) -{ - *fd = open(dev, O_RDWR|O_NOCTTY|O_NDELAY); - - if((*fd) < 0) - { - printf("\r\n common_device_UaritOpen Error! Dev=%s \r\n",dev); - return -1; - } - else - { - return 0; - } -} - -/************************************************************** -**Describe: 关闭串口节结 -**Input: int fd: 要关闭的设备节点的文件描述符 ; -**Ouput: -**Return: 0:success -1 :Fail -**************************************************************/ -char common_device_UartClose(int fd) -{ - int ret=0; /*0:表示成功; -1 :表示失败*/ - ret = close(fd); - - if(ret == -1) - { - printf("\r\n common_device_UaritClose Error! fd=%d \r\n",fd); - } - return ret; -} - -/************************************************************** -**Describe: 设置串口属性 -**Input: int fd:文件描述符 int nSpeed:波特率 int nBits:数据位 - char nEvent:奇偶校验 int nStop:停止位 -**Ouput: -**Return: 0->Sucess -1 ->Fail -**************************************************************/ -int common_device_UartSetAttr(int fd,int nSpeed, int nBits, char nEvent, int nStop) -{ - struct termios newtio,oldtio; - - if(tcgetattr( fd,&oldtio)!=0) /*保存现有串口参数设置*/ - { - printf("tcgetattr(fd,&oldtio) -> %d\n",tcgetattr( fd,&oldtio)); - return -1; - } - memset( &newtio, 0,sizeof( newtio ) ); - - newtio.c_cflag |= CLOCAL | CREAD; - newtio.c_cflag &= ~CSIZE; - - /*设置停止位*/ - switch( nBits ) - { - case 5: - newtio.c_cflag |= CS5; /*Every char is 5BIT */ - break; - case 6: - newtio.c_cflag |= CS6; /*Every char is 6BIT */ - break; - case 7: - newtio.c_cflag |= CS7; /*Every char is 7BIT */ - break; - case 8: - newtio.c_cflag |= CS8; /*Every char is 8BIT */ - break; - } - - /*设置奇偶校验位*/ - switch( nEvent ) - { - case 'o': - case 'O': //奇数 - newtio.c_cflag |= PARENB; - newtio.c_cflag |= PARODD; - newtio.c_iflag |= (INPCK | ISTRIP); - break; - case 'e': - case 'E': //偶数 - newtio.c_iflag |= (INPCK | ISTRIP); - newtio.c_cflag |= PARENB; - newtio.c_cflag &= ~PARODD; - break; - case 'n': - case 'N': //无奇偶校验位 - newtio.c_cflag &= ~PARENB; - break; - default: - break; - } - - /*设置波特率*/ - switch( nSpeed ) - { - case 2400: - cfsetispeed(&newtio, B2400); - cfsetospeed(&newtio, B2400); - break; - case 4800: - cfsetispeed(&newtio, B4800); - cfsetospeed(&newtio, B4800); - break; - case 9600: - cfsetispeed(&newtio, B9600); - cfsetospeed(&newtio, B9600); - break; - case 19200: - cfsetispeed(&newtio, B19200); - cfsetospeed(&newtio, B19200); - break; - case 38400: - cfsetispeed(&newtio, B38400); - cfsetospeed(&newtio, B38400); - break; - case 57600: - cfsetispeed(&newtio, B57600); - cfsetospeed(&newtio, B57600); - break; - case 115200: - cfsetispeed(&newtio, B115200); - cfsetospeed(&newtio, B115200); - break; - case 460800: - cfsetispeed(&newtio, B460800); - cfsetospeed(&newtio, B460800); - break; - default: - cfsetispeed(&newtio, B9600); - cfsetospeed(&newtio, B9600); - break; - } - - /*设置停止位*/ - if( nStop == 1 ) - newtio.c_cflag &= ~CSTOPB; - else if ( nStop == 2 ) - newtio.c_cflag |= CSTOPB; - - /*设置等待时间和最小接收字符*/ - newtio.c_cc[VTIME] = 0; - newtio.c_cc[VMIN] = 0; - - /*处理未接收字符*/ - tcflush(fd,TCIFLUSH); - /*激活新配置*/ - if((tcsetattr(fd,TCSANOW,&newtio))!=0) - { - perror("com set error"); - return -1; - } - // printf("set done!\n"); - return 0; -} - - - - - - - - diff --git a/app/bmc/comm_device_serial.h b/app/bmc/comm_device_serial.h deleted file mode 100644 index 418606585..000000000 --- a/app/bmc/comm_device_serial.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef __COMMON_DEVICE_UART_H__ -#define __COMMON_DEVICE_UART_H__ - -// #include "commonLib.h" - -char common_device_UartOpen(int *fd,char *dev); -char common_device_UartClose(int fd); -int common_device_UartSetAttr(int fd,int nSpeed, int nBits, char nEvent, int nStop); - -#endif - - - diff --git a/app/bmc/comm_gpio.c b/app/bmc/comm_gpio.c deleted file mode 100755 index 5199ed2a6..000000000 --- a/app/bmc/comm_gpio.c +++ /dev/null @@ -1,183 +0,0 @@ -/******************************************************************************** -* File : -* Intro : -* Author : -* Version : v1.0 -* Notes : -* Change History : -Date Version Changed By Changes -* -------------------------------------------------------------------------------- -2018-12-20 v0.1 create - -* Copyright(c) -*******************************************************************************/ - -#include -#include -#include - - - -#include "comm_gpio.h" - -/************************************************************************* -* global variable * -**************************************************************************/ -static pthread_mutex_t gpio_lock = PTHREAD_MUTEX_INITIALIZER; - - -/************************************************************************* -* Function implementation * -**************************************************************************/ -/************************************************************** -**Describe: Open operation gpio node,and set the direction -**Input: gpio_num Operation Gpio num; - direct: 0->output 1-> input -**Ouput: -**Return: 0:success -1 :Fail -*************************************************************************/ -char common_device_gpioOpen(unsigned int gpio_num,bool direct) -{ - FILE *fp; - char file_name[50]; - - - pthread_mutex_lock(&gpio_lock); - - //open operation giop node - sprintf(file_name, "/sys/class/gpio/export"); - fp = fopen(file_name, "w"); - if (fp == NULL) - { - printf("Cannot open %s.\n", file_name); - return -1; - } - fprintf(fp, "%d", gpio_num); - fclose(fp); - - //set gpio direct - sprintf(file_name, "/sys/class/gpio/gpio%d/direction", gpio_num); - fp = fopen(file_name, "rb+"); - if (fp == NULL) - { - printf("Cannot open %s.\n", file_name); - return -1; - } - if(direct == 0) - { - fprintf(fp, "out"); - } - else - { - fprintf(fp, "in"); - } - - fclose(fp); - - pthread_mutex_unlock(&gpio_lock); - - return 0; -} - -/************************************************************** -**Describe: Close operation gpio node -**Input: gpio_num Operation Gpio num; -**Ouput: -**Return: 0:success -1 :Fail -**************************************************************/ -char common_device_gpioClose(unsigned int gpio_unm) -{ - FILE *fp; - char file_name[50]; - - sprintf(file_name, "/sys/class/gpio/unexport"); - fp = fopen(file_name, "w"); - if(fp == NULL) - { - printf("Cannot open %s.\n", file_name); - return -1; - } - fprintf(fp, "%d", gpio_unm); - fclose(fp); - - return 0; -} - -/************************************************************** -**Describe: Set gpio output value -**Input: gpio_num Operation Gpio num; - value: 0->L 1-> H -**Ouput: -**Return: 0:success -1 :Fail -**************************************************************/ -char common_device_gpioWirte(unsigned int gpio_num,bool value) -{ - FILE *fp; - char file_name[50]; - unsigned char buf[2]; - - - pthread_mutex_lock(&gpio_lock); - - //set gpio H or L - sprintf(file_name, "/sys/class/gpio/gpio%d/value", gpio_num); - fp = fopen(file_name, "rb+"); - if (fp == NULL) - { - printf("Cannot open %s.\n", file_name); - return -1; - } - - if (value == GPIO_H) - strcpy(buf,"1"); - else - strcpy(buf,"0"); - - fwrite(buf, sizeof(char), sizeof(buf) - 1, fp); - - //printf("%s: gpio%d_%d = %s\n", __func__,gpio_num/8, gpio_num%8, buf); - - fclose(fp); - - pthread_mutex_unlock(&gpio_lock); - - return 0; -} - -/************************************************************** -**Describe: Get gpio input value -**Input: gpio_num Operation Gpio num; -**Ouput: -**Return: value: 0->L 1-> H -1 ->Fail -**************************************************************/ -char common_device_gpioRead(unsigned int gpio_num) -{ - FILE *fp; - char file_name[50]; - unsigned char buf[2]; - - - pthread_mutex_lock(&gpio_lock); - - sprintf(file_name, "/sys/class/gpio/gpio%d/value", gpio_num); - fp = fopen(file_name, "rb+"); - if (fp == NULL) { - printf("Cannot open %s.\n", file_name); - return -1; - } - memset(buf, 0, 2); - fread(buf, sizeof(char), sizeof(buf) - 1, fp); - - //printf("%s: gpio%d_%d = %d \n", __func__,gpio_num/8, gpio_num%8, buf[0]-48); - - fclose(fp); - - pthread_mutex_unlock(&gpio_lock); - - if(buf[0] == '1') - return GPIO_H; - else if(buf[0] == '0') - return GPIO_L; - else - return -1; -} \ No newline at end of file diff --git a/app/bmc/comm_gpio.h b/app/bmc/comm_gpio.h deleted file mode 100755 index 75f2d9163..000000000 --- a/app/bmc/comm_gpio.h +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************** -* File : -* Intro : -* Author : -* Version : v1.0 -* Notes : -* Change History : -Date Version Changed By Changes -* -------------------------------------------------------------------------------- -2018-12-20 v0.1 create - -* Copyright(c) -*******************************************************************************/ - - -#ifndef __COMM_GPIO_H__ -#define __COMM_GPIO_H__ - -#include - -#define GPIO_IN 1 -#define GPIO_OUT 0 - -#define GPIO_H 1 -#define GPIO_L 0 - - -char common_device_gpioOpen(unsigned int gpio_num,bool direct); -char common_device_gpioClose(unsigned int gpio_unm); -char common_device_gpioWirte(unsigned int gpio_num,bool value); -char common_device_gpioRead(unsigned int gpio_num); - - -#endif diff --git a/app/bmc/inc/goahead.h b/app/bmc/inc/goahead.h deleted file mode 100644 index d270e8241..000000000 --- a/app/bmc/inc/goahead.h +++ /dev/null @@ -1,4226 +0,0 @@ -/* - goahead.h -- GoAhead Web Server Header - - Copyright (c) All Rights Reserved. See details at the end of the file. - */ - -#ifndef _h_GOAHEAD -#define _h_GOAHEAD 1 - -/************************************ Overrides *******************************/ -/* - Override osdep defaults - */ -#define ME_MAX_IP 64 /**< Maximum IP address size */ - -/************************************ Includes ********************************/ - -#include "me.h" -#include "osdep.h" - -/************************************ Defaults ********************************/ - -#ifdef __cplusplus -extern "C" { -#endif - - -#if (ME_COM_MBEDTLS + ME_COM_MATRIXSSL + ME_COM_NANOSSL + ME_COM_OPENSSL) > 1 -#error "Cannot have more than one SSL provider configured" -#endif - -#ifndef ME_GOAHEAD_LOGGING -#define ME_GOAHEAD_LOGGING 1 /**< Default for logging is "on" */ -#endif -#ifndef ME_GOAHEAD_TRACING -#define ME_GOAHEAD_TRACING 1 /**< Default for tracing "on" */ -#endif -#ifndef ME_GOAHEAD_DEBUG -#if ME_DEBUG -#define ME_GOAHEAD_DEBUG 1 /**< Debug logging on in debug builds by default */ -#else -#define ME_GOAHEAD_DEBUG 0 -#endif -#endif -#if ECOS -#if ME_GOAHEAD_CGI -#error "Ecos does not support CGI. Disable ME_GOAHEAD_CGI" -#endif -#endif /* ECOS */ - -#if QNX -typedef long fd_mask; -#define NFDBITS (sizeof (fd_mask) * NBBY) /* bits per mask */ -#endif - -#if MACOSX -typedef int32_t fd_mask; -#endif -#if WINDOWS -typedef fd_set fd_mask; -#endif - -#if !LINUX -PUBLIC char *basename(char *name); -#endif - -#if VXWORKS -PUBLIC int vxchdir(char *dirname); -#endif - -#if DOXYGEN -typedef int Socket; -typedef int Socklen; -typedef int64 Offset; -#endif - -/** - File status structure - */ -typedef struct stat WebsStat; - -/* - Copyright. The software license requires that this not be modified or removed. - */ -#define EMBEDTHIS_GOAHEAD_COPYRIGHT \ - "Copyright (c) Embedthis Software Inc., 1993-2014. All Rights Reserved." \ - "Copyright (c) GoAhead Software Inc., 2003. All Rights Reserved." - -/************************************* Main ***********************************/ - -#define ME_MAX_ARGC 32 -#if VXWORKS -#define MAIN(name, _argc, _argv, _envp) \ - static int innerMain(int argc, char **argv, char **envp); \ - int name(char *arg0, ...) { \ - va_list args; \ - char *argp, *largv[ME_MAX_ARGC]; \ - int largc = 0; \ - va_start(args, arg0); \ - largv[largc++] = #name; \ - if (arg0) { \ - largv[largc++] = arg0; \ - } \ - for (argp = va_arg(args, char*); argp && largc < ME_MAX_ARGC; argp = va_arg(args, char*)) { \ - largv[largc++] = argp; \ - } \ - return innerMain(largc, largv, NULL); \ - } \ - static int innerMain(_argc, _argv, _envp) -#elif ME_WIN_LIKE -#define MAIN(name, _argc, _argv, _envp) \ - APIENTRY WinMain(HINSTANCE inst, HINSTANCE junk, char *command, int junk2) { \ - extern int main(); \ - char *largv[ME_MAX_ARGC]; \ - int largc; \ - largc = websParseArgs(command, &largv[1], ME_MAX_ARGC - 1); \ - largv[0] = #name; \ - main(largc, largv, NULL); \ - } \ - int main(_argc, _argv, _envp) -#else -#define MAIN(name, _argc, _argv, _envp) int main(_argc, _argv, _envp) -#endif - -PUBLIC int websParseArgs(char *args, char **argv, int maxArgc); - -#if WINDOWS -PUBLIC void websSetInst(HINSTANCE inst); -PUBLIC HINSTANCE websGetInst(); -#endif - -/************************************ Tunables ********************************/ - -#define WEBS_MAX_LISTEN 8 /**< Maximum number of listen endpoints */ -#define WEBS_SMALL_HASH 31 /**< General small hash size */ -#define WEBS_MAX_PASSWORD 32 /**< Default maximum password */ - -/************************************* Error **********************************/ -#if ME_GOAHEAD_LOGGING - -#define WEBS_L __FILE__, __LINE__ -#define WEBS_ARGS_DEC char *file, int line -#define WEBS_ARGS file, line - -PUBLIC_DATA int logLevel; - -/** - Standard logging trace levels are 0 to 9 with 0 being the most verbose. These are ored with the error source - and type flags. The WEBS_LOG_MASK is used to extract the trace level from a flags word. We expect most apps - to run with level 2 trace enabled. -*/ -#define WEBS_ERROR 1 /**< Hard error trace level */ -#define WEBS_WARN 2 /**< Soft warning trace level */ -#define WEBS_CONFIG 2 /**< Configuration settings trace level. */ -#define WEBS_VERBOSE 9 /**< Highest level of trace */ -#define WEBS_LEVEL_MASK 0xF /**< Level mask */ - -/* - Log message flags - */ -#define WEBS_ASSERT_MSG 0x10 /**< Originated from assert */ -#define WEBS_ERROR_MSG 0x20 /**< Originated from error */ -#define WEBS_LOG_MSG 0x100 /**< Originated from logmsg */ -#define WEBS_RAW_MSG 0x200 /**< Raw message output */ -#define WEBS_TRACE_MSG 0x400 /**< Originated from trace */ - - -#if ME_GOAHEAD_TRACING && ME_GOAHEAD_LOGGING -#if ME_COMPILER_HAS_MACRO_VARARGS -#define trace(l, ...) if (((l) & WEBS_LEVEL_MASK) <= websGetLogLevel()) { traceProc(l, __VA_ARGS__); } else {} -#else -inline void trace(int level, cchar *fmt, ...) -{ - WebsLogHandler logHandler = logGetHandler(); - if ((level & WEBS_LEVEL_MASK) <= logLevel && logHandler) - { - va_list args; - va_start(args, fmt); - char *message = sfmtv((char*) fmt, args); - logHandler(level | WEBS_TRACE_MSG, message); - wfree(message); - va_end(args); - } -} -#endif -#else -#define trace(l, ...) if (1) ; else {} -#endif - -#if ME_GOAHEAD_LOGGING -#if ME_COMPILER_HAS_MACRO_VARARGS -#define logmsg(l, ...) if ((l) <= logLevel) { logmsgProc(l, __VA_ARGS__); } else {} -#else -inline void logmsg(int level, cchar *fmt, ...) -{ - WebsLogHandler logHandler = logGetHandler(); - if ((level & WEBS_LEVEL_MASK) <= logLevel && logHandler) - { - va_list args; - va_start(args, fmt); - char *message = sfmtv((char*) fmt, args); - logHandler(level | WEBS_TRACE_MSG, message); - wfree(message); - va_end(args); - } -} -#endif -#else -#define logmsg(l, ...) if (1) ; else {} -#endif - - -#if DOXYGEN -#undef assert -/** - Assure that an assert condition is true - @param cond Boolean result of a conditional test - @stability Stable - */ -extern void assert(bool cond); -#elif ME_GOAHEAD_DEBUG -#define assert(C) if (C) ; else assertError(WEBS_L, "%s", #C) //hisi -PUBLIC void assertError(WEBS_ARGS_DEC, char *fmt, ...); -#else -#define assert(C) if (1) ; else {} //hisi -#endif - -// Deprecated 3.1 -#if DEPRECATED -#define traceOpen logOpen -#define traceClose logClose -#define WebsTraceHandler WebLogHandler -#define traceSetPath logSetPath -#define websGetTraceLevel websGetLogLevel -#endif - -/** - Callback for emitting trace log output - @param level Integer between 0 and 9. Zero is the lowest trace level used for the most important messages. - @param msg Message to log - @return Zero if successful - @internal - */ -typedef void (*WebsLogHandler)(int level, char *msg); - -/** - Emit an error message - @return Zero if successful - @stability Stable -*/ -PUBLIC void error(char *fmt, ...); - -/** - Open the log logging module - @return Zero if successful - @internal - */ -PUBLIC int logOpen(); - -/** - Close the log logging module - @internal - */ -PUBLIC void logClose(); - -/** - Get the log callback - @return handler Callback handler function of type WebsLogHandler - @stability Stable - */ -PUBLIC WebsLogHandler logGetHandler(); - -/** - Set a log callback - @param handler Callback handler function of type WebsLogHandler - @return The previous callback function - @stability Stable - */ -PUBLIC WebsLogHandler logSetHandler(WebsLogHandler handler); - -/** - Get the current trace log level - @return Number between 0 and 9 - @ingroup Webs - @stability Stable - */ -PUBLIC int websGetLogLevel(); - -/** - Set the current trace log level - @return Number between 0 and 9 - @ingroup Webs - @stability Prototype - */ -void websSetLogLevel(int level); - -/** - Set the filename to save logging output - @param path Filename path to use - @stability Stable - */ -PUBLIC void logSetPath(char *path); - -/** - Emit a message to the log - @description This emits a message at the specified level. GoAhead filters logging messages by defining a verbosity - level at startup. Level 0 is the least verbose where only the most important messages will be output. Level 9 is the - Logging support is enabled by the MakeMe setting: "logging: true" which creates the ME_GOAHEAD_LOGGING define in me.h - most verbose. Level 2-4 are the most useful for debugging. - @param level Integer verbosity level (0-9). - @param fmt Printf style format string - @param ... Arguments for the format string - @stability Stable - */ -PUBLIC void logmsgProc(int level, char *fmt, ...); - -/** - Emit a debug trace message to the log - @description This emits a message at the specified level. GoAhead filters logging messages by defining a verbosity - level at startup. Level 0 is the least verbose where only the most important messages will be output. Level 9 is the - most verbose. Level 2-4 are the most useful for debugging. - Debug trace support is enabled by the MakeMe setting: "tracing: true" which creates the ME_GOAHEAD_TRACING define in - me.h. - @param level Integer verbosity level (0-9). - @param fmt Printf style format string - @param ... Arguments for the format string - @stability Stable - */ -PUBLIC void traceProc(int level, char *fmt, ...); - -#else /*! ME_GOAHEAD_LOGGING */ -#define assert(C) if (1) ; else {} -#define error(l, ...) if (1) ; else {} -#define trace(l, ...) if (1) ; else {} -#define logOpen() if (1) ; else {} -#define logClose() if (1) ; else {} -#define websGetLogLevel() 0 -#define logmsg(l, ...) if (1) ; else {} -#define logSetPath(p) if (1) ; else {} -#endif - -/*********************************** HTTP Codes *******************************/ -/* - Standard HTTP/1.1 status codes - */ -#define HTTP_CODE_CONTINUE 100 /**< Continue with request, only partial content transmitted */ -#define HTTP_CODE_OK 200 /**< The request completed successfully */ -#define HTTP_CODE_CREATED 201 /**< The request has completed and a new resource was created */ -#define HTTP_CODE_ACCEPTED 202 /**< The request has been accepted and processing is continuing */ -#define HTTP_CODE_NOT_AUTHORITATIVE 203 /**< The request has completed but content may be from another source */ -#define HTTP_CODE_NO_CONTENT 204 /**< The request has completed and there is no response to send */ -#define HTTP_CODE_RESET 205 /**< The request has completed with no content. Client must reset view */ -#define HTTP_CODE_PARTIAL 206 /**< The request has completed and is returning partial content */ -#define HTTP_CODE_MOVED_PERMANENTLY 301 /**< The requested URI has moved permanently to a new location */ -#define HTTP_CODE_MOVED_TEMPORARILY 302 /**< The URI has moved temporarily to a new location */ -#define HTTP_CODE_SEE_OTHER 303 /**< The requested URI can be found at another URI location */ -#define HTTP_CODE_NOT_MODIFIED 304 /**< The requested resource has changed since the last request */ -#define HTTP_CODE_USE_PROXY 305 /**< The requested resource must be accessed via the location proxy */ -#define HTTP_CODE_TEMPORARY_REDIRECT 307 /**< The request should be repeated at another URI location */ -#define HTTP_CODE_BAD_REQUEST 400 /**< The request is malformed */ -#define HTTP_CODE_UNAUTHORIZED 401 /**< Authentication for the request has failed */ -#define HTTP_CODE_PAYMENT_REQUIRED 402 /**< Reserved for future use */ -#define HTTP_CODE_FORBIDDEN 403 /**< The request was legal, but the server refuses to process */ -#define HTTP_CODE_NOT_FOUND 404 /**< The requested resource was not found */ -#define HTTP_CODE_BAD_METHOD 405 /**< The request HTTP method was not supported by the resource */ -#define HTTP_CODE_NOT_ACCEPTABLE 406 /**< The requested resource cannot generate the required content */ -#define HTTP_CODE_REQUEST_TIMEOUT 408 /**< The server timed out waiting for the request to complete */ -#define HTTP_CODE_CONFLICT 409 /**< The request had a conflict in the request headers and URI */ -#define HTTP_CODE_GONE 410 /**< The requested resource is no longer available*/ -#define HTTP_CODE_LENGTH_REQUIRED 411 /**< The request did not specify a required content length*/ -#define HTTP_CODE_PRECOND_FAILED 412 /**< The server cannot satisfy one of the request preconditions */ -#define HTTP_CODE_REQUEST_TOO_LARGE 413 /**< The request is too large for the server to process */ -#define HTTP_CODE_REQUEST_URL_TOO_LARGE 414 /**< The request URI is too long for the server to process */ -#define HTTP_CODE_UNSUPPORTED_MEDIA_TYPE 415 /**< The request media type is not supported by the server or resource */ -#define HTTP_CODE_RANGE_NOT_SATISFIABLE 416 /**< The request content range does not exist for the resource */ -#define HTTP_CODE_EXPECTATION_FAILED 417 /**< The server cannot satisfy the Expect header requirements */ -#define HTTP_CODE_NO_RESPONSE 444 /**< The connection was closed with no response to the client */ -#define HTTP_CODE_INTERNAL_SERVER_ERROR 500 /**< Server processing or configuration error. No response generated */ -#define HTTP_CODE_NOT_IMPLEMENTED 501 /**< The server does not recognize the request or method */ -#define HTTP_CODE_BAD_GATEWAY 502 /**< The server cannot act as a gateway for the given request */ -#define HTTP_CODE_SERVICE_UNAVAILABLE 503 /**< The server is currently unavailable or overloaded */ -#define HTTP_CODE_GATEWAY_TIMEOUT 504 /**< The server gateway timed out waiting for the upstream server */ -#define HTTP_CODE_BAD_VERSION 505 /**< The server does not support the HTTP protocol version */ -#define HTTP_CODE_INSUFFICIENT_STORAGE 507 /**< The server has insufficient storage to complete the request */ - -/* - Proprietary HTTP status codes - */ -#define HTTP_CODE_START_LOCAL_ERRORS 550 -#define HTTP_CODE_COMMS_ERROR 550 /**< The server had a communicationss error responding to the client */ - -/************************************* WebsValue ******************************/ -/** - Value types. - */ -typedef enum WebsType -{ - undefined = 0, - byteint = 1, - shortint = 2, - integer = 3, - hex = 4, - percent = 5, - octal = 6, - big = 7, - flag = 8, - floating = 9, - string = 10, - bytes = 11, - symbol = 12, - errmsg = 13 -} WebsType; - -/** - System native time type. This is the time in seconds. - This may be 32 or 64 bits and may be signed or unsigned on some systems. - */ -typedef time_t WebsTime; - -/** - Value union to store primitive value types - */ -typedef struct WebsValue -{ - union - { - char flag; - char byteint; - short shortint; - char percent; - long integer; - long hex; - long octal; - long big[2]; -#if ME_FLOAT - double floating; -#endif - char *string; - char *bytes; - char *errmsg; - void *symbol; - } value; - WebsType type; - uint valid : 8; - uint allocated : 8; /* String was allocated */ -} WebsValue; - -/** - The value is a numeric type - */ -#define value_numeric(t) (t >= byteint && t <= big) - -/** - The value is a string type - */ -#define value_str(t) (t >= string && t <= bytes) - -/** - The value is valid supported type - */ -#define value_ok(t) (t > undefined && t <= symbol) - -/** - Allocate strings using malloc - */ -#define VALUE_ALLOCATE 0x1 - -/** - Create an integer value - @param value Integer long value - @return Value object containing the integer - @stability Stable - */ -PUBLIC WebsValue valueInteger(long value); - -/** - Create an string value - @param value String long value - @param flags Set to VALUE_ALLOCATE to store a copy of the string reference - @return Value object containing the string - @stability Stable - */ -PUBLIC WebsValue valueString(char *value, int flags); - -/** - Create an symbol value containing an object reference - @param value Value reference - @return Value object containing the symbol reference - @stability Stable - */ -PUBLIC WebsValue valueSymbol(void *value); - -/** - Free any allocated string in a value - @param value Value object - @stability Stable - */ -PUBLIC void valueFree(WebsValue *value); - -/************************************* Ringq **********************************/ -/** - A WebsBuf (ring queue) allows maximum utilization of memory for data storage and is - ideal for input/output buffering. This module provides a highly effecient - implementation and a vehicle for dynamic strings. - \n\n - WARNING: This is a public implementation and callers have full access to - the queue structure and pointers. Change this module very carefully. - \n\n - This module follows the open/close model. - \n\n - Operation of a WebsBuf where bp is a pointer to a WebsBuf : - - bp->buflen contains the size of the buffer. - bp->buf will point to the start of the buffer. - bp->servp will point to the first (un-consumed) data byte. - bp->endp will point to the next free location to which new data is added - bp->endbuf will point to one past the end of the buffer. - \n\n - Eg. If the WebsBuf contains the data "abcdef", it might look like : - \n\n - +-------------------------------------------------------------------+ - | | | | | | | | a | b | c | d | e | f | | | | | - +-------------------------------------------------------------------+ - ^ ^ ^ ^ - | | | | - bp->buf bp->servp bp->endp bp->enduf - \n\n - The queue is empty when servp == endp. This means that the queue will hold - at most bp->buflen -1 bytes. It is the fillers responsibility to ensure - the WebsBuf is never filled such that servp == endp. - \n\n - It is the fillers responsibility to "wrap" the endp back to point to - bp->buf when the pointer steps past the end. Correspondingly it is the - consumers responsibility to "wrap" the servp when it steps to bp->endbuf. - The bufPutc and bufGetc routines will do this automatically. - @defgroup WebsBuf WebsBuf - @stability Stable - */ -typedef struct WebsBuf -{ - char *buf; /**< Holding buffer for data */ - char *servp; /**< Pointer to start of data */ - char *endp; /**< Pointer to end of data */ - char *endbuf; /**< Pointer to end of buffer */ - ssize buflen; /**< Length of ring queue */ - ssize maxsize; /**< Maximum size */ - int increment; /**< Growth increment */ -} WebsBuf; - -/** - Add a trailing null to the buffer. The end pointer is not changed. - @param bp Buffer reference - @ingroup WebsBuf - @stability Stable - */ -PUBLIC void bufAddNull(WebsBuf *bp); - -/** - Adjust the endp pointer by the specified size. - @description This is useful after manually copying data into the buffer and needing to adjust the end pointer. - @param bp Buffer reference - @param size Size of adjustment. May be positive or negative value. - @ingroup WebsBuf - @stability Stable - */ -PUBLIC void bufAdjustEnd(WebsBuf *bp, ssize size); - -/** - Adjust the start (servp) reference - @param bp Buffer reference - @param count Number of bytes to adjust - @ingroup WebsBuf - @stability Stable - */ -PUBLIC void bufAdjustStart(WebsBuf *bp, ssize count); - -/** - Compact the data in the buffer and move to the start of the buffer - @param bp Buffer reference - @ingroup WebsBuf - @stability Stable - */ -PUBLIC void bufCompact(WebsBuf *bp); - -/** - Create a buffer - @param bp Buffer reference - @param increment Incremental size to grow the buffer. This will be increased by a power of two each time - the buffer grows. - @param maxsize Maximum size of the buffer - @return Zero if successful - @ingroup WebsBuf - @stability Stable - */ -PUBLIC int bufCreate(WebsBuf *bp, int increment, int maxsize); - -/** - Flush all data in the buffer and reset the pointers. - @param bp Buffer reference - @ingroup WebsBuf - @stability Stable - */ -PUBLIC void bufFlush(WebsBuf *bp); - -/** - Free allocated storage for the buffer - @param bp Buffer reference - @return Zero if successful - @ingroup WebsBuf - @stability Stable - */ -PUBLIC void bufFree(WebsBuf *bp); - -/** - Copy a block of from the buffer and adjust the servp. - @param bp Buffer reference - @param blk Block into which to place the data - @param len Length of the block - @return Number of bytes copied. - @ingroup WebsBuf - @stability Stable - */ -PUBLIC ssize bufGetBlk(WebsBuf *bp, char *blk, ssize len); - -/** - Return the maximum number of bytes the buffer can provide via a single block copy. - @description Useful if the user is doing their own data retrieval. - @param bp Buffer reference - @return Number of bytes available for copying. - @ingroup WebsBuf - @stability Stable - */ -PUBLIC ssize bufGetBlkMax(WebsBuf *bp); - -/** - Get a character from the buffer and increment the servp - @param bp Buffer reference - @return The next character or -1 if the buffer is empty - @ingroup WebsBuf - @stability Stable - */ -PUBLIC int bufGetc(WebsBuf *bp); - -/** - Grow the buffer by at least the required amount of room - @param bp Buffer reference - @param room Available size required after growing the buffer - @return True if the buffer can be grown to have the required amount of room. - @ingroup WebsBuf - @stability Stable - */ -PUBLIC bool bufGrow(WebsBuf *bp, ssize room); - -/** - Get the length of available data in the buffer - @param bp Buffer reference - @return Size of available data in bytes - @ingroup WebsBuf - @stability Stable - */ -PUBLIC ssize bufLen(WebsBuf *bp); - -/** - Insert a character to the buffer before the servp position and decrement the servp - @param bp Buffer reference - @param c Character to insert - @return Zero if successful - @ingroup WebsBuf - @stability Stable - */ -PUBLIC int bufInsertc(WebsBuf *bp, char c); - -/** - Append a character to the buffer at the endp position and increment the endp - @param bp Buffer reference - @param c Character to append - @return Zero if successful - @ingroup WebsBuf - @stability Stable - */ -PUBLIC int bufPutc(WebsBuf *bp, char c); -/** - Put a block to the buffer. - @param bp Buffer reference - @param blk Block to append to the buffer - @param len Size of the block - @return Length of data appended. Should equal len. - @ingroup WebsBuf - @stability Stable - */ -PUBLIC ssize bufPutBlk(WebsBuf *bp, char *blk, ssize len); - -/** - Append a formatted string to the buffer at the endp position and increment the endp - @param bp Buffer reference - @param fmt Printf style format string - @param ... Variable arguments for the format string - @return Count of characters appended. Returns negative if there is an allocation error. - @ingroup WebsBuf - @stability Stable - */ -PUBLIC ssize bufPut(WebsBuf *bp, char *fmt, ...) PRINTF_ATTRIBUTE(2, 3); - -/** - Append a string to the buffer at the endp position and increment the endp - @param bp Buffer reference - @param str String to append - @return Count of characters appended. Returns negative if there is an allocation error. - @ingroup WebsBuf - @stability Stable - */ -PUBLIC ssize bufPutStr(WebsBuf *bp, char *str); - -/** - Reset the buffer pointers to the start of the buffer if empty - @param bp Buffer reference - @ingroup WebsBuf - @stability Stable - */ -PUBLIC void bufReset(WebsBuf *bp); - -/** - Determine the room available in the buffer. - @description This returns the maximum number of bytes the buffer can absorb in a single block copy. - @param bp Buffer reference - @return Number of bytes of availble space. - @ingroup WebsBuf - @stability Stable - */ -PUBLIC ssize bufRoom(WebsBuf *bp); - -/** - Get a reference to the start of buffer data - @param bp Buffer reference - @return A string pointer. - @ingroup WebsBuf - @stability Stable - */ -PUBLIC char *bufStart(WebsBuf *bp); - -/******************************* Malloc Replacement ***************************/ -#if ME_GOAHEAD_REPLACE_MALLOC -/** - GoAhead allocator memory block - Memory block classes are: 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536. - @defgroup WebsAlloc WebsAlloc - @stability Stable - */ -typedef struct WebsAlloc -{ - union - { - void *next; /**< Pointer to next in q */ - int size; /**< Actual requested size */ - } u; - int flags; /**< Per block allocation flags */ -} WebsAlloc; - -#define WEBS_DEFAULT_MEM (64 * 1024) /**< Default memory allocation */ -#define WEBS_MAX_CLASS 13 /**< Maximum class number + 1 */ -#define WEBS_SHIFT 4 /**< Convert size to class */ -#define WEBS_ROUND ((1 << (B_SHIFT)) - 1) -#define WEBS_MALLOCED 0x80000000 /* Block was malloced */ -#define WEBS_FILL_CHAR (0x77) /* Fill byte for buffers */ -#define WEBS_FILL_WORD (0x77777777) /* Fill word for buffers */ - -/* - Flags. The integrity value is used as an arbitrary value to fill the flags. - */ -#define WEBS_USE_MALLOC 0x1 /**< Okay to use malloc if required */ -#define WEBS_USER_BUF 0x2 /* User supplied buffer for mem */ -#define WEBS_INTEGRITY 0x8124000 /* Integrity value */ -#define WEBS_INTEGRITY_MASK 0xFFFF000 /* Integrity mask */ -#endif /* ME_GOAHEAD_REPLACE_MALLOC */ - -/** - Close the GoAhead memory allocator - @ingroup WebsAlloc - @stability Stable - */ -PUBLIC void wcloseAlloc(); - -/** - Initialize the walloc module. - @description The wopenAlloc function should be called the very first thing after the application starts and wclose - should be called the last thing before exiting. If wopenAlloc is not called, it will be called on the first allocation - with default values. "buf" points to memory to use of size "bufsize". If buf is NULL, memory is allocated using malloc. - flags may be set to WEBS_USE_MALLOC if using malloc is okay. This routine will allocate * an initial buffer of size - bufsize for use by the application. - @param buf Optional user supplied block of memory to use for allocations - @param bufsize Size of buf - @param flags Allocation flags. Set to WEBS_USE_MALLOC to permit the use of malloc() to grow memory. - @return Zero if successful, otherwise -1. - @ingroup WebsAlloc - @stability Stable - */ -PUBLIC int wopenAlloc(void *buf, int bufsize, int flags); - -/** - Allocate a block of the requested size - @param size Memory size required - @return A reference to the allocated block - @ingroup WebsAlloc - @stability Stable - */ -PUBLIC void *walloc(ssize size); - -/** - Free an allocated block of memory - @param blk Reference to the memory block to free. - @ingroup WebsAlloc - @stability Stable - */ -PUBLIC void wfree(void *blk); - -/** - Reallocate a block of memory and grow its size - @description If the new size is larger than the existing block, a new block will be allocated and the old data - will be copied to the new block. - @param blk Original block reference - @param newsize Size of the new block. - @return Reference to the new memory block - @ingroup WebsAlloc - @stability Stable - */ -PUBLIC void *wrealloc(void *blk, ssize newsize); - -/** - Duplicate memory - @param ptr Original block reference - @param usize Size to allocate - @return Reference to the new memory block - @ingroup WebsAlloc - */ -PUBLIC void *wdup(cvoid *ptr, size_t usize); - -typedef void (*WebsMemNotifier)(ssize size); - -/** - Define a global memory allocation notifier. - @description The notifier is called if any memory allocation fails. It is called with the requested allocation size - as its only parameter. - @param cback Callback function to invoke for allocation failures. - @ingroup WebsAlloc - @stability Evolving - */ -PUBLIC void websSetMemNotifier(WebsMemNotifier cback); - -#ifndef WEBS_SHIFT -#define WEBS_SHIFT 4 -#endif - -#if DEPRECATE || 1 -PUBLIC ssize mtow(wchar *dest, ssize count, char *src, ssize len); -PUBLIC ssize wtom(char *dest, ssize count, wchar *src, ssize len); -PUBLIC wchar *amtow(char *src, ssize *len); -PUBLIC char *awtom(wchar *src, ssize *len); -#endif - -/******************************* Hash Table *********************************/ -/** - Hash table entry structure. - @description The hash structure supports growable hash tables with high performance, collision resistant hashes. - Each hash entry has a descriptor entry. This is used to manage the hash table link chains. - @see hashCreate hashFree hashLookup hashEnter hashDelete hashWalk hashFirst hashNext - @defgroup WebsHash WebsHash - @stability Stable - */ -typedef struct WebsKey -{ - struct WebsKey *forw; /* Pointer to next hash list */ - WebsValue name; /* Name of symbol */ - WebsValue content; /* Value of symbol */ - int arg; /* Parameter value */ - int bucket; /* Bucket index */ -} WebsKey; - -/** - Hash table ID returned by hashCreate - */ -typedef int WebsHash; /* Returned by symCreate */ - -/** - Create a hash table - @param size Minimum size of the hash index - @return Hash table ID. Negative if the hash cannot be created. - @ingroup WebsHash - @stability Stable - */ -PUBLIC WebsHash hashCreate(int size); - -/** - Free a hash table - @param id Hash table id returned by hashCreate - @ingroup WebsHash - @stability Stable - */ -PUBLIC void hashFree(WebsHash id); - -/** - Lookup a name in the hash table - @param id Hash table id returned by hashCreate - @param name Key name to search for - @return Reference to the WebKey object storing the key and value - @ingroup WebsHash - @stability Stable - */ -PUBLIC WebsKey *hashLookup(WebsHash id, char *name); - -/** - Lookup a name in the hash table and return a symbol reference - @param sd Hash table id returned by hashCreate - @param name Key name to search for - @return Reference to the symbole - @ingroup WebsHash - @stability Evolving - */ -PUBLIC void *hashLookupSymbol(WebsHash sd, char *name); - -/** - Enter a new key and value into the hash table - @param id Hash table id returned by hashCreate - @param name Key name to create - @param value Key value to enter - @param arg Optional extra argument to store with the value - @return Reference to the WebKey object storing the key and value - @ingroup WebsHash - @stability Stable - */ -PUBLIC WebsKey *hashEnter(WebsHash id, char *name, WebsValue value, int arg); - -/** - Delete a key by name - @param id Hash table id returned by hashCreate - @param name Key name to delete - @return Zero if the delete was successful. Otherwise -1 if the key was not found. - @ingroup WebsHash - @stability Stable - */ -PUBLIC int hashDelete(WebsHash id, char *name); - -/** - Start walking the hash keys by returning the first key entry in the hash - @param id Hash table id returned by hashCreate - @return Reference to the first WebKey object. Return null if there are no keys in the hash. - @ingroup WebsHash - @stability Stable - */ -PUBLIC WebsKey *hashFirst(WebsHash id); - -/** - Continue walking the hash keys by returning the next key entry in the hash - @param id Hash table id returned by hashCreate - @param last Reference to a WebsKey to hold the current traversal key state. - @return Reference to the next WebKey object. Returns null if no more keys exist to be traversed. - @ingroup WebsHash - @stability Stable - */ -PUBLIC WebsKey *hashNext(WebsHash id, WebsKey *last); - -/************************************ Socket **********************************/ -/* - Socket flags - */ -#define SOCKET_EOF 0x1 /**< Seen end of file */ -#define SOCKET_CONNECTING 0x2 /**< Connect in progress */ -#define SOCKET_RESERVICE 0x4 /**< Socket needs re-servicing */ -#define SOCKET_ASYNC 0x8 /**< Use async connect */ -#define SOCKET_BLOCK 0x10 /**< Use blocking I/O */ -#define SOCKET_LISTENING 0x20 /**< Socket is server listener */ -#define SOCKET_CLOSING 0x40 /**< Socket is closing */ -#define SOCKET_CONNRESET 0x80 /**< Socket connection was reset */ -#define SOCKET_HANDSHAKING 0x100 /**< Doing SSL handshake */ -#define SOCKET_BUFFERED_READ 0x200 /**< Message pending on this socket */ -#define SOCKET_BUFFERED_WRITE 0x400 /**< Message pending on this socket */ -#define SOCKET_NODELAY 0x800 /**< Disable Nagle algorithm */ - -#define SOCKET_PORT_MAX 0xffff /**< Max Port size */ - -#ifndef ME_MAX_IP -#define ME_MAX_IP 64 /**< Maximum IP address size */ -#endif - -/* - Socket error values - */ -#define SOCKET_WOULDBLOCK 1 /**< Socket would block on I/O */ -#define SOCKET_RESET 2 /**< Socket has been reset */ -#define SOCKET_NETDOWN 3 /**< Network is down */ -#define SOCKET_AGAIN 4 /**< Issue the request again */ -#define SOCKET_INTR 5 /**< Call was interrupted */ -#define SOCKET_INVAL 6 /**< Invalid */ - -/* - Handler event masks - */ -#define SOCKET_READABLE 0x2 /**< Make socket readable */ -#define SOCKET_WRITABLE 0x4 /**< Make socket writable */ -#define SOCKET_EXCEPTION 0x8 /**< Interested in exceptions */ - -/** - Socket I/O callback - @param sid Socket ID handle returned from socketConnect or when a new socket is passed to a SocketAccept - callback.. - @param mask Mask of events of interest. Set to SOCKET_READABLE | SOCKET_WRITABLE | SOCKET_EXCEPTION. - @param data Data argument to pass to the callback function. - @ingroup WebsSocket - @stability Stable - */ -typedef void (*SocketHandler)(int sid, int mask, void *data); - -/** - Socket accept callback - @param sid Socket ID handle for the newly accepted socket - @param ipaddr IP address of the connecting client. - @param port Port of the connecting client. - @param listenSid Socket ID for the listening socket - @ingroup WebsSocket - @stability Stable - */ -typedef int (*SocketAccept)(int sid, char *ipaddr, int port, int listenSid); - -/** - Socket control structure - @see socketAddress socketAddressIsV6 socketClose socketCloseConnection socketCreateHandler - socketDeletehandler socketReservice socketEof socketGetPort socketInfo socketIsV6 - socketOpen socketListen socketParseAddress socketProcess socketRead socketWrite socketWriteString - socketSelect socketGetHandle socketSetBlock socketGetBlock socketAlloc socketFree socketGetError - socketSetError socketPtr socketWaitForEvent socketRegisterInterest - @defgroup WebsSocket WebsSocket - @stability Stable - */ -typedef struct WebsSocket -{ - WebsBuf lineBuf; /**< Line ring queue */ - SocketAccept accept; /**< Accept handler */ - SocketHandler handler; /**< User I/O handler */ - char *ip; /**< Server listen address or remote client address */ - void *handler_data; /**< User handler data */ - int handlerMask; /**< Handler events of interest */ - int sid; /**< Index into socket[] */ - int port; /**< Port to listen on */ - int flags; /**< Current state flags */ - Socket sock; /**< Actual socket handle */ - int fileHandle; /**< ID of the file handler */ - int interestEvents; /**< Mask of events to watch for */ - int currentEvents; /**< Mask of ready events (FD_xx) */ - int selectEvents; /**< Events being selected */ - int saveMask; /**< saved Mask for socketFlush */ - int error; /**< Last error */ - int secure; /**< Socket is using SSL */ - int handshakes; /**< Number of renegotiations */ -} WebsSocket; - - -/** - Extract the numerical IP address and port for the given socket info - @param addr Reference to the socket address. - @param addrlen Length of the socket address - @param ipbuf Buffer to contain the parsed IP address - @param ipLen Size of ipbuf - @param port Reference to an integer to hold the parsed port. - @return Zero if successful. Otherwise -1 for parse errors. - @ingroup WebsSocket - @stability Stable - */ -PUBLIC int socketAddress(struct sockaddr *addr, int addrlen, char *ipbuf, int ipLen, int *port); - -/** - Determine if an IP address is an IPv6 address. - @param ip String IP address. - @return True if the address is an IPv6 address. - @ingroup WebsSocket - @stability Stable - */ -PUBLIC bool socketAddressIsV6(char *ip); - -/** - Allocate a socket object - @param host String host IP address. - @param port Socket port - @param accept Optional SocketAccept accept callback function - @param flags Control flags - @return Socket ID handle to use with other APIs. - @ingroup WebsSocket - @stability Stable - */ -PUBLIC int socketAlloc(char *host, int port, SocketAccept accept, int flags); - -/** - Close the socket module - @ingroup WebsSocket - @stability Stable - */ -PUBLIC void socketClose(); - -/** - Close a socket connection - @param sid Socket ID handle returned from socketConnect or socketAccept. - @ingroup WebsSocket - @stability Stable - */ -PUBLIC void socketCloseConnection(int sid); - -/** - Connect to a server and create a new socket - @param host Host IP address. - @param port Port number to connect to - @param flags Set to SOCKET_BLOCK for blocking I/O. Otherwise non-blocking I/O is used. - @return True if the address is an IPv6 address. - @ingroup WebsSocket - @internal - @stability Stable - */ -PUBLIC int socketConnect(char *host, int port, int flags); - -/** - Create a socket handler that will be invoked when I/O events occur. - @param sid Socket ID handle returned from socketConnect or socketAccept. - @param mask Mask of events of interest. Set to SOCKET_READABLE | SOCKET_WRITABLE | SOCKET_EXCEPTION. - @param handler Socket handler function. - @param arg Arbitrary object reference to pass to the SocketHandler callback function. - @return True if the address is an IPv6 address. - @ingroup WebsSocket - @stability Stable - */ -PUBLIC void socketCreateHandler(int sid, int mask, SocketHandler handler, void *arg); - -/** - Delete a socket handler created via socketCreateHandler - @param sid Socket ID handle returned from socketConnect or socketAccept. - @ingroup WebsSocket - @stability Stable - */ -PUBLIC void socketDeleteHandler(int sid); - -/** - Determine if the socket is at end-of-file for input. - @param sid Socket ID handle returned from socketConnect or socketAccept. - @return True if the address is at EOF - @ingroup WebsSocket - @stability Stable - */ -PUBLIC bool socketEof(int sid); - -/** - Free (and close) the socket - @param sid Socket ID handle returned from socketConnect or socketAccept. - @ingroup WebsSocket - @stability Stable - */ -PUBLIC void socketFree(int sid); - -/** - Get the current blocking mode - @param sid Socket ID handle returned from socketConnect or socketAccept. - @return True if the socket is in blocking mode. - @ingroup WebsSocket - @stability Stable - */ -PUBLIC int socketGetBlock(int sid); - -/** - Get the error code for the last socket operation on this thread. - @return Integer error code. See errno or GetLastError() on windows. - @ingroup WebsSocket - @stability Stable - */ -PUBLIC int socketGetError(); - -/** - Get the underlying socket operating system socket/file handle - @param sid Socket ID handle returned from socketConnect or socketAccept. - @return The socket handle - @ingroup WebsSocket - @stability Stable - */ -PUBLIC Socket socketGetHandle(int sid); - -/** - Get the list of sockets - @return The socket list pointer - @ingroup WebsSocket - @stability Stable - */ -PUBLIC WebsSocket **socketGetList(); - -/** - Get the IP port associated with this socket. - @param sid Socket ID handle returned from socketConnect or socketAccept. - @return The TCP/IP port for this socket - @ingroup WebsSocket - @stability Stable - */ -PUBLIC int socketGetPort(int sid); - -/** - Indicate if the system has a dual IPv4 and IPv6 stack - @return True if IPv4 and IPv6 are supported on a single stack - @ingroup WebsSocket - @stability Stable - */ -PUBLIC bool socketHasDualNetworkStack(); - -/** - Indicate if the system has IPv6 support - @return True if IPv6 is supported on this system - @ingroup WebsSocket - @stability Stable - */ -PUBLIC bool socketHasIPv6(); - -/** - Indicate that the application layer has buffered data for the socket. - @description This is used by SSL and other network stacks that buffer pending data - @param sp Socket object returned from #socketPtr - @param len Length of buffered data in bytes - @param dir Buffer direction. Set to MPR_READABLE for buffered read data and MPR_WRITABLE for buffered write data. - @ingroup WebsSocket - @stability Stable - */ -PUBLIC void socketHiddenData(WebsSocket *sp, ssize len, int dir); - -/** - Get a socket address structure for the specified IP:Port - @description This returns address details in *family, *protocol, *addr, and *addrlen. - @param ip IP address to parse - @param port TCP/IP port number - @param family Reference to an integer to hold the address family - @param protocol Reference to an integer to hold the address protocol - @param addr Reference to an integer to hold the address structure - @param addrlen Reference to an integer to hold the address structure length - @return Zero if successful, otherwise -1. - @ingroup WebsSocket - @stability Stable - */ -PUBLIC int socketInfo(char *ip, int port, int *family, int *protocol, struct sockaddr_storage *addr, Socklen *addrlen); - -/** - Determine if a socket is bound to an IPv6 address. - @param sid Socket ID handle returned from socketConnect or socketAccept. - @return True if the socket is using IPv6. - @ingroup WebsSocket - @stability Stable - */ -PUBLIC bool socketIsV6(int sid); - -/** - Open a listening socket - @param host Host IP address on which to listen. Set to NULL to listen on all interfaces. - @param port TCP/IP port on which to listen - @param accept SocketAccept callback function to invoke to receive incoming connections. - @param flags Reserved - @return Zero if successful, otherwise -1. - @ingroup WebsSocket - @stability Stable - */ -PUBLIC int socketListen(char *host, int port, SocketAccept accept, int flags); - -/** - Open the socket module - @return Zero if successful, otherwise -1. - @ingroup WebsSocket - @stability Stable - */ -PUBLIC int socketOpen(); - -/** - Parse an IP address into its constituent parts. - @description Parse the IP address and return the IP address and port components. Handles ipv4 and ipv6 addresses. - If the IP portion is absent, pip is set to null. If the port portion is absent, port is set to the defaultPort. - If a ":*" port specifier is used, pport is set to -1; - When an address contains an ipv6 port it should be written as - aaaa:bbbb:cccc:dddd:eeee:ffff:gggg:hhhh:iiii - or - [aaaa:bbbb:cccc:dddd:eeee:ffff:gggg:hhhh:iiii]:port - If supplied an IPv6 address, the backets are stripped in the returned IP address. - @param ipAddrPort IP address which may contain an optional ":port" component. - @param pip Returns a reference to an allocated string containing the IP address portion. Caller must free. - @param pport Reference to an integer to hold the port component. - @param secure Reference to an integer to be set to true if the address is using SSL/TLS. - @param defaultPort Default port number to use if no port specifier is included in ipAddrPort. - @return Zero if successful, otherwise -1. - @ingroup WebsSocket - @stability Stable - */ -PUBLIC int socketParseAddress(char *ipAddrPort, char **pip, int *pport, int *secure, int defaultPort); - -/** - Process pending socket I/O events. - @ingroup WebsSocket - @stability Stable - @internal - */ -PUBLIC void socketProcess(); - -/** - Read data from a socket - @param sid Socket ID handle returned from socketConnect or socketAccept. - @param buf Buffer to hold read data - @param len Size of the buffer - @return Count of bytes actually read. Returns -1 for errors and EOF. Distinguish between errors and EOF - via socketEof(). - @ingroup WebsSocket - @stability Stable - */ -PUBLIC ssize socketRead(int sid, void *buf, ssize len); - -/** - Register interest in socket I/OEvents - @param sid Socket ID handle returned from socketConnect or socketAccept. - @param mask Mask of events of interest. Set to SOCKET_READABLE | SOCKET_WRITABLE | SOCKET_EXCEPTION. - @ingroup WebsSocket - @stability Stable - */ -PUBLIC void socketRegisterInterest(int sid, int mask); - -/** - Request that the socket be reserviced. - @description This routine is useful when upper layers have unprocessed, buffered data for the socket. - This routine will cause the socket I/O callback handler to be invoked soon in the future. - @param sid Socket ID handle returned from socketConnect or socketAccept. - @ingroup WebsSocket - @stability Stable - */ -PUBLIC void socketReservice(int sid); - -/** - Wait for I/O on a socket - @description This call uses the mask of events of interest defined by socketRegisterInterest. It blocks the caller - until a suitable I/O event or timeout occurs. - @param sid Socket ID handle returned from socketConnect or socketAccept. - @param timeout Timeout in milliseconds. - @return Number of I/O events. - @ingroup WebsSocket - @stability Stable - */ -PUBLIC int socketSelect(int sid, int timeout); - -/** - Set the socket blocking mode - @param sid Socket ID handle returned from socketConnect or socketAccept. - @param on Set to 1 to enable blocking - @return The previous blocking mode - @ingroup WebsSocket - @stability Stable - */ -PUBLIC int socketSetBlock(int sid, int on); - -/** - Set the error code for the last socket operation on this thread. - @param error Integer error code. See errno or GetLastError() on windows. - @ingroup WebsSocket - @stability Stable - */ -PUBLIC void socketSetError(int error); - -/** - Set the socket delay mode - @description This is used to enable or disable the TCP Nagle algorithm - @param sid Socket ID handle returned from socketConnect or socketAccept. - @param on Set to 1 to disable the Nagle algorithm - @return The previous blocking mode - @ingroup WebsSocket - @stability Stable - */ -PUBLIC int socketSetNoDelay(int sid, bool on); - -/** - Wait for a socket I/O event - @param sp Socket object - @param mask Mask of events of interest. Set to SOCKET_READABLE | SOCKET_WRITABLE | SOCKET_EXCEPTION. - @return Zero if successful in waiting for the desired event, othewise return -1. - @ingroup WebsSocket - @stability Stable - */ -PUBLIC int socketWaitForEvent(WebsSocket *sp, int mask); - -/** - Write data to the socket - @param sid Socket ID handle returned from socketConnect or socketAccept. - @param buf Buffer containing data to write - @param len Size of buf - @return Count of bytes written. May be less than len if the socket is in non-blocking mode. - Returns -1 for errors and if the socket cannot absorb any more data. If the transport is saturated, - will return a negative error and errno will be set to EAGAIN or EWOULDBLOCK. - @ingroup WebsSocket - @stability Stable - */ -PUBLIC ssize socketWrite(int sid, void *buf, ssize len); - -/** - Return the socket object for the socket ID. - @param sid Socket ID handle returned from socketConnect or socketAccept. - @return Corresponding socket object. - @ingroup WebsSocket - @stability Stable - */ -PUBLIC WebsSocket *socketPtr(int sid); - -/*********************************** Runtime **********************************/ - -/** - GoAhead Web Server Runtime - @description GoAhead provides a secure runtime environment for safe string manipulation and to - help prevent buffer overflows and other potential security traps. - @defgroup WebsRuntime WebsRuntime - @see fmt wallocHandle wallocObject wfreeHandle hextoi itosbuf scaselesscmp scaselessmatch - sclone scmp scopy sfmt sfmtv slen slower smatch sstarts sncaselesscmp sncmp sncopy stok strim supper - @stability Stable - */ - -/** - Format a string into a static buffer. - @description This call format a string using printf style formatting arguments. A trailing null will - always be appended. The call returns the size of the allocated string excluding the null. - @param buf Pointer to the buffer. - @param maxSize Size of the buffer. - @param format Printf style format string - @param ... Variable arguments to format - @return Returns the buffer. - @ingroup WebsRuntime - @stability Stable - */ -PUBLIC char *fmt(char *buf, ssize maxSize, char *format, ...); - -/** - Allocate a handle from a map - @param map Reference to a location holding the map reference. On the first call, the map is allocated. - @return Integer handle index. Otherwise return -1 on allocation errors. - @ingroup WebsRuntime - @stability Stable - */ -PUBLIC int wallocHandle(void *map); - -/** - Allocate an object in a halloc map - @param map Reference to a location holding the map reference. On the first call, the map is allocated. - @param max Reference to an integer that holds the maximum handle in the map. - @param size Size of the object to allocate. - @return Integer handle index. Otherwise return -1 on allocation errors. - @ingroup WebsRuntime - @stability Stable - */ -PUBLIC int wallocObject(void *map, int *max, int size); - -/** - Free a handle in the map - @param map Reference to a location to hold the map reference. - @param handle Handle to free in the map. - @return Integer handle index. Otherwise return -1 on allocation errors. - @ingroup WebsRuntime - @stability Stable - */ -PUBLIC int wfreeHandle(void *map, int handle); - -/** - Convert a hex string to an integer - @description This call converts the supplied string to an integer using base 16. - @param str Pointer to the string to parse. - @return Returns the integer equivalent value of the string. - @ingroup WebsRuntime - @stability Stable - */ -PUBLIC uint hextoi(char *str); - -/** - Convert an integer to a string buffer. - @description This call converts the supplied 64 bit integer into a string formatted into the supplied buffer according - to the specified radix. - @param buf Pointer to the buffer that will hold the string. - @param size Size of the buffer. - @param value Integer value to convert - @param radix The base radix to use when encoding the number - @return Returns a reference to the string. - @ingroup WebsRuntime - @stability Stable - */ -PUBLIC char *itosbuf(char *buf, ssize size, int64 value, int radix); - -/** - Compare strings ignoring case. This is a safe replacement for strcasecmp. It can handle NULL args. - @description Compare two strings ignoring case differences. This call operates similarly to strcmp. - @param s1 First string to compare. - @param s2 Second string to compare. - @return Returns zero if the strings are equivalent, < 0 if s1 sorts lower than s2 in the collating sequence - or > 0 if it sorts higher. - @ingroup WebsRuntime - @stability Stable - */ -PUBLIC int scaselesscmp(char *s1, char *s2); - -/** - Compare strings ignoring case. This is similar to scaselesscmp but it returns a boolean. - @description Compare two strings ignoring case differences. - @param s1 First string to compare. - @param s2 Second string to compare. - @return Returns true if the strings are equivalent, otherwise false. - @ingroup WebsRuntime - @stability Stable - */ -PUBLIC bool scaselessmatch(char *s1, char *s2); - -/** - Clone a string - @description Copy a string into a newly allocated block. - @param str Pointer to the block to duplicate. - @return Returns a newly allocated string. - @ingroup WebsRuntime - @stability Stable - */ -PUBLIC char *sclone(char *str); - -/** - Clone a substring. - @description Copy a substring into a newly allocated block. - @param str Pointer to the block to duplicate. - @param len Number of bytes to copy. The actual length copied is the minimum of the given length and the length of - the supplied string. The result is null terminated. - @return Returns a newly allocated string. - @ingroup WebsRuntime - @stability Stable - */ -PUBLIC char *snclone(char *str, ssize len); - -/** - Compare strings. - @description Compare two strings. This is a safe replacement for strcmp. It can handle null args. - @param s1 First string to compare. - @param s2 Second string to compare. - @return Returns zero if the strings are identical. Return -1 if the first string is less than the second. Return 1 - if the first string is greater than the second. - @ingroup WebsRuntime - @stability Stable - */ -PUBLIC int scmp(char *s1, char *s2); - -/** - Copy a string. - @description Safe replacement for strcpy. Copy a string and ensure the destination buffer is not overflowed. - The call returns the length of the resultant string or an error code if it will not fit into the target - string. This is similar to strcpy, but it will enforce a maximum size for the copied string and will - ensure it is always terminated with a null. - @param dest Pointer to a pointer that will hold the address of the allocated block. - @param destMax Maximum size of the target string in characters. - @param src String to copy - @return Returns the number of characters in the target string. - @ingroup WebsRuntime - @stability Stable - */ -PUBLIC ssize scopy(char *dest, ssize destMax, char *src); - -/* - String trim flags - */ -#define WEBS_TRIM_START 0x1 /**< Flag for strim to trim from the start of the string */ -#define WEBS_TRIM_END 0x2 /**< Flag for strim to trim from the end of the string */ -#define WEBS_TRIM_BOTH 0x3 /**< Flag for strim to trim from both the start and the end of the string */ - -/** - Format a string. This is a secure verion of printf that can handle null args. - @description Format the given arguments according to the printf style format. See fmt() for a full list of the - format specifies. This is a secure replacement for sprintf, it can handle null arguments without crashes. - @param format Printf style format string - @param ... Variable arguments for the format string - @return Returns a newly allocated string - @ingroup WebsRuntime - @stability Stable - */ -PUBLIC char *sfmt(char *format, ...); - -/** - Format a string with varargs. This is a secure verion of printf that can handle null args. - @description Format the given arguments according to the printf style format. See fmt() for a full list of the - format specifies. This is a secure replacement for sprintf, it can handle null arguments without crashes. - @param format Printf style format string - @param args Varargs argument obtained from va_start. - @return Returns a newly allocated string - @ingroup WebsRuntime - @stability Stable - */ -PUBLIC char *sfmtv(char *format, va_list args); - -/** - Return the length of a string. - @description Safe replacement for strlen. This call returns the length of a string and tests if the length is - less than a given maximum. It will return zero for NULL args. - @param str String to measure. - @return Returns the length of the string - @ingroup WebsRuntime - @stability Stable - */ -PUBLIC ssize slen(cchar *str); - -/** - Convert a string to lower case. - @description Convert a string to its lower case equivalent. - @param str String to convert. This string is modified. - @return Reference to the supplied str. - @ingroup WebsRuntime - @stability Stable - */ -PUBLIC char *slower(char *str); - -/** - Compare strings - @description Compare two strings. This is similar to #scmp but it returns a boolean. - @param s1 First string to compare. - @param s2 Second string to compare. - @return Returns true if the strings are equivalent, otherwise false. - @ingroup WebsRuntime - @stability Stable - */ -PUBLIC bool smatch(char *s1, char *s2); - -/** - Compare strings ignoring case. - @description Compare two strings ignoring case differences for a given string length. This call operates - similarly to strncasecmp. - @param s1 First string to compare. - @param s2 Second string to compare. - @param len Length of characters to compare. - @return Returns zero if the strings are equivalent, < 0 if s1 sorts lower than s2 in the collating sequence - or > 0 if it sorts higher. - @ingroup WebsRuntime - @stability Stable - */ -PUBLIC int sncaselesscmp(char *s1, char *s2, ssize len); - -/** - Compare strings. - @description Compare two strings for a given string length. This call operates similarly to strncmp. - @param s1 First string to compare. - @param s2 Second string to compare. - @param len Length of characters to compare. - @return Returns zero if the strings are equivalent, < 0 if s1 sorts lower than s2 in the collating sequence - or > 0 if it sorts higher. - @ingroup WebsRuntime - @stability Stable - */ -PUBLIC int sncmp(char *s1, char *s2, ssize len); - -/** - Copy characters from a string. - @description Safe replacement for strncpy. Copy bytes from a string and ensure the target string is not overflowed. - The call returns the length of the resultant string or an error code if it will not fit into the target - string. This is similar to strcpy, but it will enforce a maximum size for the copied string and will - ensure it is terminated with a null. - @param dest Pointer to a pointer that will hold the address of the allocated block. - @param destMax Maximum size of the target string in characters. - @param src String to copy - @param count Maximum count of characters to copy - @return Returns a reference to the destination if successful or NULL if the string won't fit. - @ingroup WebsRuntime - @stability Stable - */ -PUBLIC ssize sncopy(char *dest, ssize destMax, char *src, ssize count); - -/* - Test if a string is a radix 10 number. - @description The supported format is: [(+|-)][DIGITS] - @return true if all characters are digits or '+' or '-' - @ingroup WebsRuntime - @stability Stable - */ -PUBLIC bool snumber(cchar *s); - -/** - Split a string at a delimiter - @description Split a string and return parts. The string is modified. - This routiner never returns null. If there are leading delimiters, the empty string will be returned - and *last will be set to the portion after the delimiters. - If str is null, an empty string will be returned. - If there are no characters after the delimiter, then *last will be set to the empty string. - @param str String to tokenize. - @param delim Set of characters that are used as token separators. - @param last Reference to the portion after the delimiters. Will return an empty string if is not trailing portion. - @return Returns a pointer to the first part before the delimiters. If the string begins with delimiters, the empty - string will be returned. - @ingroup WebsRuntime - @stability Evolving - */ -PUBLIC char *ssplit(char *str, cchar *delim, char **last); - -/** - Test if the string starts with a given pattern. - @param str String to examine - @param prefix Pattern to search for - @return Returns TRUE if the pattern was found. Otherwise returns zero. - @ingroup MprString - @stability Stable - */ -PUBLIC bool sstarts(cchar *str, cchar *prefix); - -/** - Tokenize a string - @description Split a string into tokens. - @param str String to tokenize. - @param delim String of characters to use as token separators. - @param last Last token pointer. - @return Returns a pointer to the next token. - @ingroup WebsRuntime - @stability Stable - */ -PUBLIC char *stok(char *str, char *delim, char **last); - -/** - Trim a string. - @description Trim leading and trailing characters off a string. - @param str String to trim. - @param set String of characters to remove. - @param where Flags to indicate trim from the start, end or both. Use WEBS_TRIM_START, WEBS_TRIM_END, WEBS_TRIM_BOTH. - @return Returns a pointer to the trimmed string. May not equal \a str. - @ingroup WebsRuntime - @stability Stable - */ -PUBLIC char *strim(char *str, char *set, int where); - -/** - Convert a string to upper case. - @description Convert a string to its upper case equivalent. - @param str String to convert. This string is modified. - @return Returns a pointer to the converted string. Will always equal str. - @ingroup WebsRuntime - @stability Stable - */ -PUBLIC char *supper(char *str); - -/** - Callback function for events - @param data Opaque data argument - @param id Event ID - @ingroup WebsRuntime - @stability Stable - */ -typedef void (*WebsEventProc)(void *data, int id); - -/** - Start a callback event - @description This schedules an event to run once. The event can be rescheduled in the callback by invoking - websRestartEvent. - @param delay Delay in milliseconds in which to run the callback - @param proc Callback procedure function. Signature is: void (*fn)(void *data, int id) - @param data Data reference to pass to the callback - @return A positive integer event ID - @ingroup WebsRuntime - @stability Stable - */ -PUBLIC int websStartEvent(int delay, WebsEventProc proc, void *data); - -/** - Stop an event - @param id Event id allocated by websStartEvent - @return Integer handle index. Otherwise return -1 on allocation errors. - @ingroup WebsRuntime - @stability Stable - */ -PUBLIC void websStopEvent(int id); - -/** - Restart an event - @param id Event id allocated by websStartEvent - @param delay Delay in milliseconds till the event next runs - @ingroup WebsRuntime - @stability Stable - */ -PUBLIC void websRestartEvent(int id, int delay); - -/** - Run due events - @ingroup WebsRuntime - @return Time delay till the next event - @internal - */ -PUBLIC int websRunEvents(); - -/* Forward declare */ -struct WebsRoute; -struct WebsUser; -struct WebsSession; -struct Webs; - -/********************************** Upload ************************************/ -#if ME_GOAHEAD_UPLOAD - -/** - File upload structure - @see websUploadOpen websLookupUpload websGetUpload - @defgroup WebsUpload WebsUpload - */ -typedef struct WebsUpload -{ - char *filename; /**< Local (temp) name of the file */ - char *clientFilename; /**< Client side name of the file */ - char *contentType; /**< Content type */ - ssize size; /**< Uploaded file size */ -} WebsUpload; - -/** - Open the file upload filter - @ingroup WebsUpload - @stability Stable - */ -PUBLIC void websUploadOpen(); - -/** - Get the hash of uploaded files for the request - @param wp Webs request object - @return Hash table of uploaded files - @ingroup WebsUpload - @stability Stable - */ -PUBLIC WebsHash websGetUpload(struct Webs *wp); - -/** - Open the file upload filter - @param wp Webs request object - @param key Form upload name - @return Upload object for the uploaded file - @ingroup WebsUpload - @stability Stable - */ -PUBLIC WebsUpload *websLookupUpload(struct Webs *wp, char *key); -#endif -/********************************** Defines ***********************************/ - -#define WEBS_MAX_PORT_LEN 16 /* Max digits in port number */ -#define WEBS_HASH_INIT 67 /* Hash size for form table */ -#define WEBS_SESSION_HASH 31 /* Hash size for session stores */ -#define WEBS_SESSION_PRUNE (60*1000) /* Prune sessions every minute */ - -/* - The license agreement stipulates that you must not change this definition. - */ -#define WEBS_NAME "Server: GoAhead-http" - -/* - Request flags - */ -#define WEBS_ACCEPTED 0x1 /**< TLS connection accepted */ -#define WEBS_CHUNKING 0x2 /**< Currently chunking output body data */ -#define WEBS_CLOSED 0x4 /**< Connection closed, ready to free */ -#define WEBS_COOKIE 0x8 /**< Cookie supplied in request */ -#if DEPRECATED || 1 -#define WEBS_FINALIZED 0x10 /**< Output is finalized */ -#endif -#define WEBS_FORM 0x20 /**< Request is a form (url encoded data) */ -#define WEBS_HEADERS_CREATED 0x40 /**< Headers have been created and buffered */ -#define WEBS_HTTP11 0x80 /**< Request is using HTTP/1.1 */ -#define WEBS_JSON 0x100 /**< Request has a JSON payload */ -#define WEBS_KEEP_ALIVE 0x200 /**< HTTP/1.1 keep alive */ -#define WEBS_REROUTE 0x400 /**< Restart route matching */ -#define WEBS_RESPONSE_TRACED 0x800 /**< Started tracing the response */ -#define WEBS_SECURE 0x1000 /**< Connection uses SSL */ -#define WEBS_UPLOAD 0x2000 /**< Multipart-mime file upload */ -#define WEBS_VARS_ADDED 0x4000 /**< Query and body form vars added */ -#if ME_GOAHEAD_LEGACY -#define WEBS_LOCAL 0x8000 /**< Request from local system */ -#endif - -/* - Incoming chunk encoding states. Used for tx and rx chunking. - */ -#define WEBS_CHUNK_UNCHUNKED 0 /**< Data is not transfer-chunk encoded */ -#define WEBS_CHUNK_START 1 /**< Start of a new chunk */ -#define WEBS_CHUNK_HEADER 2 /**< Preparing tx chunk header */ -#define WEBS_CHUNK_DATA 3 /**< Start of chunk data */ - -/* - Webs state - */ -#define WEBS_BEGIN 0 /**< Beginning state */ -#define WEBS_CONTENT 1 /**< Ready for body data */ -#define WEBS_READY 2 /**< Ready to route and start handler */ -#define WEBS_RUNNING 3 /**< Processing request */ -#define WEBS_COMPLETE 4 /**< Request complete */ - -/* - Session names - */ -#define WEBS_SESSION "-goahead-session-" -#define WEBS_SESSION_USERNAME "_:USERNAME:_" /* Username variable */ - -/* - WebsDone flags - */ -#define WEBS_CODE_MASK 0xFFFF /**< Mask valid status codes */ -#define WEBS_CLOSE 0x20000 /**< Close connection */ -#define WEBS_NOLOG 0x40000 /**< Don't write error to log */ - -/** - Callback for write I/O events - */ -typedef void (*WebsWriteProc)(struct Webs *wp); - -/** - GoAhead request structure. This is a per-socket connection structure. - @defgroup Webs Webs - */ -typedef struct Webs -{ - WebsBuf rxbuf; /**< Raw receive buffer */ - WebsBuf input; /**< Receive buffer after de-chunking */ - WebsBuf output; /**< Transmit buffer after chunking */ - WebsBuf chunkbuf; /**< Pre-chunking data buffer */ - WebsBuf *txbuf; - WebsTime since; /**< Parsed if-modified-since time */ - WebsTime timestamp; /**< Last transaction with browser */ - WebsHash vars; /**< CGI standard variables */ - int timeout; /**< Timeout handle */ - char ipaddr[ME_MAX_IP]; /**< Connecting ipaddress */ - char ifaddr[ME_MAX_IP]; /**< Local interface ipaddress */ - - int rxChunkState; /**< Rx chunk encoding state */ - ssize rxChunkSize; /**< Rx chunk size */ - char *rxEndp; /**< Pointer to end of raw data in input beyond endp */ - ssize lastRead; /**< Number of bytes last read from the socket */ - bool eof; /**< If at the end of the request content */ - - char txChunkPrefix[16]; /**< Transmit chunk prefix */ - char *txChunkPrefixNext; /**< Current I/O pos in txChunkPrefix */ - ssize txChunkPrefixLen; /**< Length of prefix */ - ssize txChunkLen; /**< Length of the chunk */ - int txChunkState; /**< Transmit chunk state */ - - char *authDetails; /**< Http header auth details */ - char *authResponse; /**< Outgoing auth header */ - char *authType; /**< Authorization type (Basic/DAA) */ - char *contentType; /**< Body content type */ - char *cookie; /**< Request cookie string */ - char *decodedQuery; /**< Decoded request query */ - char *digest; /**< Password digest */ - char *ext; /**< Path extension */ - char *filename; /**< Document path name */ - char *host; /**< Requested host */ - char *method; /**< HTTP request method */ - char *password; /**< Authorization password */ - char *path; /**< Path name without query. This is decoded. */ - char *protoVersion; /**< Protocol version (HTTP/1.1)*/ - char *protocol; /**< Protocol scheme (normally http|https) */ - char *putname; /**< PUT temporary filename */ - char *query; /**< Request query. This is decoded. */ - char *realm; /**< Realm field supplied in auth header */ - char *referrer; /**< The referring page */ - char *responseCookie; /**< Outgoing cookie */ - char *url; /**< Full request url. This is not decoded. */ - char *userAgent; /**< User agent (browser) */ - char *username; /**< Authorization username */ - int sid; /**< Socket id (handler) */ - int listenSid; /**< Listen Socket id */ - int port; /**< Request port number */ - int state; /**< Current state */ - int flags; /**< Current flags -- see above */ - int code; /**< Response status code */ - int routeCount; /**< Route count limiter */ - ssize rxLen; /**< Rx content length */ - ssize rxRemaining; /**< Remaining content to read from client */ - ssize txLen; /**< Tx content length header value */ - int wid; /**< Index into webs */ -#if ME_GOAHEAD_CGI - char *cgiStdin; /**< Filename for CGI program input */ - int cgifd; /**< File handle for CGI program input */ -#endif -#if !ME_ROM - int putfd; /**< File handle to write PUT data */ -#endif - int docfd; /**< File descriptor for document being served */ - ssize written; /**< Bytes actually transferred */ - ssize putLen; /**< Bytes read by a PUT request */ - - int finalized: 1; /**< Request has been completed */ - int error: 1; /**< Request has an error */ - int connError: 1; /**< Request has a connection error */ - - struct WebsSession *session; /**< Session record */ - struct WebsRoute *route; /**< Request route */ - struct WebsUser *user; /**< User auth record */ - WebsWriteProc writeData; /**< Handler write I/O event callback. Used by fileHandler */ - int encoded; /**< True if the password is MD5(username:realm:password) */ -#if ME_GOAHEAD_DIGEST - char *cnonce; /**< check nonce */ - char *digestUri; /**< URI found in digest header */ - char *nonce; /**< opaque-to-client string sent by server */ - char *nc; /**< nonce count */ - char *opaque; /**< opaque value passed from server */ - char *qop; /**< quality operator */ -#endif -#if ME_GOAHEAD_UPLOAD - int upfd; /**< Upload file handle */ - WebsHash files; /**< Uploaded files */ - char *boundary; /**< Mime boundary (static) */ - ssize boundaryLen; /**< Boundary length */ - int uploadState; /**< Current file upload state */ - WebsUpload *currentFile; /**< Current file context */ - char *clientFilename; /**< Current file filename */ - char *uploadTmp; /**< Current temp filename for upload data */ - char *uploadVar; /**< Current upload form variable name */ -#endif - void *ssl; /**< SSL context */ -} Webs; - -#if ME_GOAHEAD_LEGACY -#define WEBS_LEGACY_HANDLER 0x1 /* Using legacy calling sequence */ -#endif - - -/** - GoAhead handler service callback - @param wp Webs request object - @return True if the handler serviced the request - @ingroup Webs - @stability Stable - */ -typedef bool (*WebsHandlerProc)(Webs *wp); - -/** - GoAhead handler close to release memory prior to shutdown. - @description This callback is invoked when GoAhead is shutting down. - @ingroup Webs - @stability Stable - */ -typedef void (*WebsHandlerClose)(); - -/** - GoAhead handler object - @ingroup Webs - @stability Stable - */ -typedef struct WebsHandler -{ - char *name; /**< Handler name */ - WebsHandlerProc match; /**< Handler match callback */ - WebsHandlerProc service; /**< Handler service callback */ - WebsHandlerClose close; /**< Handler close callback */ - int flags; /**< Handler control flags */ -} WebsHandler; - -/** - Action callback - @param wp Webs request object - @ingroup Webs - @stability Stable - */ -typedef void (*WebsAction)(Webs *wp); - -#if ME_GOAHEAD_LEGACY -typedef void (*WebsProc)(Webs *wp, char *path, char *query); -#endif - -/** - Error code list - @ingroup Webs - @stability Stable - */ -typedef struct WebsError -{ - int code; /**< HTTP error code */ - char *msg; /**< HTTP error message */ -} WebsError; - -/** - Mime type list - @ingroup Webs - @stability Stable - */ -typedef struct WebsMime -{ - char *type; /**< Mime type */ - char *ext; /**< File extension */ -} WebsMime; - -/** - File information structure. - @ingroup Webs - @stability Stable - */ -typedef struct WebsFileInfo -{ - ulong size; /**< File length */ - int isDir; /**< Set if directory */ - WebsTime mtime; /**< Modified time */ -} WebsFileInfo; - -/** - Compiled Rom Page Index - @ingroup Webs - @stability Stable - */ -typedef struct WebsRomIndex -{ - char *path; /**< Web page URL path */ - uchar *page; /**< Web page data */ - int size; /**< Size of web page in bytes */ - Offset pos; /**< Current read position */ -} WebsRomIndex; - -#if ME_ROM -/** - List of documents to service when built with ROM support - @ingroup Webs - @stability Stable - */ -PUBLIC_DATA WebsRomIndex websRomIndex[]; -#endif - -#define WEBS_DECODE_TOKEQ 1 /**< Decode base 64 blocks up to a NULL or equals */ - -/** - Accept a new connection - @param sid Socket ID handle for the newly accepted socket - @param ipaddr IP address originating the connection. - @param port Port number originating the connection. - @param listenSid Socket ID of the listening socket - @return Zero if successful, otherwise -1 - @ingroup Webs - @stability Stable - */ -PUBLIC int websAccept(int sid, char *ipaddr, int port, int listenSid); - -/** - Open the action handler - @ingroup Webs - @stability Stable - */ -PUBLIC void websActionOpen(); - -/** - Allocate a new Webs object - @param sid Socket ID handle for the newly accepted socket - @return The webs[] handle index for the allocated Webs object - @ingroup Webs - @stability Stable - */ -PUBLIC int websAlloc(int sid); - -/** - Cancel the request timeout. - @description Handlers may choose to manually manage the request timeout. This routine will disable the - centralized management of the timeout for this request. - @param wp Webs request object - @ingroup Webs - @stability Stable - */ -PUBLIC void websCancelTimeout(Webs *wp); - -#if ME_GOAHEAD_CGI -/** - Open the CGI handler - @return Zero if successful, otherwise -1 - @ingroup Webs - @stability Stable - */ -PUBLIC int websCgiOpen(); - -/** - CGI handler service callback - @param wp Webs object - @return Returns 1 if the request was handled. - @ingroup Webs - @stability Stable - */ -PUBLIC int websCgiHandler(Webs *wp); - -/** - Poll for output from CGI processes and output. - @return Time delay till next poll - @ingroup Webs - @stability Stable - */ -PUBLIC int websCgiPoll(); - -/* Internal */ -PUBLIC bool cgiHandler(Webs *wp); - -#endif /* ME_GOAHEAD_CGI */ - -/** - Close the core GoAhead web server module - @description Invoked when GoAhead is shutting down. - @ingroup Webs - @stability Stable - */ -PUBLIC void websClose(); - -/** - Close an open file - @param fd Open file handle returned by websOpenFile - @ingroup Webs - @stability Stable - */ -PUBLIC void websCloseFile(int fd); - -/** - Compare a request variable - @param wp Webs request object - @param var Variable name - @param value Value to compare with - @return True if the value matches. Otherwise return 0 - @ingroup Webs - @stability Stable - */ -PUBLIC int websCompareVar(Webs *wp, char *var, char *value); - -/** - Consume input from the request input buffer. - @description This is called by handlers when consuming data from the request input buffer. - This call updates the input service pointers and compacts the input buffer if required. - @param wp Webs request object - @param nbytes Number of bytes the handler has consumed from the input buffer. - @ingroup Webs - @stability Stable - */ -PUBLIC void websConsumeInput(Webs *wp, ssize nbytes); - -/** - Decode the string using base-64 encoding - @description This modifies the original string - @param str String to decode - @return The original string. - @ingroup Webs - @stability Stable - */ -PUBLIC char *websDecode64(char *str); - -/** - Decode a block using base-46 encoding - @param str String to decode. The string must be null terminated. - @param len Reference to an integer holding the length of the decoded string. - @param flags Reserved. - @return The original string. - @ingroup Webs - @stability Stable - */ -PUBLIC char *websDecode64Block(char *str, ssize *len, int flags); - -/** - Decode a URL expanding %NN encoding - @description Supports insitu decoding. i.e. Input and output buffers may be the same. - @param decoded Buffer to hold the decoded URL - @param input Input URL or buffer to decode - @param len Length of the decoded buffer. - @ingroup Webs - @stability Stable - */ -PUBLIC void websDecodeUrl(char *decoded, char *input, ssize len); - -/** - Define a request handler - @param name Name of the handler - @param match Handler callback match procedure. Invoked to match the request with the handler. - The handler should return true to accept the request. - @param service Handler callback service procedure. Invoked to service each request. - @param close Handler callback close procedure. Called when GoAhead is shutting down. - @param flags Set to WEBS_LEGACY_HANDLER to support the legacy handler API calling sequence. - @return Zero if successful, otherwise -1. - @ingroup Webs - @stability Stable - */ -PUBLIC int websDefineHandler(char *name, WebsHandlerProc match, WebsHandlerProc service, WebsHandlerClose close, int flags); - -/** - Complete a request. - @description A handler should call websDone() to complete the request. - @param wp Webs request object - @ingroup Webs - @stability Stable - */ -PUBLIC void websDone(Webs *wp); - -/** - Encode a string using base-64 encoding - @description The string is encoded insitu. - @param str String to encode - @return The original string. - @ingroup Webs - @stability Stable - */ -PUBLIC char *websEncode64(char *str); - -/** - Encode a block using base-64 encoding - @description The string is encoded insitu. - @param str String to encode. - @param len Length of string to encode - @return The original string. - @ingroup Webs - @stability Stable - */ -PUBLIC char *websEncode64Block(char *str, ssize len); - -/** - Escape unsafe characters in a string - @param str String to escape - @return An allocated block containing the escaped string. Caller must free. - @ingroup Webs - @stability Stable - */ -PUBLIC char *websEscapeHtml(char *str); - -/** - Complete a request with an error response - @param wp Webs request object - @param code HTTP status code - @param fmt Message printf style format - @param ... Format args - @ingroup Webs - @stability Stable - */ -PUBLIC void websError(Webs *wp, int code, char *fmt, ...); - -/** - Get a message for a HTTP status code - @param code HTTP status code - @return Http status message - @ingroup Webs - @stability Stable - */ -PUBLIC char *websErrorMsg(int code); - -/** - Open and initialize the file handler - @ingroup Webs - @stability Stable - */ -PUBLIC void websFileOpen(); - -/** - Flush buffered transmit data and compact the transmit buffer to make room for more data - @description This call initiates sending buffered data. If blocking mode is selected via the block parameter, - this call will wait until all the data has been sent to the O/S for transmission to the client. - If block is false, the flush will be initiated and the call will return immediately without blocking. - @param wp Webs request object - @param block Set to true to wait for all data to be written to the socket. Set to false to - write whatever the socket can absorb without blocking. - @return -1 for I/O errors. Return zero if there is more data remaining in the buffer. Return 1 if the - contents of the transmit buffer are fully written and the buffer is now empty. - @ingroup Webs - @stability Stable - */ -PUBLIC int websFlush(Webs *wp, bool block); - -/** - Free the webs request object. - @description Callers should call websDone to complete requests prior to invoking websFree. - @param wp Webs request object - @ingroup Webs - @stability Stable - */ -PUBLIC void websFree(Webs *wp); - -/** - Get the background execution flag - @description If GoAhead is invoked with --background, it will run as a daemon in the background. - @return True if GoAhead is running in the background. - @ingroup Webs - @stability Stable - */ -PUBLIC int websGetBackground(); - -#if ME_GOAHEAD_CGI -/** - Get a unique temporary filename for CGI communications - @return Filename string - @ingroup Webs - @stability Stable - */ -PUBLIC char *websGetCgiCommName(); -#endif /* ME_GOAHEAD_CGI */ - -/** - Get the request cookie if supplied - @param wp Webs request object - @return Cookie string if defined, otherwise null. - @ingroup Webs - @stability Stable - */ -PUBLIC char *websGetCookie(Webs *wp); - -/** - Get a date as a string - @description If sbuf is supplied, it is used to calculate the date. Otherwise, the current time is used. - @param sbuf File info object - @return An allocated date string. Caller should free. - @ingroup Webs - @stability Stable - */ -PUBLIC char *websGetDateString(WebsFileInfo *sbuf); - -/** - Get the debug flag - @description If GoAhead is invoked with --debugger, the debug flag will be set to true - @return True if GoAhead is running in debug mode. - @ingroup Webs - @stability Stable - */ -PUBLIC int websGetDebug(); - -/** - Get the base file directory for a request - @description Returns the request route directory if defined, otherwise returns the documents directory. - @param wp Webs request object - @return Path name string. Caller should not free. - @ingroup Webs - @stability Stable - */ -PUBLIC char *websGetDir(Webs *wp); - -/** - Get the GoAhead base documents directory - @description The documents directory is defined at build time and may be overridden by the GoAhead command line. - @return Path string for the documents directory. - @ingroup Webs - @stability Stable - */ -PUBLIC char *websGetDocuments(); - -/** - Get the request EOF status - @description The request EOF status is set to true when all the request body (POST|PUT) data has been received. - @param wp Webs request object - @return True if all the request body data has been received. - @ingroup Webs - @stability Stable - */ -PUBLIC int websGetEof(Webs *wp); - -/** - Get the request URI extension - @param wp Webs request object - @return The URI filename extension component. Caller should not free. - @ingroup Webs - @stability Stable - */ -PUBLIC char *websGetExt(Webs *wp); - -/** - Get the request filename - @description The URI is mapped to a filename by decoding and prepending with the request directory. - @param wp Webs request object - @return Filename string. Caller should not free. - @ingroup Webs - @stability Stable - */ -PUBLIC char *websGetFilename(Webs *wp); - -/** - Get the request host - @description The request host is set to the Host HTTP header value if it is present. Otherwise it is set to - the request URI hostname. - @param wp Webs request object - @return Host string. Caller should not free. - @ingroup Webs - @stability Stable - */ -PUBLIC char *websGetHost(Webs *wp); - -/** - Get the request interface address - @param wp Webs request object - @return Network interface string. Caller should not free. - @ingroup Webs - @stability Stable - */ -PUBLIC char *websGetIfaddr(Webs *wp); - -/** - Get the default index document name - @description The default index is "index.html" and can be updated via websSetIndex. - @return Index name string. Caller should not free. - @ingroup Webs - @stability Stable - */ -PUBLIC char *websGetIndex(); - -/** - Get the request method - @param wp Webs request object - @return HTTP method string. Caller should not free. - @ingroup Webs - @stability Stable - */ -PUBLIC char *websGetMethod(Webs *wp); - -/** - Get the request password - @description The request password may be encoded depending on the authentication scheme. - See wp->encoded to test if it is encoded. - @param wp Webs request object - @return Password string. Caller should not free. - @ingroup Webs - @stability Stable - */ -PUBLIC char *websGetPassword(Webs *wp); - -/** - Get the request path - @description The URI path component excludes the http protocol, hostname, port, reference and query components. - It always beings with "/". - @param wp Webs request object - @return Request path string. Caller should not free. - @ingroup Webs - @stability Stable - */ -PUBLIC char *websGetPath(Webs *wp); - -/** - Get the request TCP/IP port - @param wp Webs request object - @return TCP/IP Port integer - @ingroup Webs - @stability Stable - */ -PUBLIC int websGetPort(Webs *wp); - -/** - Get the request HTTP protocol - @description This will be set to either "http" or "https" - @param wp Webs request object - @return Protocol string. Caller should not free. - @ingroup Webs - @stability Stable - */ -PUBLIC char *websGetProtocol(Webs *wp); - -/** - Get the request query component - @param wp Webs request object - @return Request query string. Caller should not free. - @ingroup Webs - @stability Stable - */ -PUBLIC char *websGetQuery(Webs *wp); - -/** - Get the server host name - @return Host name string. Caller should not free. - @ingroup Webs - @stability Stable - */ -PUBLIC char *websGetServer(); - -/** - Get the server host name with port number. - @return Host name string with port number. Caller should not free. - @ingroup Webs - @stability Stable - */ -PUBLIC char *websGetServerUrl(); - -/** - Get the server IP address - @return Server IP address string. Caller should not free. - @ingroup Webs - @stability Stable - */ -PUBLIC char *websGetServerAddress(); - -/** - Get the server IP address with port number - @return Server IP:PORT address string. Caller should not free. - @ingroup Webs - @stability Stable - */ -PUBLIC char *websGetServerAddressUrl(); - -/** - Get the request URI - @description This returns the request URI. This may be modified if the request is rewritten via websRewrite - @param wp Webs request object - @return URI string. Caller should not free. - @ingroup Webs - @stability Stable - */ -PUBLIC char *websGetUrl(Webs *wp); - -/** - Get the client User-Agent HTTP header - @param wp Webs request object - @return User-Agent string. Caller should not free. - @ingroup Webs - @stability Stable - */ -PUBLIC char *websGetUserAgent(Webs *wp); - -/** - Get the request username - @description If the request is authenticated, this call returns the username supplied during authentication. - @param wp Webs request object - @return Username string if defined, otherwise null. Caller should not free. - @ingroup Webs - @stability Stable - */ -PUBLIC char *websGetUsername(Webs *wp); - -/** - Get a request variable - @description Request variables are defined for HTTP headers of the form HTTP_*. - Some request handlers also define their own variables. For example: CGI environment variables. - @param wp Webs request object - @param name Variable name - @param defaultValue Default value to return if the variable is not defined - @return Variable value string. Caller should not free. - @ingroup Webs - @stability Stable - */ -PUBLIC char *websGetVar(Webs *wp, char *name, char *defaultValue); - -/** - Listen on a TCP/IP address endpoint - @description The URI is mapped to a filename by decoding and prepending with the request directory. - For IPv6 addresses, use the format: [aaaa:bbbb:cccc:dddd:eeee:ffff:gggg:hhhh:iiii]:port. - @param endpoint IPv4 or IPv6 address on which to listen. - @return Positive integer holding a Socket ID handle if successful, otherwise -1. - @ingroup Webs - @stability Stable - */ -PUBLIC int websListen(char *endpoint); - -/** - Get an MD5 digest of a string - @param str String to analyze. - @return Allocated MD5 checksum. Caller should free. - @ingroup Webs - @stability Stable - */ -PUBLIC char *websMD5(char *str); - -/** - Get an MD5 digest of a block and optionally prepend a prefix. - @param buf Block to analyze - @param length Length of block - @param prefix Optional prefix to prepend to the MD5 sum. - @return Allocated MD5 checksum. Caller should free. - @ingroup Webs - @stability Stable - */ -PUBLIC char *websMD5Block(char *buf, ssize length, char *prefix); - -/** - Normalize a URI path - @description This removes "./", "../" and redundant separators. - @param path URI path to normalize - @return An allocated normalized URI path. Caller must free. - @ingroup Webs - @stability Stable - */ -PUBLIC char *websNormalizeUriPath(char *path); - -/** - Take not of the request activity and mark the time. - @description This is used to defer the request timeout whenever there is request I/O activity. - @param wp Webs request object - @ingroup Webs - @stability Stable - */ -PUBLIC void websNoteRequestActivity(Webs *wp); - -/** - Close the runtime code. - @description Called from websClose - @ingroup Webs - @internal - */ -PUBLIC void websRuntimeClose(); - -/** - Open the runtime code. - @description Called from websOpen - @return Zero if successful - @ingroup Webs - @internal - */ -PUBLIC int websRuntimeOpen(); - -/** - Open the web server - @description This initializes the web server and defines the documents directory. - @param documents Optional web documents directory. If set to null, the build time ME_GOAHEAD_DOCUMENTS value - is used for the documents directory. - @param routes Optional filename for a route configuration file to load. Additional route or - authentication configuration files can be loaded via websLoad. - @param routes Webs request object - @return Zero if successful, otherwise -1. - @ingroup Webs - @stability Stable - */ -PUBLIC int websOpen(char *documents, char *routes); - -/** - Close the O/S dependant code. - @description Called from websClose - @ingroup Webs - @internal - */ -PUBLIC void websOsClose(); - -/** - Open the O/S dependant code. - @description Called from websOpen - @return Zero if successful, otherwise -1. - @ingroup Webs - @internal - */ -PUBLIC int websOsOpen(); - -/** - Open the web page document for the current request - @param path Filename path to open - @param flags File open flags - @param mode Permissions mask - @return Positive file handle if successful, otherwise -1. - @ingroup Webs - @stability Stable - */ -PUBLIC int websOpenFile(char *path, int flags, int mode); - -/** - Open the options handler - @return Zero if successful, otherwise -1. - @ingroup Webs - @stability Stable - */ -PUBLIC int websOptionsOpen(); - -/** - Close the document page - @param wp Webs request object - @ingroup Webs - @stability Stable - */ -PUBLIC void websPageClose(Webs *wp); - -/** - Test if the document page for the request corresponds to a directory - @param wp Webs request object - @return True if the filename is a directory - @ingroup Webs - @stability Stable - */ -PUBLIC int websPageIsDirectory(Webs *wp); - -/** - Open a web page document for a request - @param wp Webs request object - @param mode File open mode. Select from O_RDONLY and O_BINARY. Rom files systems ignore this argument. - @param perms Ignored - @return File handle if successful, otherwise -1. - @ingroup Webs - @stability Stable - */ -PUBLIC int websPageOpen(Webs *wp, int mode, int perms); - -/** - Read data from the request page document - @param wp Webs request object - @param buf Buffer for the read data - @param size Size of buf - @return Count of bytes read if successful, otherwise -1. - @ingroup Webs - @stability Stable - */ -PUBLIC ssize websPageReadData(Webs *wp, char *buf, ssize size); - -/** - Seek to a position in the request page document - @param wp Webs request object - @param offset Offset of location in the file to seek to. This is relative to the specified origin. - @param origin Set to SEEK_CUR, SEEK_SET or SEEK_END to position relative to the current position, - beginning or end of the document. - @ingroup Webs - @stability Stable - */ -PUBLIC void websPageSeek(Webs *wp, Offset offset, int origin); - -/** - Get file status for the current request document - @param wp Webs request object - @param sbuf File information structure to modify with file status - @return Zero if successful, otherwise -1. - @ingroup Webs - @stability Stable - */ -PUBLIC int websPageStat(Webs *wp, WebsFileInfo *sbuf); - -#if !ME_ROM -/** - Process request PUT body data - @description This routine is called by the core HTTP engine to process request PUT data. - @param wp Webs request object - @return True if processing the request can proceed. - @ingroup Webs - @stability Stable - */ -PUBLIC bool websProcessPutData(Webs *wp); -#endif - -/** - Pump the state machine - @description This routine will advance the connection state machine in response to events. - @param wp Webs request object - @ingroup Webs - @stability Stable - */ -PUBLIC void websPump(Webs *wp); - -/** - Define an action callback for use with the action handler. - @description The action handler binds a C function to a URI under "/action". - @param name URI path suffix. This suffix is added to "/action" to form the bound URI path. - @param fun Callback function. The signature is void (*WebsAction)(Webs *wp); - @return Zero if successful, otherwise -1. - @ingroup Webs - @stability Stable - */ -PUBLIC int websDefineAction(cchar *name, void *fun); - -/** - Read data from an open file - @param fd Open file handle returned by websOpenFile - @param buf Buffer for the read data - @param size Size of buf - @return Count of bytes read if successful, otherwise -1. - @ingroup Webs - @stability Stable - */ -PUBLIC ssize websReadFile(int fd, char *buf, ssize size); - -/** - Read all the data from a file - @param path File path to read from - @return An allocated buffer containing the file data with an appended null. Caller must free. - @ingroup Webs - @stability Stable - */ -PUBLIC char *websReadWholeFile(char *path); - -/** - Redirect the client to a new URL. - @description This creates a response to the client with a Location header directing the client to a new location. - The response uses a 302 HTTP status code. - @param wp Webs request object - @param url URL to direct the client to. - @ingroup Webs - @stability Stable - */ -PUBLIC void websRedirect(Webs *wp, char *url); - -/** - Redirect the client to a new URI - @description The routing configuration file can define redirection routes for various HTTP status codes. - This routine will utilize the appropriate route redirection based on the request route and specified status code. - @param wp Webs request object - @param status HTTP status code to use in selecting the route redirection. - @return Zero if successful, otherwise -1. - @ingroup Webs - @stability Stable - */ -PUBLIC int websRedirectByStatus(Webs *wp, int status); - -/** - Create and send a request response - @description This creates a response for the current request using the specified HTTP status code and - the supplied message. - @param wp Webs request object - @param status HTTP status code. - @param msg Response message body - @return Zero if successful, otherwise -1. - @ingroup Webs - @stability Stable - */ -PUBLIC void websResponse(Webs *wp, int status, char *msg); - -/** - Rewrite a request - @description Handlers may choose to not process a request but rather rewrite requests and then reroute. - @param wp Webs request object - @param url New request URL. - @return Zero if successful, otherwise -1. - @ingroup Webs - @stability Stable - */ -PUBLIC int websRewriteRequest(Webs *wp, char *url); - -/** - Open the file system module - @return Zero if successful, otherwise -1. - @ingroup Webs - @stability Stable - */ -PUBLIC int websFsOpen(); - -/** - Close the file system module - @ingroup Webs - @stability Stable - */ -PUBLIC void websFsClose(); - -/** - Seek to a position in the current request page document - @param fd Open file handle returned by websOpenFile - @param offset Location in the file to seek to. - @param origin Set to SEEK_CUR, SEEK_SET or SEEK_END to position relative to the current position, - beginning or end of the document. - @ingroup Webs - @stability Stable - */ -PUBLIC Offset websSeekFile(int fd, Offset offset, int origin); - -/** - Get file status for a file - @param path Filename path - @param sbuf File information structure to modify with file status - @return Zero if successful, otherwise -1. - @ingroup Webs - @stability Stable - */ -PUBLIC int websStatFile(char *path, WebsFileInfo *sbuf); - -/** - One line embedding API. - @description This call will also open auth.txt and route.txt for authentication and routing configuration. - @param endpoint IP:PORT address on which to listen - @param documents Directory containing web documents to serve - @ingroup Webs - @stability Stable - */ -PUBLIC int websServer(char *endpoint, char *documents); - -/** - Service I/O events until finished - @description This will wait for socket events and service those until *finished is set to true - @param finished Integer location to test. If set to true, then exit. Note: setting finished will not - automatically wake up the service routine. - @ingroup Webs - @stability Stable - */ -PUBLIC void websServiceEvents(int *finished); - -/** - Set the background processing flag - @param on Value to set the background flag to. - @ingroup Webs - @internal - */ -PUBLIC void websSetBackground(int on); - -/** - Define a background write I/O event callback - @param wp Webs request object - @param proc Write callback - */ -PUBLIC void websSetBackgroundWriter(Webs *wp, WebsWriteProc proc); - -/* - Flags for websSetCookie - */ -#define WEBS_COOKIE_SECURE 0x1 /**< Flag for websSetCookie for secure cookies (https only) */ -#define WEBS_COOKIE_HTTP 0x2 /**< Flag for websSetCookie for http cookies (http only) */ - -/** - Define a cookie to include in the response - @param wp Webs request object - @param name Cookie name - @param value Cookie value - @param path URI path prefix applicable for this cookie - @param domain Domain applicable for this cookie - @param lifespan Cookie lifespan in seconds - @param flags Set to WEBS_COOKIE_SECURE for https only. Set to WEBS_COOKIE_HTTP for http only. - Otherwise the cookie applies to both http and https requests. - @return Zero if successful, otherwise -1. - @ingroup Webs - @stability Stable - */ -PUBLIC void websSetCookie(Webs *wp, char *name, char *value, char *path, char *domain, int lifespan, int flags); - -/** - Set the debug processing flag - @param on Value to set the debug flag to. - @ingroup Webs - @internal - */ -PUBLIC void websSetDebug(int on); - -/** - Set the web documents directory - @description The web documents directory is used when resolving request URIs into filenames. - @param dir Directory path to use - @ingroup Webs - @stability Stable - */ -PUBLIC void websSetDocuments(char *dir); - -/** - Create the CGI environment variables for the current request. - @param wp Webs request object - @ingroup Webs - @stability Stable - */ -PUBLIC void websSetEnv(Webs *wp); - -/** - Create request variables for query and POST body data - @description This creates request variables if the request is a POST form (has a Content-Type of - application/x-www-form-urlencoded). The POST body data is consumed from the input buffer. - @param wp Webs request object - @ingroup Webs - @stability Stable - */ -PUBLIC void websSetFormVars(Webs *wp); - -/** - Define the host name for the server - @param host String host name - @ingroup Webs - @stability Stable - */ -PUBLIC void websSetHost(char *host); - -/** - Define the host IP address - @param ipaddr Host IP address - @ingroup Webs - @stability Stable - */ -PUBLIC void websSetIpAddr(char *ipaddr); - -/** - Create and send a request response - @description This creates a response for the current request using the specified HTTP status code and - the supplied message. - @param filename Web document name to use as the index. This should not contain any directory components. - @ingroup Webs - @stability Stable - */ -PUBLIC void websSetIndex(char *filename); - -/** - Create request variables for query string data - @param wp Webs request object - @ingroup Webs - @stability Stable - */ -PUBLIC void websSetQueryVars(Webs *wp); - -/** - Set the response HTTP status code - @param wp Webs request object - @param status HTTP status code - @ingroup Webs - @stability Stable - */ -PUBLIC void websSetStatus(Webs *wp, int status); - -/** - Set the response body content length - @param wp Webs request object - @param length Length value to use - @ingroup Webs - @stability Stable - */ -PUBLIC void websSetTxLength(Webs *wp, ssize length); - -/** - Set a request variable to a formatted string value - @description Request variables are defined for HTTP headers of the form HTTP_*. - Some request handlers also define their own variables. For example: CGI environment variables. - @param wp Webs request object - @param name Variable name to set - @param fmt Value format string - @param ... Args to format - @return the allocated WebsKey - @ingroup Webs - @stability Evolving - */ -PUBLIC WebsKey *websSetVarFmt(Webs *wp, char *name, char *fmt, ...); - -/** - Set a request variable to a string value - @description Request variables are defined for HTTP headers of the form HTTP_*. - Some request handlers also define their own variables. For example: CGI environment variables. - @param wp Webs request object - @param name Variable name to set - @param value Value to set - @return the allocated WebsKey - @ingroup Webs - @stability Evolving - */ -PUBLIC WebsKey *websSetVar(Webs *wp, char *name, char *value); - -/** - Test if a request variable is defined - @param wp Webs request object - @param name Variable name - @return True if the variable is defined - @ingroup Webs - @stability Stable - */ -PUBLIC bool websTestVar(Webs *wp, char *name); - -/** - Create a temporary filename - This does not guarantee the filename is unique or that it is not already in use by another application. - @param dir Directory to locate the temp file. Defaults to the O/S default temporary directory (usually /tmp) - @param prefix Filename prefix - @return An allocated filename string - @ingroup Webs - @stability Stable - */ -PUBLIC char *websTempFile(char *dir, char *prefix); - -/** - Open the date/time parsing module - @return Zero if successful, otherwise -1. - @ingroup Webs - @stability Evolving - */ -PUBLIC int websTimeOpen(); - -/** - Close the date/time parsing module - @ingroup Webs - @stability Evolving -*/ -PUBLIC void websTimeClose(); - -/** - Parse a date/time string - @description Try to intelligently parse a date. - This is a tolerant parser. It is not validating and will do its best to parse any possible date string. - Supports the following date/time formats: - \n\n - ISO dates: 2009-05-21t16:06:05.000z - \n\n - Date: 07/28/2014, 07/28/08, Jan/28/2014, Jaunuary-28-2014, 28-jan-2014. - \n\n - Support date order: dd/mm/yy, mm/dd/yy and yyyy/mm/dd - \n\n - Support separators "/", ".", "-" - \n\n - Timezones: GMT|UTC[+-]NN[:]NN - \n\n - Time: 10:52[:23] - \n\n - @param time Reference to a - @param date Date/time string to parse - @param defaults Optionally supply missing components for the date/time. Set to NULL if not used. - @return Zero if successful, otherwise -1 - @ingroup Webs - @stability Evolving - */ -PUBLIC int websParseDateTime(WebsTime *time, char *date, struct tm *defaults); - -/** - Parse a URL into its components - @param url URL to parse - @param buf Buffer to hold storage for various parsed components. Caller must free. NOTE: the parsed components may - point to locations in this buffer. - @param protocol Parsed URL protocol component - @param host Parsed hostname - @param port Parsed URL port - @param path Parsed URL path component - @param ext Parsed URL extension - @param reference Parsed URL reference portion (\#reference) - @param query Parsed URL query component - @return Zero if successful, otherwise -1. - @ingroup Webs - @stability Evolving - */ -PUBLIC int websUrlParse(char *url, char **buf, char **protocol, char **host, char **port, char **path, char **ext, - char **reference, char **query); - -/** - Test if a webs object is valid - @description After calling websDone, the websFree routine will have been called and the memory for the webs object - will be released. Call websValid to test a Webs object for validity. - @param wp Webs request object - @return True if the webs object is still valid and the request has not been completed. - @ingroup Webs - @stability Stable - */ -PUBLIC bool websValid(Webs *wp); - -/** - Validate a URI path as expected in a HTTP request line - @description This expects a URI beginning with "/" and containing only valid URI characters. - The URI is decoded, and normalized removing "../" and "." segments. - The URI must begin with a "/" both before and after decoding and normalization. - @param uri URI to validate. - @return A validated, normalized URI path. Caller must free. - @ingroup Webs - @stability Stable - */ -PUBLIC char *websValidateUriPath(char *uri); - -/** - Test if a URI is using only valid characters - Note this does not test if the URI is fully legal. Some components of the URI have restricted character sets - that this routine does not test. This tests if the URI has only characters valid to use in a URI before decoding. - i.e. It will permit %NN encodings. The set of valid characters is: - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~:/?#[]@!$&'()*+,;=%" - @param uri Uri to test - @return True if the URI string is comprised of legal URI characters. - @ingroup Webs - @stability Evolving - */ -PUBLIC bool websValidUriChars(char *uri); - -/** - Write a set of standard response headers - @param wp Webs request object - @param contentLength Value for the Content-Length header which describes the length of the response body - @param redirect Value for the Location header which redirects the client to a new URL. - @ingroup Webs - @see websSetStatus - @stability Stable - */ -PUBLIC void websWriteHeaders(Webs *wp, ssize contentLength, char *redirect); - -/** - Signify the end of the response headers - @description This call concludes the response headers and writes a blank line to the response. - @param wp Webs request object - @ingroup Webs - @stability Stable - */ -PUBLIC void websWriteEndHeaders(Webs *wp); - -/** - Write a response header - @description This routine writes a response header. It should be invoked after calling websWriteHeaders - to write the standard headers and before websWriteEndHeaders. - This routine differs from websWrite in that it traces header values to the log. - @param wp Webs request object - @param key Header key value - @param fmt Header value format string. - @param ... Arguments to the format string. - @return Zero if successful, otherwise -1. - @ingroup Webs - @stability Stable - */ -PUBLIC int websWriteHeader(Webs *wp, char *key, char *fmt, ...); - -/** - Write data to the response - @description The data is buffered and will be sent to the client when the buffer is full or websFlush is - called. - @param wp Webs request object - @param fmt Printf style format string. - @param ... Arguments to the format string. - @return Count of bytes written - @ingroup Webs - @stability Stable - */ -PUBLIC ssize websWrite(Webs *wp, char *fmt, ...); - -/** - Write data to the open file - @param fd Open file handle returned by websOpenFile - @param buf Buffer for the read data - @param size Size of buf - @return Count of bytes read if successful, otherwise -1. - @ingroup Webs - @stability Stable - */ -PUBLIC ssize websWriteFile(int fd, char *buf, ssize size); - -/** - Write a block of data to the response - @description The data is buffered and will be sent to the client when the buffer is full or websFlush is - called. This routine will never return "short", it will always write all the data unless there are errors. - @param wp Webs request object - @param buf Buffer of data to write - @param size Length of buf - @return Count of bytes written or -1. This will always equal size if there are no errors. - @ingroup Webs - @stability Stable - */ -PUBLIC ssize websWriteBlock(Webs *wp, char *buf, ssize size); - -/** - Write a block of data to the network - @description This bypassed output buffering and is the lowest level write. - @param wp Webs request object - @param buf Buffer of data to write - @param size Length of buf - @return Count of bytes written. May be less than len if the socket is in non-blocking mode. - Returns -1 for errors and if the socket cannot absorb any more data. If the transport is saturated, - will return a negative error and errno will be set to EAGAIN or EWOULDBLOCK. - @ingroup Webs - @stability Stable - */ -PUBLIC ssize websWriteSocket(Webs *wp, char *buf, ssize size); - -#if ME_GOAHEAD_UPLOAD -/** - Process upload data for form, multipart mime file upload. - @param wp Webs request object - @return True if processing the request can proceed. - @ingroup Webs - @stability Stable - */ -PUBLIC bool websProcessUploadData(Webs *wp); - -/** - Free file upload data structures. - @param wp Webs request object - @ingroup Webs - @stability Stable - */ -PUBLIC void websFreeUpload(Webs *wp); -#endif - -#if ME_GOAHEAD_CGI -/** - Process CGI request body data. - @param wp Webs request object - @return True if processing the request can proceed. - @ingroup Webs - @stability Stable - */ -PUBLIC bool websProcessCgiData(Webs *wp); -#endif - -/************************************** Crypto ********************************/ - -/** - Get some random data - @param buf Reference to a buffer to hold the random data - @param length Size of the buffer - @param block Set to true if it is acceptable to block while accumulating entropy sufficient to provide good - random data. Setting to false will cause this API to not block and may return random data of a lower quality. - @ingroup Crypto - @stability Prototype. - */ -PUBLIC int websGetRandomBytes(char *buf, ssize length, bool block); - -/** - Encrypt a password using the Blowfish algorithm - @param password User's password to encrypt - @param salt Salt text to add to password. Helps to make each user's password unique. - @param rounds Number of times to encrypt. More times, makes the routine slower and passwords harder to crack. - @return The encrypted password. - @ingroup Crypto - @stability Prototype - */ -PUBLIC char *websCryptPassword(char *password, char *salt, int rounds); - -/** - Make salt for adding to a password. - @param size Size in bytes of the salt text. - @return The random salt text. - @ingroup Crypto - @stability Prototype - */ -PUBLIC char *websMakeSalt(ssize size); - -/** - Make a password hash for a plain-text password using the Blowfish algorithm. - @param password User's password to encrypt - @param saltLength Length of salt text to add to password. Helps to make each user's password unique. - @param rounds Number of times to encrypt. More times, makes the routine slower and passwords harder to crack. - @return The encrypted password. - @ingroup Crypto - @stability Prototype - */ -PUBLIC char *websMakePassword(char *password, int saltLength, int rounds); - -/** - Check a plain-text password against the defined hashed password. - @param plainTextPassword User's plain-text-password to check - @param passwordHash Required password in hashed format previously computed by websMakePassword. - @return True if the password is correct. - @ingroup Crypto - @stability Prototype - */ -PUBLIC bool websCheckPassword(char *plainTextPassword, char *passwordHash); - -/** - Get a password from the terminal console - @param prompt Text prompt to display before reading the password - @return The entered password. - @ingroup Crypto - @stability Prototype - */ -PUBLIC char *websReadPassword(char *prompt); - -/*************************************** JST ***********************************/ - -#if ME_GOAHEAD_JAVASCRIPT -/** - Javascript native function - @param jid JavaScript engine ID - @param wp Webs request object - @param argc Count of function arguments - @param argv Array of function arguments - @param defaultValue Default value to return if the variable is not defined - @return Return zero if successful, otherwise -1. - @ingroup Webs - @stability Stable - */ -typedef int (*WebsJstProc)(int jid, Webs *wp, int argc, char **argv); - -/** - Define a Javscript native function. - @description This routine binds a C function to a Javascript function. When the Javascript function is called, - the C function is invoked. - @param name Javascript function name - @param fn C function to invoke - @return Zero if successful, otherwise -1. - @ingroup Webs - @stability Stable - */ -PUBLIC int websDefineJst(char *name, WebsJstProc fn); - -/** - Open the Javascript module. - @return Zero if successful, otherwise -1. - @ingroup Webs - @stability Stable - */ -PUBLIC int websJstOpen(); - -/** - Write data to the response - @param jid Javascript ID handle - @param wp Webs request object - @param argc Count of arguments - @param argv Array arguments - @return Zero if successful, otherwise -1. - @ingroup Webs - @stability Stable - */ -PUBLIC int websJstWrite(int jid, Webs *wp, int argc, char **argv); -#endif - -/*************************************** SSL ***********************************/ - -#if ME_COM_SSL -/* - Default MakeMe settings - */ -#ifndef ME_GOAHEAD_SSL_AUTHORITY -#define ME_GOAHEAD_SSL_AUTHORITY "" -#endif -#ifndef ME_GOAHEAD_SSL_CACHE -#define ME_GOAHEAD_SSL_CACHE 512 -#endif -#ifndef ME_GOAHEAD_SSL_CERTIFICATE -#define ME_GOAHEAD_SSL_CERTIFICATE "" -#endif -#ifndef ME_GOAHEAD_SSL_CIPHERS -#define ME_GOAHEAD_SSL_CIPHERS "" -#endif -#ifndef ME_GOAHEAD_SSL_KEY -#define ME_GOAHEAD_SSL_KEY "" -#endif -#ifndef ME_GOAHEAD_SSL_LOG_LEVEL -#define ME_GOAHEAD_SSL_LOG_LEVEL 4 -#endif -#ifndef ME_GOAHEAD_SSL_RENEGOTIATE -#define ME_GOAHEAD_SSL_RENEGOTIATE 1 -#endif -#ifndef ME_GOAHEAD_SSL_REVOKE -#define ME_GOAHEAD_SSL_REVOKE "" -#endif -#ifndef ME_GOAHEAD_SSL_TICKET -#define ME_GOAHEAD_SSL_TICKET 1 -#endif -#ifndef ME_GOAHEAD_SSL_TIMEOUT -#define ME_GOAHEAD_SSL_TIMEOUT 86400 -#endif -#ifndef ME_GOAHEAD_SSL_VERIFY -#define ME_GOAHEAD_SSL_VERIFY 0 -#endif -#ifndef ME_GOAHEAD_SSL_VERIFY_ISSUER -#define ME_GOAHEAD_SSL_VERIFY_ISSUER 0 -#endif - -/** - Open the ssl module - @return Zero if successful, otherwise -1. - @ingroup Webs - @stability Stable - */ -PUBLIC int sslOpen(); - -/** - Close the ssl module - @ingroup Webs - @stability Stable - */ -PUBLIC void sslClose(); - -/** - Free a ssl connection associated with a request - @param wp Webs request object - @ingroup Webs - @stability Stable - */ -PUBLIC void sslFree(Webs *wp); - -/** - Upgrade a request connection to utilize SSL - @description This routine is invoked on a connection received on a secure listening socket - @param wp Webs request object - @return Zero if successful, otherwise -1. - @ingroup Webs - @stability Stable - */ -PUBLIC int sslUpgrade(Webs *wp); - -/** - Read data from a secure socket - @param wp Webs request object - @param buf Buffer into which to read data - @param len Size of buf - @return Count of bytes read if successful, otherwise -1. - @ingroup Webs - @stability Stable - */ -PUBLIC ssize sslRead(Webs *wp, void *buf, ssize len); - -/** - WRite data to a secure socket - @param wp Webs request object - @param buf Buffer from which to write data - @param len Size of buf - @return Count of bytes written if successful, otherwise -1. - @ingroup Webs - @stability Stable - */ -PUBLIC ssize sslWrite(Webs *wp, void *buf, ssize len); -#endif /* ME_COM_SSL */ - -/*************************************** Route *********************************/ -/** - Callback to prompt the user for their password - @param wp Webs request object - @ingroup Webs - @stability Stable - */ -typedef void (*WebsAskLogin)(Webs *wp); - -/** - Callback to verify the username and password - @param wp Webs request object - @return True if the password is verified - @ingroup Webs - @stability Stable - */ -typedef bool (*WebsVerify)(Webs *wp); - -/** - Callback to parse authentication details submitted with the web request - @param wp Webs request object - @return True if the details can be parsed - @ingroup Webs - @stability Stable - */ -typedef bool (*WebsParseAuth)(Webs *wp); - -/** - Request route structure - @defgroup WebsRoute WebsRoute - */ -typedef struct WebsRoute -{ - char *prefix; /**< Route path prefix */ - ssize prefixLen; /**< Prefix length */ - char *dir; /**< Filesystem base directory for route documents */ - char *protocol; /**< HTTP protocol to use for this route */ - char *authType; /**< Authentication type */ - WebsHandler *handler; /**< Request handler to service requests */ - WebsHash abilities; /**< Required user abilities */ - WebsHash extensions; /**< Permissible URI extensions */ - WebsHash redirects; /**< Response redirections */ - WebsHash methods; /**< Supported HTTP methods */ - WebsAskLogin askLogin; /**< Route path prefix */ - WebsParseAuth parseAuth; /**< Parse authentication details callback*/ - WebsVerify verify; /**< Verify password callback */ - int flags; /**< Route control flags */ -} WebsRoute; - -/** - Add a route to the routing tables - @param uri Matching URI prefix - @param handler Request handler to service routed requests - @param pos Position in the list of routes. Zero inserts at the front of the list. A value of -1 will append to the - end of the list. - @return A route object - @ingroup WebsRoute - @stability Stable - */ -PUBLIC WebsRoute *websAddRoute(char *uri, char *handler, int pos); - -/** - Close the route module - @ingroup WebsRoute - @stability Stable - */ -PUBLIC void websCloseRoute(); - -/** - Load routing tables from the specified filename - @param path Route configuration filename - @return Zero if successful, otherwise -1. - @ingroup WebsRoute - @stability Stable - */ -PUBLIC int websLoad(char *path); - -/** - Open the routing module - @ingroup WebsRoute - @stability Stable - */ -PUBLIC int websOpenRoute(); - -/** - Remove a route from the routing tables - @param uri Matching URI prefix - @return Zero if successful, otherwise -1. - @ingroup WebsRoute - @stability Stable - */ -PUBLIC int websRemoveRoute(char *uri); - -/** - Route a request - @description This routine will select a matching route and will invoke the selected route handler to service - the request. In the process, authentication and request rewriting may take place. - This routine is called internally by the request pipeline. - @param wp Webs request object - @ingroup WebsRoute - @stability Stable - */ -PUBLIC void websRouteRequest(Webs *wp); - -/** - Run a request handler - @description This routine will run the handler and route selected by #websRouteRequest. - This routine is called internally by the request pipeline. - @param wp Webs request object - @return True if the handler serviced the request. Return false to test other routes to handle this request. - This is for legacy handlers that do not have a match callback. - @ingroup WebsRoute - @stability Stable - */ -PUBLIC bool websRunRequest(Webs *wp); - -/** - Configure a route by adding matching criteria - @param route Route to modify - @param dir Set the route documents directory filename - @param protocol Set the matching HTTP protocol (http or https) - @param methods Hash of permissible HTTP methods. (GET, HEAD, POST, PUT) - @param extensions Hash of permissible URI filename extensions. - @param abilities Required user abilities. The user must be authenticated. - @param abilities Required user abilities. If abilities are required, the user must be authenticated. - @param redirects Set of applicable response redirections when completing the request. - @return Zero if successful, otherwise -1. - @ingroup WebsRoute - @stability Evolving - */ -PUBLIC int websSetRouteMatch(WebsRoute *route, char *dir, char *protocol, WebsHash methods, WebsHash extensions, - WebsHash abilities, WebsHash redirects); - -/** - Set route authentication scheme - @param route Route to modify - @param authType Set to "basic", "digest" or "form". - @return Zero if successful, otherwise -1. - @ingroup WebsRoute - @stability Stable - */ -PUBLIC int websSetRouteAuth(WebsRoute *route, char *authType); - -/*************************************** Auth **********************************/ -#if ME_GOAHEAD_AUTH - -#define WEBS_USIZE 128 /* Size of realm:username */ - -/** - GoAhead Authentication - @defgroup WebsAuth WebsAuth - */ -/** - User definition structure - @ingroup WebsAuth - @stability Stable - */ -typedef struct WebsUser -{ - char *name; /**< User name */ - char *password; /**< User password (encrypted) */ - char *roles; /**< User roles */ - WebsHash abilities; /**< Resolved user abilities */ -} WebsUser; - -/** - Role definition structure - @ingroup WebsAuth - @stability Stable - */ -typedef struct WebsRole -{ - WebsHash abilities; /**< Resolved role abilities */ -} WebsRole; - -/** - Add a role - @description The role is added to the list of roles - @param role Role name - @param abilities Hash of abilities for the role - @return The allocated role. - @ingroup WebsAuth - @stability Stable - */ -PUBLIC WebsRole *websAddRole(char *role, WebsHash abilities); - -/** - Add a user - @description The user is added to the list of users - @param username User name - @param password User password (encrypted) - @param roles Space separated list of roles. This may also contain abilities. - @return User object. - @ingroup WebsAuth - @stability Stable - */ -PUBLIC WebsUser *websAddUser(char *username, char *password, char *roles); - -/** - Authenticate a user - @description The user is authenticated if required by the selected request route. - @param wp Webs request object - @return True if the route does not require authentication or the user is authenticated successfully. - @ingroup WebsAuth - @stability Stable - */ -PUBLIC bool websAuthenticate(Webs *wp); - -/** - Test if a user possesses the required ability - @param wp Webs request object - @param ability Set of required abilities. - @return True if the user has the required ability. - @ingroup WebsAuth - @stability Stable - */ -PUBLIC bool websCan(Webs *wp, WebsHash ability); - -/** - Close the authentication module - @ingroup WebsAuth - @stability Stable - */ -PUBLIC void websCloseAuth(); - -/** - Compute the abilities for all users by resolving roles into abilities - @ingroup WebsAuth - @stability Stable - */ -PUBLIC void websComputeAllUserAbilities(); - -/** - Set the password store verify callback - @return verify WebsVerify callback function - @ingroup WebsAuth - @stability Stable - */ -PUBLIC WebsVerify websGetPasswordStoreVerify(); - -/** - Get the roles hash - @return The roles hash object - @ingroup WebsAuth - @stability Stable - */ -PUBLIC WebsHash websGetRoles(); - -/** - Get the users hash - @return The users hash object - @ingroup WebsAuth - @stability Stable - */ -PUBLIC WebsHash websGetUsers(); - -/** - Login a user by verifying the login credentials. - @description This may be called by handlers to manually authenticate a user. - @param wp Webs request object - @param username User name - @param password User password (encrypted) - @return True if the user can be authenticated. - @ingroup WebsAuth - @stability Stable - */ -PUBLIC bool websLoginUser(Webs *wp, char *username, char *password); - -/** - Logout a user and remove the user login session. - @param wp Webs request object - @return True if successful. - @ingroup WebsAuth - @stability Stable - */ -PUBLIC bool websLogoutUser(Webs *wp); - -/** - Lookup if a user exists - @param username User name to search for - @return User object or null if the user cannot be found - @ingroup WebsAuth - @stability Stable - */ -PUBLIC WebsUser *websLookupUser(char *username); - -/** - Remove a role from the system - @param role Role name - @return Zero if successful, otherwise -1 - @ingroup WebsAuth - @stability Stable - */ -PUBLIC int websRemoveRole(char *role); - -/** - Remove a user from the system - @param name User name - @return Zero if successful, otherwise -1 - @ingroup WebsAuth - @stability Stable - */ -PUBLIC int websRemoveUser(char *name); - -/** - Open the authentication module - @param minimal Reserved. Set to zero. - @return True if the user has the required ability. - @ingroup WebsAuth - @stability Stable - */ -PUBLIC int websOpenAuth(int minimal); - -/** - Set the password store verify callback - @param verify WebsVerify callback function - @ingroup WebsAuth - @stability Stable - */ -PUBLIC void websSetPasswordStoreVerify(WebsVerify verify); - -/** - Set a password for the user - @param username User name - @param password Null terminated password string - @return Zero if successful, otherwise -1. - @ingroup WebsAuth - @stability Stable - */ -PUBLIC int websSetUserPassword(char *username, char *password); - - -/** - Define the set of roles for a user - @param username User name - @param roles Space separated list of roles or abilities - @return Zero if successful, otherwise -1. - @ingroup WebsAuth - @stability Stable - */ -PUBLIC int websSetUserRoles(char *username, char *roles); - -/** - User password verification routine from a custom password back-end store. - @param wp Webs request object - @return True if the user password verifies. - @ingroup WebsAuth - @stability Stable - */ -PUBLIC bool websVerifyPasswordFromCustom(Webs *wp); - -/** - User password verification routine from auth.txt - @param wp Webs request object - @return True if the user password verifies. - @ingroup WebsAuth - @stability Stable - */ -PUBLIC bool websVerifyPasswordFromFile(Webs *wp); - -#if ME_COMPILER_HAS_PAM -/** - Verify a password using the system PAM password database. - @param wp Webs request object - @return True if the user password verifies. - @ingroup WebsAuth - @stability Stable - */ -PUBLIC bool websVerifyPasswordFromPam(Webs *wp); -#endif - -#endif /* ME_GOAHEAD_AUTH */ -/************************************** Sessions *******************************/ -/** - Session state storage - @defgroup WebsSession WebsSession - */ -typedef struct WebsSession -{ - char *id; /**< Session ID key */ - int lifespan; /**< Session inactivity timeout (secs) */ - WebsTime expires; /**< When the session expires */ - WebsHash cache; /**< Cache of session variables */ -} WebsSession; - -/** - Test if a user possesses the required ability - @param wp Webs request object - @param id Session ID to use. Set to null to allocate a new session ID. - @param lifespan Lifespan of the session in seconds. - @return Allocated session object - @ingroup WebsSession - @stability Stable - */ -PUBLIC WebsSession *websAllocSession(Webs *wp, char *id, int lifespan); - -/** - Test if a user possesses the required ability - @param wp Webs request object - @return Allocated session object - @ingroup WebsSession - @stability Stable - */ -PUBLIC WebsSession *websCreateSession(Webs *wp); - -/** - Destroy the webs session object - @description Useful to be called as part of the user logout process - @param wp Webs request object - @ingroup WebsSession - @stability Prototype - */ -PUBLIC void websDestroySession(Webs *wp); - -/** - Get the session ID - @param wp Webs request object - @return The session ID if session state storage is defined for this request. - @ingroup WebsSession - @stability Stable - */ -PUBLIC char *websGetSessionID(Webs *wp); - -/** - Get the session state object for the current request - @param wp Webs request object - @param create Set to true to create a new session if one does not already exist. - @return Session object - @ingroup WebsSession - @stability Stable - */ -PUBLIC WebsSession *websGetSession(Webs *wp, int create); - -/** - Get a session variable - @param wp Webs request object - @param name Session variable name - @param defaultValue Default value to return if the variable does not exist - @return Session variable value or default value if it does not exist - @ingroup WebsSession - @stability Stable - */ -PUBLIC char *websGetSessionVar(Webs *wp, char *name, char *defaultValue); - -/** - Remove a session variable - @param wp Webs request object - @param name Session variable name - @ingroup WebsSession - @stability Stable - */ -PUBLIC void websRemoveSessionVar(Webs *wp, char *name); - -/** - Set a session variable name value - @param wp Webs request object - @param name Session variable name - @param value Value to set the variable to - @return Zero if successful, otherwise -1 - @ingroup WebsSession - @stability Stable - */ -PUBLIC int websSetSessionVar(Webs *wp, char *name, char *value); - -/************************************ Legacy **********************************/ -/* - Legacy mappings for pre GoAhead 3.X applications - This is a list of the name changes from GoAhead 2.X to GoAhead 3.x - To maximize forward compatibility, It is best to not use ME_GOAHEAD_LEGACY except as - a transitional compilation aid. - */ -#if ME_GOAHEAD_LEGACY -#define B_L 0 -#define a_assert assert -#define balloc walloc -#define bclose wcloseAlloc -#define bfree(loc, p) wfree(p) -#define bfreeSafe(loc, p) wfree(p) -#define bopen wopenAlloc -#define brealloc wrealloc -#define bstrdup sclone -#define emfReschedCallback websRestartEvent -#define emfSchedCallback websStartEvent -#define emfSchedProc WebsEventProc -#define emfSchedProcess websRunEvents -#define emfUnschedCallback websStopEvent -#define fmtStatic fmt -#define gassert assert -#define galloc walloc -#define gallocEntry wallocObject -#define gfree wfree -#define gFree wfreeHandle -#define grealloc wrealloc -#define gaccess access -#define gasctime asctime -#define gatoi atoi -#define gchmod chmod -#define wclose close -#define wclosedir closedir -#define gcreat creat -#define gctime ctime -#define gexecvp execvp -#define gfgets fgets -#define gfindclose _findclose -#define gfinddata_t _finddata_t -#define gfindfirst _findfirst -#define gfindnext _findnext -#define gfopen fopen -#define gfprintf fprintf -#define gfputs fputs -#define gfscanf fscanf -#define ggetcwd getcwd -#define ggetenv getenv -#define ggets gets -#define gisalnum isalnum -#define gisalpha isalpha -#define gisdigit isdigit -#define gislower islower -#define gisspace isspace -#define gisupper isupper -#define gisxdigit isxdigit -#define gloadModule loadModule -#define glseek lseek -#define gopendir opendir -#define gprintf printf -#define gread read -#define greaddir readdir -#define gremove remove -#define grename rename -#define gsprintf sprintf -#define gsscanf sscanf -#define gstat stat -#define gstrcat strcat -#define gstrchr strchr -#define gstrcmp strcmp -#define gstrcpy strcpy -#define gstrcspn strcspn -#define gstricmp strcmpci -#define gstritoa stritoa -#define gstrlen strlen -#define gstrlower strlower -#define gstrncat strncat -#define gstrncmp strncmp -#define gstrncpy strncpy -#define gstrnlen strnlen -#define gstrnset strnset -#define gstrrchr strrchr -#define gstrspn strspn -#define gstrstr strstr -#define gstrtok strtok -#define gstrtol strtol -#define gstrupper strupper -#define gtempnam websTempFile -#define gtolower tolower -#define gtoupper toupper -#define gunlink unlink -#define gvsprintf vsprintf -#define gwrite write -#define hAlloc wallocHandle -#define hAllocEntry wallocObject -#define hFree wfreeHandle -#define stritoa gstritoa -#define strlower gstrlower -#define strupper gstrupper -#define websAspDefine websDefineJst -#define websAspOpen websJstOpen -#define websAspRequest websJstRequest -#define websFormDefine websDefineAction -#define websGetDefaultDir websGetDocuments -#define websGetDefaultPage websGetIndex - -#define websGetRequestDir(wp) wp->dir -#define websGetRequestIpAddr(wp) wp->ipaddr -#define websGetRequestFilename(wp) wp->filename -#define websGetRequestFlags(wp) wp->flags -#define websGetRequestLpath(wp) wp->filename -#define websGetRequestPath(wp) wp->path -#define websGetRequestPassword(wp) wp->password -#define websGetRequestUserName(wp) wp->username -#define websGetRequestWritten(wp) wp->written - -#define websSetDefaultDir websSetDocuments -#define websSetDefaultPage websSetIndex -#define websSetRequestLpath websSetRequestFilename -#define websSetRequestWritten(wp, nbytes) if (1) { wp->written = nbytes; } else {} -#define websTimeoutCancel websCancelTimeout -#define websWriteDataNonBlock websWriteRaw - -#define ringqOpen bufCreate -#define ringqClose bufFree -#define ringqLen bufLen -#define ringqPutc bufPutc -#define ringqInsertc bufInsertc -#define ringqPutStr bufPutStr -#define ringqGetc bufGetc -#define ringqGrow bufGrow -#define ringqPutBlk bufPutBlk -#define ringqPutBlkMax bufRoom -#define ringqPutBlkAdj bufAdjustEnd -#define ringqGetBlk bufGetBlk -#define ringqGetBlkMax bufGetBlkMax -#define ringqGetBlkAdj bufAdjustSTart -#define ringqFlush bufFlush -#define ringqCompact bufCompact -#define ringqReset bufReset -#define ringqAddNull bufAddNull - -#define symCreate hashCreate -#define symClose hashFree -#define symLookup hashLookup -#define symEnter hashEnter -#define symDelete hashDelete -#define symWalk hashWalk -#define symFirst hashFirst -#define symNext hashNext - -typedef Webs *webs_t; -typedef Webs WebsRec; -typedef Webs websType; -typedef WebsBuf ringq_t; -typedef WebsError websErrorType; -typedef WebsProc WebsFormProc; -typedef int (*WebsLegacyHandlerProc)(Webs *wp, char *prefix, char *dir, int flags); -typedef SocketHandler socketHandler_t; -typedef SocketAccept socketAccept_t; -typedef WebsType vtype_t; - -typedef WebsHash sym_fd_t; -typedef WebsKey sym_t; -typedef WebsMime websMimeType; -typedef WebsSocket socket_t; -typedef WebsStat gstat_t; -typedef WebsValue value_t; - -PUBLIC int fmtValloc(char **s, int n, char *fmt, va_list arg); -PUBLIC int fmtAlloc(char **s, int n, char *fmt, ...); -PUBLIC void websFooter(Webs *wp); -PUBLIC void websHeader(Webs *wp); -PUBLIC int websPublish(char *prefix, char *path); -PUBLIC void websSetRequestFilename(Webs *wp, char *filename); -PUBLIC int websUrlHandlerDefine(char *prefix, char *dir, int arg, WebsLegacyHandlerProc handler, int flags); - -#if ME_ROM -typedef WebsRomIndex websRomIndexType; -#endif -#endif - -#if ME_CUSTOMIZE -#include "customize.h" -#endif - - -/*-----------------------------------------add by lyj 10.29*/ - -typedef void(*WebsActProc)(Webs *wp); - -typedef struct __go_asp_func_t -{ - int func_type; // 1:jst 2:action - char fn_name[32]; - WebsJstProc jst_fn; - WebsActProc act_fn; -} go_asp_func_t; - - -typedef struct __go_asp_func_reg_t -{ - int func_num; - go_asp_func_t funcList[128]; -} go_asp_func_reg_t; - - -int start_goahead(char *home, char *documents, char *endpoint, char *route, char *auth, go_asp_func_t *pFunc, int FuncNum); - -/*------------------------------------------*/ -WebsSession *websCheckSession(Webs *wp, char *session_ptr, int *session_len); //add by wenyi 2019-01-25 - - -#ifdef __cplusplus -} -#endif -#endif /* _h_GOAHEAD */ - -/* - Copyright (c) Embedthis Software. All Rights Reserved. - This software is distributed under commercial and open source licenses. - You may use the Embedthis GoAhead open source license or you may acquire - a commercial license from Embedthis Software. You agree to be fully bound - by the terms of either license. Consult the LICENSE.md distributed with - this software for full details and other copyrights. - */ diff --git a/app/bmc/inc/me.h b/app/bmc/inc/me.h deleted file mode 100644 index 1380acece..000000000 --- a/app/bmc/inc/me.h +++ /dev/null @@ -1,390 +0,0 @@ -/* - me.h -- MakeMe Configure Header for linux-x86-default - - This header is created by Me during configuration. To change settings, re-run - configure or define variables in your Makefile to override these default values. - */ - -/* Settings */ -#ifndef ME_AUTHOR - #define ME_AUTHOR "Embedthis Software" -#endif -#ifndef ME_CERTS_BITS - #define ME_CERTS_BITS 2048 -#endif -#ifndef ME_CERTS_DAYS - #define ME_CERTS_DAYS 3650 -#endif -#ifndef ME_CERTS_GENDH - #define ME_CERTS_GENDH 1 -#endif -#ifndef ME_COMPANY - #define ME_COMPANY "embedthis" -#endif -#ifndef ME_COMPATIBLE - #define ME_COMPATIBLE "3.6" -#endif -#ifndef ME_COMPILER_FORTIFY - #define ME_COMPILER_FORTIFY 1 -#endif -#ifndef ME_COMPILER_HAS_ATOMIC - #define ME_COMPILER_HAS_ATOMIC 0 -#endif -#ifndef ME_COMPILER_HAS_ATOMIC64 - #define ME_COMPILER_HAS_ATOMIC64 0 -#endif -#ifndef ME_COMPILER_HAS_DOUBLE_BRACES - #define ME_COMPILER_HAS_DOUBLE_BRACES 0 -#endif -#ifndef ME_COMPILER_HAS_DYN_LOAD - #define ME_COMPILER_HAS_DYN_LOAD 1 -#endif -#ifndef ME_COMPILER_HAS_LIB_EDIT - #define ME_COMPILER_HAS_LIB_EDIT 0 -#endif -#ifndef ME_COMPILER_HAS_LIB_RT - #define ME_COMPILER_HAS_LIB_RT 1 -#endif -#ifndef ME_COMPILER_HAS_MMU - #define ME_COMPILER_HAS_MMU 1 -#endif -#ifndef ME_COMPILER_HAS_MTUNE - #define ME_COMPILER_HAS_MTUNE 1 -#endif -#ifndef ME_COMPILER_HAS_PAM - #define ME_COMPILER_HAS_PAM 0 -#endif -#ifndef ME_COMPILER_HAS_STACK_PROTECTOR - #define ME_COMPILER_HAS_STACK_PROTECTOR 1 -#endif -#ifndef ME_COMPILER_HAS_SYNC - #define ME_COMPILER_HAS_SYNC 1 -#endif -#ifndef ME_COMPILER_HAS_SYNC64 - #define ME_COMPILER_HAS_SYNC64 1 -#endif -#ifndef ME_COMPILER_HAS_SYNC_CAS - #define ME_COMPILER_HAS_SYNC_CAS 0 -#endif -#ifndef ME_COMPILER_HAS_UNNAMED_UNIONS - #define ME_COMPILER_HAS_UNNAMED_UNIONS 1 -#endif -#ifndef ME_COMPILER_WARN64TO32 - #define ME_COMPILER_WARN64TO32 0 -#endif -#ifndef ME_COMPILER_WARN_UNUSED - #define ME_COMPILER_WARN_UNUSED 1 -#endif -#ifndef ME_DEBUG - #define ME_DEBUG 1 -#endif -#ifndef ME_DEPTH - #define ME_DEPTH 1 -#endif -#ifndef ME_DESCRIPTION - #define ME_DESCRIPTION "Embedthis GoAhead Embedded Web Server" -#endif -#ifndef ME_GOAHEAD_ACCESS_LOG - #define ME_GOAHEAD_ACCESS_LOG 0 -#endif -#ifndef ME_GOAHEAD_AUTH - #define ME_GOAHEAD_AUTH 1 -#endif -#ifndef ME_GOAHEAD_AUTH_STORE - #define ME_GOAHEAD_AUTH_STORE "file" -#endif -#ifndef ME_GOAHEAD_AUTO_LOGIN - #define ME_GOAHEAD_AUTO_LOGIN 0 -#endif -#ifndef ME_GOAHEAD_CGI - #define ME_GOAHEAD_CGI 1 -#endif -#ifndef ME_GOAHEAD_CGI_VAR_PREFIX - #define ME_GOAHEAD_CGI_VAR_PREFIX "CGI_" -#endif -#ifndef ME_GOAHEAD_CLIENT_CACHE - #define ME_GOAHEAD_CLIENT_CACHE "css,gif,ico,jpg,js,png" -#endif -#ifndef ME_GOAHEAD_CLIENT_CACHE_LIFESPAN - #define ME_GOAHEAD_CLIENT_CACHE_LIFESPAN 86400 -#endif -#ifndef ME_GOAHEAD_DIGEST - #define ME_GOAHEAD_DIGEST 1 -#endif -#ifndef ME_GOAHEAD_DOCUMENTS - #define ME_GOAHEAD_DOCUMENTS "web" -#endif -#ifndef ME_GOAHEAD_JAVASCRIPT - #define ME_GOAHEAD_JAVASCRIPT 1 -#endif -#ifndef ME_GOAHEAD_LEGACY - #define ME_GOAHEAD_LEGACY 0 -#endif -#ifndef ME_GOAHEAD_LIMIT_BUFFER - #define ME_GOAHEAD_LIMIT_BUFFER 1024 -#endif -#ifndef ME_GOAHEAD_LIMIT_FILENAME - #define ME_GOAHEAD_LIMIT_FILENAME 256 -#endif -#ifndef ME_GOAHEAD_LIMIT_FILES - #define ME_GOAHEAD_LIMIT_FILES 0 -#endif -#ifndef ME_GOAHEAD_LIMIT_HEADER - #define ME_GOAHEAD_LIMIT_HEADER 4096 //modify by wenyi 2019-04-12 -#endif -#ifndef ME_GOAHEAD_LIMIT_HEADERS - #define ME_GOAHEAD_LIMIT_HEADERS 4096 -#endif -#ifndef ME_GOAHEAD_LIMIT_NUM_HEADERS - #define ME_GOAHEAD_LIMIT_NUM_HEADERS 64 -#endif -#ifndef ME_GOAHEAD_LIMIT_PARSE_TIMEOUT - #define ME_GOAHEAD_LIMIT_PARSE_TIMEOUT 5 -#endif -#ifndef ME_GOAHEAD_LIMIT_PASSWORD - #define ME_GOAHEAD_LIMIT_PASSWORD 32 -#endif -#ifndef ME_GOAHEAD_LIMIT_POST - #define ME_GOAHEAD_LIMIT_POST 204800000 -#endif -#ifndef ME_GOAHEAD_LIMIT_PUT - #define ME_GOAHEAD_LIMIT_PUT 204800000 -#endif -#ifndef ME_GOAHEAD_LIMIT_SESSION_COUNT - #define ME_GOAHEAD_LIMIT_SESSION_COUNT 512 -#endif -#ifndef ME_GOAHEAD_LIMIT_SESSION_LIFE - #define ME_GOAHEAD_LIMIT_SESSION_LIFE 1800 -#endif -#ifndef ME_GOAHEAD_LIMIT_STRING - #define ME_GOAHEAD_LIMIT_STRING 256 -#endif -#ifndef ME_GOAHEAD_LIMIT_TIMEOUT - #define ME_GOAHEAD_LIMIT_TIMEOUT 60 -#endif -#ifndef ME_GOAHEAD_LIMIT_UPLOAD - #define ME_GOAHEAD_LIMIT_UPLOAD 204800000 -#endif -#ifndef ME_GOAHEAD_LIMIT_URI - #define ME_GOAHEAD_LIMIT_URI 2048 -#endif -#ifndef ME_GOAHEAD_LISTEN - #define ME_GOAHEAD_LISTEN "http://*:80,https://*:443" -#endif -#ifndef ME_GOAHEAD_LOGFILE - #define ME_GOAHEAD_LOGFILE "stderr:0" -#endif -#ifndef ME_GOAHEAD_LOGGING - #define ME_GOAHEAD_LOGGING 1 -#endif -#ifndef ME_GOAHEAD_PUT_DIR - #define ME_GOAHEAD_PUT_DIR "." -#endif -#ifndef ME_GOAHEAD_REALM - #define ME_GOAHEAD_REALM "example.com" -#endif -#ifndef ME_GOAHEAD_REPLACE_MALLOC - #define ME_GOAHEAD_REPLACE_MALLOC 0 -#endif -#ifndef ME_GOAHEAD_SSL_AUTHORITY - #define ME_GOAHEAD_SSL_AUTHORITY "" -#endif -#ifndef ME_GOAHEAD_SSL_CACHE - #define ME_GOAHEAD_SSL_CACHE 512 -#endif -#ifndef ME_GOAHEAD_SSL_CERTIFICATE - #define ME_GOAHEAD_SSL_CERTIFICATE "/mnt/self.crt" //lyj -#endif -#ifndef ME_GOAHEAD_SSL_CIPHERS - #define ME_GOAHEAD_SSL_CIPHERS "" -#endif -#ifndef ME_GOAHEAD_SSL_HANDSHAKES - #define ME_GOAHEAD_SSL_HANDSHAKES 1 -#endif -#ifndef ME_GOAHEAD_SSL_KEY - #define ME_GOAHEAD_SSL_KEY "/mnt/self.key" //lyj -#endif -#ifndef ME_GOAHEAD_SSL_LOG_LEVEL - #define ME_GOAHEAD_SSL_LOG_LEVEL 5 -#endif -#ifndef ME_GOAHEAD_SSL_REVOKE - #define ME_GOAHEAD_SSL_REVOKE "" -#endif -#ifndef ME_GOAHEAD_SSL_TICKET - #define ME_GOAHEAD_SSL_TICKET 1 -#endif -#ifndef ME_GOAHEAD_SSL_TIMEOUT - #define ME_GOAHEAD_SSL_TIMEOUT 86400 -#endif -#ifndef ME_GOAHEAD_SSL_VERIFY_ISSUER - #define ME_GOAHEAD_SSL_VERIFY_ISSUER 0 -#endif -#ifndef ME_GOAHEAD_SSL_VERIFY_PEER - #define ME_GOAHEAD_SSL_VERIFY_PEER 0 -#endif -#ifndef ME_GOAHEAD_STEALTH - #define ME_GOAHEAD_STEALTH 1 -#endif -#ifndef ME_GOAHEAD_TRACING - #define ME_GOAHEAD_TRACING 1 -#endif -#ifndef ME_GOAHEAD_UPLOAD - #define ME_GOAHEAD_UPLOAD 1 -#endif -#ifndef ME_GOAHEAD_UPLOAD_DIR - #define ME_GOAHEAD_UPLOAD_DIR "/tmp" -#endif -#ifndef ME_GOAHEAD_XFRAME_HEADER - #define ME_GOAHEAD_XFRAME_HEADER "SAMEORIGIN" -#endif -#ifndef ME_INTEGRATE - #define ME_INTEGRATE 1 -#endif -#ifndef ME_MANIFEST - #define ME_MANIFEST "installs/manifest.me" -#endif -#ifndef ME_MBEDTLS_COMPACT - #define ME_MBEDTLS_COMPACT 1 -#endif -#ifndef ME_NAME - #define ME_NAME "goahead" -#endif -#ifndef ME_PREFIXES - #define ME_PREFIXES "install-prefixes" -#endif -#ifndef ME_ROM - #define ME_ROM 0 -#endif -#ifndef ME_TITLE - #define ME_TITLE "Embedthis GoAhead" -#endif -#ifndef ME_VERSION - #define ME_VERSION "3.6.5" -#endif - -/* Prefixes */ -#ifndef ME_ROOT_PREFIX - #define ME_ROOT_PREFIX "/" -#endif -#ifndef ME_BASE_PREFIX - #define ME_BASE_PREFIX "/usr/local" -#endif -#ifndef ME_DATA_PREFIX - #define ME_DATA_PREFIX "/" -#endif -#ifndef ME_STATE_PREFIX - #define ME_STATE_PREFIX "/var" -#endif -#ifndef ME_APP_PREFIX - #define ME_APP_PREFIX "/usr/local/lib/goahead" -#endif -#ifndef ME_VAPP_PREFIX - #define ME_VAPP_PREFIX "/usr/local/lib/goahead/3.6.5" -#endif -#ifndef ME_BIN_PREFIX - #define ME_BIN_PREFIX "/usr/local/bin" -#endif -#ifndef ME_INC_PREFIX - #define ME_INC_PREFIX "/usr/local/include" -#endif -#ifndef ME_LIB_PREFIX - #define ME_LIB_PREFIX "/usr/local/lib" -#endif -#ifndef ME_MAN_PREFIX - #define ME_MAN_PREFIX "/usr/local/share/man" -#endif -#ifndef ME_SBIN_PREFIX - #define ME_SBIN_PREFIX "/usr/local/sbin" -#endif -#ifndef ME_ETC_PREFIX - #define ME_ETC_PREFIX "/etc/goahead" -#endif -#ifndef ME_WEB_PREFIX - #define ME_WEB_PREFIX "/var/www/goahead" -#endif -#ifndef ME_LOG_PREFIX - #define ME_LOG_PREFIX "/var/log/goahead" -#endif -#ifndef ME_SPOOL_PREFIX - #define ME_SPOOL_PREFIX "/var/spool/goahead" -#endif -#ifndef ME_CACHE_PREFIX - #define ME_CACHE_PREFIX "/var/spool/goahead/cache" -#endif -#ifndef ME_SRC_PREFIX - #define ME_SRC_PREFIX "goahead-3.6.5" -#endif - -/* Suffixes */ -#ifndef ME_EXE - #define ME_EXE "" -#endif -#ifndef ME_SHLIB - #define ME_SHLIB ".so" -#endif -#ifndef ME_SHOBJ - #define ME_SHOBJ ".so" -#endif -#ifndef ME_LIB - #define ME_LIB ".a" -#endif -#ifndef ME_OBJ - #define ME_OBJ ".o" -#endif - -/* Profile */ -#ifndef ME_CONFIG_CMD - #define ME_CONFIG_CMD "me -d -q -platform linux-x86-default -configure . -gen make" -#endif -#ifndef ME_GOAHEAD_PRODUCT - #define ME_GOAHEAD_PRODUCT 1 -#endif -#ifndef ME_PROFILE - #define ME_PROFILE "default" -#endif -#ifndef ME_TUNE_SIZE - #define ME_TUNE_SIZE 1 -#endif - -/* Miscellaneous */ -#ifndef ME_MAJOR_VERSION - #define ME_MAJOR_VERSION 3 -#endif -#ifndef ME_MINOR_VERSION - #define ME_MINOR_VERSION 6 -#endif -#ifndef ME_PATCH_VERSION - #define ME_PATCH_VERSION 5 -#endif -#ifndef ME_VNUM - #define ME_VNUM 300060005 -#endif - -/* Components */ -#ifndef ME_COM_CC - #define ME_COM_CC 1 -#endif -#ifndef ME_COM_LIB - #define ME_COM_LIB 1 -#endif -#ifndef ME_COM_MATRIXSSL - #define ME_COM_MATRIXSSL 0 -#endif -#ifndef ME_COM_MBEDTLS - #define ME_COM_MBEDTLS 1 -#endif -#ifndef ME_COM_NANOSSL - #define ME_COM_NANOSSL 0 -#endif -#ifndef ME_COM_OPENSSL - #define ME_COM_OPENSSL 0 -#endif -#ifndef ME_COM_OSDEP - #define ME_COM_OSDEP 1 -#endif -#ifndef ME_COM_SSL - #define ME_COM_SSL 1 -#endif -#ifndef ME_COM_VXWORKS - #define ME_COM_VXWORKS 0 -#endif diff --git a/app/bmc/inc/osdep.h b/app/bmc/inc/osdep.h deleted file mode 100644 index ffe87e3d6..000000000 --- a/app/bmc/inc/osdep.h +++ /dev/null @@ -1,1394 +0,0 @@ -/** - osdep.h -- O/S abstraction for products using MakeMe. - */ - -#ifndef _h_OSDEP -#define _h_OSDEP 1 - -/********************************** Includes **********************************/ - -#include "me.h" - -/******************************* Default Features *****************************/ -/* - MakeMe defaults - */ -#ifndef ME_COM_SSL - #define ME_COM_SSL 0 /**< Build without SSL support */ -#endif -#ifndef ME_DEBUG - #define ME_DEBUG 0 /**< Default to a debug build */ -#endif -#ifndef ME_FLOAT - #define ME_FLOAT 1 /**< Build with floating point support */ -#endif -#ifndef ME_ROM - #define ME_ROM 0 /**< Build for execute from ROM */ -#endif - -/********************************* CPU Families *******************************/ -/* - CPU Architectures - */ -#define ME_CPU_UNKNOWN 0 -#define ME_CPU_ARM 1 /**< Arm */ -#define ME_CPU_ITANIUM 2 /**< Intel Itanium */ -#define ME_CPU_X86 3 /**< X86 */ -#define ME_CPU_X64 4 /**< AMD64 or EMT64 */ -#define ME_CPU_MIPS 5 /**< Mips */ -#define ME_CPU_PPC 6 /**< Power PC */ -#define ME_CPU_SPARC 7 /**< Sparc */ -#define ME_CPU_TIDSP 8 /**< TI DSP */ -#define ME_CPU_SH 9 /**< SuperH */ - -/* - Byte orderings - */ -#define ME_LITTLE_ENDIAN 1 /**< Little endian byte ordering */ -#define ME_BIG_ENDIAN 2 /**< Big endian byte ordering */ - -/* - Use compiler definitions to determine the CPU type. - The default endianness can be overridden by configure --endian big|little. - */ -#if defined(__alpha__) - #define ME_CPU "alpha" - #define ME_CPU_ARCH ME_CPU_ALPHA - #define CPU_ENDIAN ME_LITTLE_ENDIAN - -#elif defined(__arm__) - #define ME_CPU "arm" - #define ME_CPU_ARCH ME_CPU_ARM - #define CPU_ENDIAN ME_LITTLE_ENDIAN - -#elif defined(__x86_64__) || defined(_M_AMD64) - #define ME_CPU "x64" - #define ME_CPU_ARCH ME_CPU_X64 - #define CPU_ENDIAN ME_LITTLE_ENDIAN - -#elif defined(__i386__) || defined(__i486__) || defined(__i585__) || defined(__i686__) || defined(_M_IX86) - #define ME_CPU "x86" - #define ME_CPU_ARCH ME_CPU_X86 - #define CPU_ENDIAN ME_LITTLE_ENDIAN - -#elif defined(_M_IA64) - #define ME_CPU "ia64" - #define ME_CPU_ARCH ME_CPU_ITANIUM - #define CPU_ENDIAN ME_LITTLE_ENDIAN - -#elif defined(__mips__) || defined(__mips64) - #define ME_CPU "mips" - #define ME_CPU_ARCH ME_CPU_MIPS - #define CPU_ENDIAN ME_BIG_ENDIAN - -#elif defined(__ppc__) || defined(__powerpc__) || defined(__ppc64__) || defined(__ppc) - #define ME_CPU "ppc" - #define ME_CPU_ARCH ME_CPU_PPC - #define CPU_ENDIAN ME_BIG_ENDIAN - -#elif defined(__sparc__) - #define ME_CPU "sparc" - #define ME_CPU_ARCH ME_CPU_SPARC - #define CPU_ENDIAN ME_BIG_ENDIAN - -#elif defined(_TMS320C6X) - #define TIDSP 1 - #define ME_CPU "tidsp" - #define ME_CPU_ARCH ME_CPU_SPARC - #define CPU_ENDIAN ME_LITTLE_ENDIAN - -#elif defined(__sh__) - #define ME_CPU "sh" - #define ME_CPU_ARCH ME_CPU_SH - #define CPU_ENDIAN ME_LITTLE_ENDIAN - -#else - #error "Cannot determine CPU type in osdep.h" -#endif - -/* - Set the default endian if me.h does not define it explicitly - */ -#ifndef ME_ENDIAN - #define ME_ENDIAN CPU_ENDIAN -#endif - -/* - Operating system defines. Use compiler standard defintions to sleuth. Works for all except VxWorks which does not - define any special symbol. NOTE: Support for SCOV Unix, LynxOS and UnixWare is deprecated. - */ -#if defined(__APPLE__) - #define ME_OS "macosx" - #define MACOSX 1 - #define ME_UNIX_LIKE 1 - #define ME_WIN_LIKE 0 - #define ME_BSD_LIKE 1 - #define HAS_USHORT 1 - #define HAS_UINT 1 - -#elif defined(__linux__) - #define ME_OS "linux" - #define LINUX 1 - #define ME_UNIX_LIKE 1 - #define ME_WIN_LIKE 0 - -#elif defined(__FreeBSD__) - #define ME_OS "freebsd" - #define FREEBSD 1 - #define ME_UNIX_LIKE 1 - #define ME_WIN_LIKE 0 - #define ME_BSD_LIKE 1 - -#elif defined(__OpenBSD__) - #define ME_OS "freebsd" - #define OPENBSD 1 - #define ME_UNIX_LIKE 1 - #define ME_WIN_LIKE 0 - #define ME_BSD_LIKE 1 - -#elif defined(_WIN32) - #define ME_OS "windows" - #define WINDOWS 1 - #define ME_UNIX_LIKE 0 - #define ME_WIN_LIKE 1 - -#elif defined(__OS2__) - #define ME_OS "os2" - #define OS2 0 - #define ME_UNIX_LIKE 0 - #define ME_WIN_LIKE 0 - -#elif defined(MSDOS) || defined(__DME__) - #define ME_OS "msdos" - #define WINDOWS 0 - #define ME_UNIX_LIKE 0 - #define ME_WIN_LIKE 0 - -#elif defined(__NETWARE_386__) - #define ME_OS "netware" - #define NETWARE 0 - #define ME_UNIX_LIKE 0 - #define ME_WIN_LIKE 0 - -#elif defined(__bsdi__) - #define ME_OS "bsdi" - #define BSDI 1 - #define ME_UNIX_LIKE 1 - #define ME_WIN_LIKE 0 - #define ME_BSD_LIKE 1 - -#elif defined(__NetBSD__) - #define ME_OS "netbsd" - #define NETBSD 1 - #define ME_UNIX_LIKE 1 - #define ME_WIN_LIKE 0 - #define ME_BSD_LIKE 1 - -#elif defined(__QNX__) - #define ME_OS "qnx" - #define QNX 0 - #define ME_UNIX_LIKE 0 - #define ME_WIN_LIKE 0 - -#elif defined(__hpux) - #define ME_OS "hpux" - #define HPUX 1 - #define ME_UNIX_LIKE 1 - #define ME_WIN_LIKE 0 - -#elif defined(_AIX) - #define ME_OS "aix" - #define AIX 1 - #define ME_UNIX_LIKE 1 - #define ME_WIN_LIKE 0 - -#elif defined(__CYGWIN__) - #define ME_OS "cygwin" - #define CYGWIN 1 - #define ME_UNIX_LIKE 1 - #define ME_WIN_LIKE 0 - -#elif defined(__VMS) - #define ME_OS "vms" - #define VMS 1 - #define ME_UNIX_LIKE 0 - #define ME_WIN_LIKE 0 - -#elif defined(VXWORKS) - /* VxWorks does not have a pre-defined symbol */ - #define ME_OS "vxworks" - #define ME_UNIX_LIKE 0 - #define ME_WIN_LIKE 0 - #define HAS_USHORT 1 - -#elif defined(ECOS) - /* ECOS may not have a pre-defined symbol */ - #define ME_OS "ecos" - #define ME_UNIX_LIKE 0 - #define ME_WIN_LIKE 0 - -#elif defined(TIDSP) - #define ME_OS "tidsp" - #define ME_UNIX_LIKE 0 - #define ME_WIN_LIKE 0 - #define HAS_INT32 1 - -#endif - -#if __WORDSIZE == 64 || __amd64 || __x86_64 || __x86_64__ || _WIN64 || __mips64 - #define ME_64 1 - #define ME_WORDSIZE 64 -#else - #define ME_64 0 - #define ME_WORDSIZE 32 -#endif - -/* - Unicode - */ -#ifndef ME_CHAR_LEN - #define ME_CHAR_LEN 1 -#endif -#if ME_CHAR_LEN == 4 - typedef int wchar; - #define UT(s) L ## s - #define UNICODE 1 -#elif ME_CHAR_LEN == 2 - typedef short wchar; - #define UT(s) L ## s - #define UNICODE 1 -#else - typedef char wchar; - #define UT(s) s -#endif - -#define ME_PLATFORM ME_OS "-" ME_CPU "-" ME_PROFILE - -/********************************* O/S Includes *******************************/ -/* - Out-of-order definitions and includes. Order really matters in this section. - */ -#if WINDOWS - #undef _CRT_SECURE_NO_DEPRECATE - #define _CRT_SECURE_NO_DEPRECATE 1 - #undef _CRT_SECURE_NO_WARNINGS - #define _CRT_SECURE_NO_WARNINGS 1 - #define _WINSOCK_DEPRECATED_NO_WARNINGS 1 - #ifndef _WIN32_WINNT - /* Target Windows 7 by default */ - #define _WIN32_WINNT 0x601 - #endif - /* - Work-around to allow the windows 7.* SDK to be used with VS 2012 - MSC_VER 1800 2013 - MSC_VER 1900 2015 - */ - #if _MSC_VER >= 1700 - #define SAL_SUPP_H - #define SPECSTRING_SUPP_H - #endif -#endif - -#if LINUX - /* - Use GNU extensions for: - RTLD_DEFAULT for dlsym() - */ - #define _GNU_SOURCE 1 - #if !ME_64 - #define _LARGEFILE64_SOURCE 1 - #ifdef __USE_FILE_OFFSET64 - #define _FILE_OFFSET_BITS 64 - #endif - #endif -#endif - -#if VXWORKS - #ifndef _VSB_CONFIG_FILE - #define _VSB_CONFIG_FILE "vsbConfig.h" - #endif - #include -#endif - -#if ME_WIN_LIKE - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #if ME_DEBUG - #include - #endif -#endif - -/* - Includes in alphabetic order - */ - #include -#if ME_WIN_LIKE - #include -#else - #include -#endif -#if ME_UNIX_LIKE - #include -#endif - #include - #include -#if ME_FLOAT - #include - #define __USE_ISOC99 1 - #include -#endif -#if ME_UNIX_LIKE - #include -#endif -#if ME_WIN_LIKE - #include -#endif -#if MACOSX || LINUX - #include -#endif - #include -#if ME_UNIX_LIKE || VXWORKS - #include - #include - #include - #include - #include - #include - #include -#endif -#if ME_UNIX_LIKE - #include - #include -#if !CYGWIN - #include -#endif -#endif -#if ME_BSD_LIKE - #include -#endif - #include - #include - #include -#if ME_UNIX_LIKE - #include -#endif - #include - #include - #include -#if ME_UNIX_LIKE - #include -#endif -#if !TIDSP - #include - #include -#endif -#if ME_UNIX_LIKE - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include -#endif - #include -#if !VXWORKS && !TIDSP - #include -#endif - -/* - Extra includes per O/S - */ -#if CYGWIN - #include "w32api/windows.h" - #include "sys/cygwin.h" -#endif -#if LINUX - #include - #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) - #include - #endif - #include - #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22) - #include - #endif - #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13) - #define HAS_INOTIFY 1 - #include - #else - #define HAS_INOTIFY 0 - #endif - #if !__UCLIBC__ - #include - #endif -#endif -#if MACOSX - #include - #include - #include - #include - #include - #include - #include - #include -#endif -#if VXWORKS - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #if _WRS_VXWORKS_MAJOR >= 6 - #include - #endif - #if _WRS_VXWORKS_MAJOR > 6 || (_WRS_VXWORKS_MAJOR == 6 && _WRS_VXWORKS_MINOR >= 8) - #include - #include - #endif -#endif - -#if TIDSP - #include - #include - #include - #include - #include -#endif - -/************************************** Types *********************************/ -/* - Standard types - */ -#ifndef HAS_BOOL - #ifndef __cplusplus - #if !MACOSX - #define HAS_BOOL 1 - /** - Boolean data type. - */ - #if _MSC_VER <= 1800 - typedef char bool; - #endif - #endif - #endif -#endif - -#ifndef HAS_UCHAR - #define HAS_UCHAR 1 - /** - Unsigned char data type. - */ - typedef unsigned char uchar; -#endif - -#ifndef HAS_SCHAR - #define HAS_SCHAR 1 - /** - Signed char data type. - */ - typedef signed char schar; -#endif - -#ifndef HAS_CCHAR - #define HAS_CCHAR 1 - /** - Constant char data type. - */ - typedef const char cchar; -#endif - -#ifndef HAS_CUCHAR - #define HAS_CUCHAR 1 - /** - Unsigned char data type. - */ - typedef const unsigned char cuchar; -#endif - -#ifndef HAS_USHORT - #define HAS_USHORT 1 - /** - Unsigned short data type. - */ - typedef unsigned short ushort; -#endif - -#ifndef HAS_CUSHORT - #define HAS_CUSHORT 1 - /** - Constant unsigned short data type. - */ - typedef const unsigned short cushort; -#endif - -#ifndef HAS_CVOID - #define HAS_CVOID 1 - /** - Constant void data type. - */ - typedef const void cvoid; -#endif - -#ifndef HAS_INT8 - #define HAS_INT8 1 - /** - Integer 8 bits data type. - */ - typedef char int8; -#endif - -#ifndef HAS_UINT8 - #define HAS_UINT8 1 - /** - Unsigned integer 8 bits data type. - */ - typedef unsigned char uint8; -#endif - -#ifndef HAS_INT16 - #define HAS_INT16 1 - /** - Integer 16 bits data type. - */ - typedef short int16; -#endif - -#ifndef HAS_UINT16 - #define HAS_UINT16 1 - /** - Unsigned integer 16 bits data type. - */ - typedef unsigned short uint16; -#endif - -#ifndef HAS_INT32 - #define HAS_INT32 1 - /** - Integer 32 bits data type. - */ - typedef int int32; -#endif - -#ifndef HAS_UINT32 - #define HAS_UINT32 1 - /** - Unsigned integer 32 bits data type. - */ - typedef unsigned int uint32; -#endif - -#ifndef HAS_UINT - #define HAS_UINT 1 - /** - Unsigned integer (machine dependent bit size) data type. - */ - typedef unsigned int uint; -#endif - -#ifndef HAS_ULONG - #define HAS_ULONG 1 - /** - Unsigned long (machine dependent bit size) data type. - */ - typedef unsigned long ulong; -#endif - -#ifndef HAS_CINT - #define HAS_CINT 1 - /** - Constant int data type. - */ - typedef const int cint; -#endif - -#ifndef HAS_SSIZE - #define HAS_SSIZE 1 - #if ME_UNIX_LIKE || VXWORKS || DOXYGEN - /** - Signed integer size field large enough to hold a pointer offset. - */ - typedef ssize_t ssize; - #elif TIDSP - typedef int ssize_t; - typedef ssize_t ssize; - #else - typedef SSIZE_T ssize; - #endif -#endif - -/* - Windows uses uint for write/read counts (Ugh!) - */ -#if ME_WIN_LIKE - typedef uint wsize; -#else - typedef ssize wsize; -#endif - -#ifndef HAS_INT64 - #if ME_UNIX_LIKE - __extension__ typedef long long int int64; - #elif VXWORKS || DOXYGEN - /** - Integer 64 bit data type. - */ - typedef long long int int64; - #elif ME_WIN_LIKE - typedef __int64 int64; - #else - typedef long long int int64; - #endif -#endif - -#ifndef HAS_UINT64 - #if ME_UNIX_LIKE - __extension__ typedef unsigned long long int uint64; - #elif VXWORKS || DOXYGEN - typedef unsigned long long int uint64; - #elif ME_WIN_LIKE - typedef unsigned __int64 uint64; - #else - typedef unsigned long long int uint64; - #endif -#endif - -/** - Signed file offset data type. Supports large files greater than 4GB in size on all systems. - */ -typedef int64 Offset; - -#if DOXYGEN - /** Size to hold the length of a socket address */ - typedef int Socklen; -#elif VXWORKS - typedef int Socklen; -#else - typedef socklen_t Socklen; -#endif - -#if DOXYGEN || ME_UNIX_LIKE || VXWORKS - /** Argument for sockets */ - typedef int Socket; - #ifndef SOCKET_ERROR - #define SOCKET_ERROR -1 - #endif - #define SOCKET_ERROR -1 - #ifndef INVALID_SOCKET - #define INVALID_SOCKET -1 - #endif -#elif ME_WIN_LIKE - typedef SOCKET Socket; -#elif TIDSP - typedef SOCKET Socket; - #define SOCKET_ERROR INVALID_SOCKET -#else - typedef int Socket; - #ifndef SOCKET_ERROR - #define SOCKET_ERROR -1 - #endif - #ifndef INVALID_SOCKET - #define INVALID_SOCKET -1 - #endif -#endif - -typedef int64 Time; - -/** - Elapsed time data type. Stores time in milliseconds from some arbitrary start epoch. - */ -typedef int64 Ticks; - -/** - Time/Ticks units per second (milliseconds) - */ -#define TPS 1000 - -/*********************************** Defines **********************************/ - -#ifndef BITSPERBYTE - #define BITSPERBYTE ((int) (8 * sizeof(char))) -#endif - -#ifndef BITS - #define BITS(type) ((int) (BITSPERBYTE * (int) sizeof(type))) -#endif - -#if ME_FLOAT - #ifndef MAXFLOAT - #if ME_WIN_LIKE - #define MAXFLOAT DBL_MAX - #else - #define MAXFLOAT FLT_MAX - #endif - #endif - #if VXWORKS - #undef isnan - #define isnan(n) ((n) != (n)) - #define isnanf(n) ((n) != (n)) - #define isinf(n) ((n) == (1.0 / 0.0) || (n) == (-1.0 / 0.0)) - #define isinff(n) ((n) == (1.0 / 0.0) || (n) == (-1.0 / 0.0)) - #endif - #if ME_WIN_LIKE - #define isNan(f) (_isnan(f)) - #elif VXWORKS || MACOSX || LINUX - #define isNan(f) (isnan(f)) - #else - #define isNan(f) (fpclassify(f) == FP_NAN) - #endif -#endif - -#if ME_WIN_LIKE - #define INT64(x) (x##i64) - #define UINT64(x) (x##Ui64) -#else - #define INT64(x) (x##LL) - #define UINT64(x) (x##ULL) -#endif - -#ifndef MAXINT -#if INT_MAX - #define MAXINT INT_MAX -#else - #define MAXINT 0x7fffffff -#endif -#endif - -#ifndef MAXUINT -#if UINT_MAX - #define MAXUINT UINT_MAX -#else - #define MAXUINT 0xffffffff -#endif -#endif - -#ifndef MAXINT64 - #define MAXINT64 INT64(0x7fffffffffffffff) -#endif -#ifndef MAXUINT64 - #define MAXUINT64 INT64(0xffffffffffffffff) -#endif - -#if SIZE_T_MAX - #define MAXSIZE SIZE_T_MAX -#elif ME_64 - #define MAXSIZE INT64(0xffffffffffffffff) -#else - #define MAXSIZE MAXINT -#endif - -#if SSIZE_T_MAX - #define MAXSSIZE SSIZE_T_MAX -#elif ME_64 - #define MAXSSIZE INT64(0x7fffffffffffffff) -#else - #define MAXSSIZE MAXINT -#endif - -#if OFF_T_MAX - #define MAXOFF OFF_T_MAX -#else - #define MAXOFF INT64(0x7fffffffffffffff) -#endif - -/* - Word size and conversions between integer and pointer. - */ -#if ME_64 - #define ITOP(i) ((void*) ((int64) i)) - #define PTOI(i) ((int) ((int64) i)) - #define LTOP(i) ((void*) ((int64) i)) - #define PTOL(i) ((int64) i) -#else - #define ITOP(i) ((void*) ((int) i)) - #define PTOI(i) ((int) i) - #define LTOP(i) ((void*) ((int) i)) - #define PTOL(i) ((int64) (int) i) -#endif - -#undef PUBLIC -#undef PUBLIC_DATA -#undef PRIVATE - -#if ME_WIN_LIKE - /* - Use PUBLIC on function declarations and definitions (*.c and *.h). - */ - #define PUBLIC __declspec(dllexport) - #define PUBLIC_DATA __declspec(dllexport) - #define PRIVATE static -#else - #define PUBLIC - #define PUBLIC_DATA extern - #define PRIVATE static -#endif - -#ifndef max - #define max(a,b) (((a) > (b)) ? (a) : (b)) -#endif -#ifndef min - #define min(a,b) (((a) < (b)) ? (a) : (b)) -#endif - -#ifndef PRINTF_ATTRIBUTE - #if ((__GNUC__ >= 3) && !DOXYGEN) || MACOSX - /** - Use gcc attribute to check printf fns. a1 is the 1-based index of the parameter containing the format, - and a2 the index of the first argument. Note that some gcc 2.x versions don't handle this properly - */ - #define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format (__printf__, a1, a2))) - #else - #define PRINTF_ATTRIBUTE(a1, a2) - #endif -#endif - -/* - Optimize expression evaluation code depending if the value is likely or not - */ -#undef likely -#undef unlikely -#if (__GNUC__ >= 3) - #define likely(x) __builtin_expect(!!(x), 1) - #define unlikely(x) __builtin_expect(!!(x), 0) -#else - #define likely(x) (x) - #define unlikely(x) (x) -#endif - -#if !__UCLIBC__ && !CYGWIN && __USE_XOPEN2K - #define ME_COMPILER_HAS_SPINLOCK 1 -#endif - -#if ME_COMPILER_HAS_DOUBLE_BRACES - #define NULL_INIT {{0}} -#else - #define NULL_INIT {0} -#endif - -#ifdef __USE_FILE_OFFSET64 - #define ME_COMPILER_HAS_OFF64 1 -#else - #define ME_COMPILER_HAS_OFF64 0 -#endif - -#if ME_UNIX_LIKE - #define ME_COMPILER_HAS_FCNTL 1 -#endif - -#ifndef R_OK - #define R_OK 4 - #define W_OK 2 -#if ME_WIN_LIKE - #define X_OK R_OK -#else - #define X_OK 1 -#endif - #define F_OK 0 -#endif - -#if MACOSX - #define LD_LIBRARY_PATH "DYLD_LIBRARY_PATH" -#else - #define LD_LIBRARY_PATH "LD_LIBRARY_PATH" -#endif - -#if VXWORKS -/* - Old VxWorks can't do array[] - */ - #define ARRAY_FLEX 0 -#else - #define ARRAY_FLEX -#endif - -/* - Deprecated API warnings - */ -#if ((__GNUC__ >= 3) || MACOSX) && !VXWORKS - #define ME_DEPRECATED(MSG) __attribute__ ((deprecated(MSG))) -#else - #define ME_DEPRECATED(MSG) -#endif - -/********************************** Tunables *********************************/ -/* - These can be defined in main.bit settings (pascal case) to override. E.g. - - settings: { - maxPath: 4096 - } - */ -#ifndef ME_MAX_FNAME - #define ME_MAX_FNAME 256 /**< Reasonable filename size */ -#endif -#ifndef ME_MAX_PATH - #define ME_MAX_PATH 1024 /**< Reasonable filename size */ -#endif -#if DEPRECATE || 1 -/* This is not a maximum, but a default size */ -#ifndef ME_MAX_BUFFER - #define ME_MAX_BUFFER 4096 /**< Reasonable size for buffers */ -#endif -#endif -#ifndef ME_BUFSIZE - #define ME_BUFSIZE 4096 /**< Reasonable size for buffers */ -#endif -#ifndef ME_MAX_ARGC - #define ME_MAX_ARGC 32 /**< Maximum number of command line args if using MAIN()*/ -#endif -#ifndef ME_DOUBLE_BUFFER - #define ME_DOUBLE_BUFFER (DBL_MANT_DIG - DBL_MIN_EXP + 4) -#endif -#ifndef ME_MAX_IP - #define ME_MAX_IP 1024 -#endif - - -#ifndef ME_STACK_SIZE -#if ME_COMPILER_HAS_MMU && !VXWORKS - /* - If the system supports virtual memory, then stack size should use system default. Only used pages will - actually consume memory - */ - #define ME_STACK_SIZE 0 /**< Default thread stack size (0 means use system default) */ -#else - /* - No MMU, so the stack size actually consumes memory. Set this as low as possible. - NOTE: php and ejs use stack heavily. - */ - #define ME_STACK_SIZE (128 * 1024) /**< Default thread stack size (0 means use system default) */ -#endif -#endif - -/*********************************** Fixups ***********************************/ - -#ifndef ME_INLINE - #if ME_WIN_LIKE - #define ME_INLINE __inline - #else - #define ME_INLINE inline - #endif -#endif - -#if ECOS - #define LIBKERN_INLINE /* to avoid kernel inline functions */ -#endif /* ECOS */ - -#if ME_UNIX_LIKE || VXWORKS || TIDSP - #define FILE_TEXT "" - #define FILE_BINARY "" -#endif - -#if !TIDSP - #define ME_COMPILER_HAS_MACRO_VARARGS 1 -#else - #define ME_COMPILER_HAS_MACRO_VARARGS 1 -#endif - -#if ME_UNIX_LIKE - #define closesocket(x) close(x) - #ifndef PTHREAD_MUTEX_RECURSIVE_NP - #define PTHREAD_MUTEX_RECURSIVE_NP PTHREAD_MUTEX_RECURSIVE - #endif - #ifndef PTHREAD_MUTEX_RECURSIVE - #define PTHREAD_MUTEX_RECURSIVE PTHREAD_MUTEX_RECURSIVE_NP - #endif -#endif - -#if !ME_WIN_LIKE && !CYGWIN - #ifndef O_BINARY - #define O_BINARY 0 - #endif - #ifndef O_TEXT - #define O_TEXT 0 - #endif -#endif - -#if !LINUX - #define __WALL 0 - #if !CYGWIN && !defined(MSG_NOSIGNAL) - #define MSG_NOSIGNAL 0 - #endif -#endif - -#if MACOSX - /* - Fix for MAC OS X - getenv - */ - #if !HAVE_DECL_ENVIRON - #ifdef __APPLE__ - #include - #define environ (*_NSGetEnviron()) - #else - extern char **environ; - #endif - #endif -#endif - -#if SOLARIS - #define INADDR_NONE ((in_addr_t) 0xffffffff) -#endif - -#if VXWORKS - #ifndef SHUT_RDWR - #define SHUT_RDWR 2 - #endif - #define HAVE_SOCKLEN_T - #if _DIAB_TOOL - #define inline __inline__ - #define MPR_INLINE __inline__ - #endif - #ifndef closesocket - #define closesocket(x) close(x) - #endif - #ifndef va_copy - #define va_copy(d, s) ((d) = (s)) - #endif - #ifndef strcasecmp - #define strcasecmp scaselesscmp - #endif - #ifndef strncasecmp - #define strncasecmp sncaselesscmp - #endif -#endif - -#if ME_WIN_LIKE - typedef int uid_t; - typedef void *handle; - typedef char *caddr_t; - typedef long pid_t; - typedef int gid_t; - typedef ushort mode_t; - typedef void *siginfo_t; - typedef int socklen_t; - - #define HAVE_SOCKLEN_T - #define MSG_NOSIGNAL 0 - #define FILE_BINARY "b" - #define FILE_TEXT "t" - - /* - Error codes - */ - #define EPERM 1 - #define ENOENT 2 - #define ESRCH 3 - #define EINTR 4 - #define EIO 5 - #define ENXIO 6 - #define E2BIG 7 - #define ENOEXEC 8 - #define EBADF 9 - #define ECHILD 10 - #define EAGAIN 11 - #define ENOMEM 12 - #define EACCES 13 - #define EFAULT 14 - #define EOSERR 15 - #define EBUSY 16 - #define EEXIST 17 - #define EXDEV 18 - #define ENODEV 19 - #define ENOTDIR 20 - #define EISDIR 21 - #define EINVAL 22 - #define ENFILE 23 - #define EMFILE 24 - #define ENOTTY 25 - #define EFBIG 27 - #define ENOSPC 28 - #define ESPIPE 29 - #define EROFS 30 - #define EMLINK 31 - #define EPIPE 32 - #define EDOM 33 - #define ERANGE 34 - - #ifndef EWOULDBLOCK - #define EWOULDBLOCK EAGAIN - #define EINPROGRESS 36 - #define EALREADY 37 - #define ENETDOWN 43 - #define ECONNRESET 44 - #define ECONNREFUSED 45 - #define EADDRNOTAVAIL 49 - #define EISCONN 56 - #define EADDRINUSE 46 - #define ENETUNREACH 51 - #define ECONNABORTED 53 - #endif - #ifndef ENOTCONN - #define ENOTCONN 126 - #endif - #ifndef EPROTO - #define EPROTO 134 - #endif - - #undef SHUT_RDWR - #define SHUT_RDWR 2 - - #define TIME_GENESIS UINT64(11644473600000000) - #ifndef va_copy - #define va_copy(d, s) ((d) = (s)) - #endif - - #if !WINCE - #define access _access - #define chdir _chdir - #define chmod _chmod - #define close _close - #define fileno _fileno - #define fstat _fstat - #define getcwd _getcwd - #define getpid _getpid - #define gettimezone _gettimezone - #define lseek _lseek - #define mkdir(a,b) _mkdir(a) - #define open _open - #define putenv _putenv - #define read _read - #define rmdir(a) _rmdir(a) - #define stat _stat - #define strdup _strdup - #define tempnam _tempnam - #define umask _umask - #define unlink _unlink - #define write _write - PUBLIC void sleep(int secs); - #endif - #define strcasecmp scaselesscmp - #define strncasecmp sncaselesscmp - #pragma comment( lib, "ws2_32.lib" ) -#endif /* WIN_LIKE */ - -#if WINCE - typedef void FILE; - typedef int off_t; - - #ifndef EOF - #define EOF -1 - #endif - #define O_RDONLY 0 - #define O_WRONLY 1 - #define O_RDWR 2 - #define O_NDELAY 0x4 - #define O_NONBLOCK 0x4 - #define O_APPEND 0x8 - #define O_CREAT 0x100 - #define O_TRUNC 0x200 - #define O_TEXT 0x400 - #define O_EXCL 0x800 - #define O_BINARY 0x1000 - /* - stat flags - */ - #define S_IFMT 0170000 - #define S_IFDIR 0040000 - #define S_IFCHR 0020000 /* character special */ - #define S_IFIFO 0010000 - #define S_IFREG 0100000 - #define S_IREAD 0000400 - #define S_IWRITE 0000200 - #define S_IEXEC 0000100 - - #ifndef S_ISDIR - #define S_ISDIR(X) (((X) & S_IFMT) == S_IFDIR) - #endif - #ifndef S_ISREG - #define S_ISREG(X) (((X) & S_IFMT) == S_IFREG) - #endif - - #define STARTF_USESHOWWINDOW 0 - #define STARTF_USESTDHANDLES 0 - - #define BUFSIZ ME_MAX_BUFFER - #define PATHSIZE ME_MAX_PATH - #define gethostbyname2(a,b) gethostbyname(a) - #pragma comment( lib, "ws2.lib" ) -#endif /* WINCE */ - -#if TIDSP - #define EINTR 4 - #define EAGAIN 11 - #define INADDR_NONE 0xFFFFFFFF - #define PATHSIZE ME_MAX_PATH - #define NBBY 8 - #define hostent _hostent - #define NFDBITS ((int) (sizeof(fd_mask) * NBBY)) - typedef long fd_mask; - typedef int Socklen; - struct sockaddr_storage { char pad[1024]; }; -#endif /* TIDSP */ - -/*********************************** Externs **********************************/ - -#ifdef __cplusplus -extern "C" { -#endif - -#if LINUX - extern int pthread_mutexattr_gettype (__const pthread_mutexattr_t *__restrict __attr, int *__restrict __kind) __THROW; - extern int pthread_mutexattr_settype (pthread_mutexattr_t *__attr, int __kind) __THROW; - extern char **environ; -#endif - -#if VXWORKS - #if _WRS_VXWORKS_MAJOR < 6 || (_WRS_VXWORKS_MAJOR == 6 && _WRS_VXWORKS_MINOR < 9) - PUBLIC int gettimeofday(struct timeval *tv, struct timezone *tz); - #endif - PUBLIC char *strdup(const char *); - PUBLIC int sysClkRateGet(); - - #if _WRS_VXWORKS_MAJOR < 6 - #define NI_MAXHOST 128 - extern STATUS access(cchar *path, int mode); - typedef int socklen_t; - struct sockaddr_storage { - char pad[1024]; - }; - #else - /* - This may or may not be necessary - let us know dev@embedthis.com if your system needs this (and why). - */ - #if _DIAB_TOOL - #if ME_CPU_ARCH == ME_CPU_PPC - #define __va_copy(dest, src) memcpy((dest), (src), sizeof(va_list)) - #endif - #endif - #define HAVE_SOCKLEN_T - #endif -#endif /* VXWORKS */ - -#if ME_WIN_LIKE - struct timezone { - int tz_minuteswest; /* minutes W of Greenwich */ - int tz_dsttime; /* type of dst correction */ - }; - PUBLIC int getuid(void); - PUBLIC int geteuid(void); - PUBLIC int gettimeofday(struct timeval *tv, struct timezone *tz); - PUBLIC long lrand48(void); - PUBLIC long nap(long); - PUBLIC void srand48(long); - PUBLIC long ulimit(int, ...); -#endif - -#if WINCE - struct stat { - int st_dev; - int st_ino; - ushort st_mode; - short st_nlink; - short st_uid; - short st_gid; - int st_rdev; - long st_size; - time_t st_atime; - time_t st_mtime; - time_t st_ctime; - }; - extern int access(cchar *filename, int flags); - extern int chdir(cchar dirname); - extern int chmod(cchar *path, int mode); - extern int close(int handle); - extern void exit(int status); - extern long _get_osfhandle(int handle); - extern char *getcwd(char* buffer, int maxlen); - extern char *getenv(cchar *charstuff); - extern pid_t getpid(); - extern long lseek(int handle, long offset, int origin); - extern int mkdir(cchar *dir, int mode); - extern time_t mktime(struct tm *pt); - extern int _open_osfhandle(int *handle, int flags); - extern uint open(cchar *file, int mode,...); - extern int read(int handle, void *buffer, uint count); - extern int rename(cchar *from, cchar *to); - extern int rmdir(cchar dir); - extern uint sleep(uint secs); - extern int stat(cchar *path, struct stat *stat); - extern char *strdup(char *s); - extern int write(int handle, cvoid *buffer, uint count); - extern int umask(int mode); - extern int unlink(cchar *path); - extern int errno; - - #undef CreateFile - #define CreateFile CreateFileA - WINBASEAPI HANDLE WINAPI CreateFileA(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, - LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, - HANDLE hTemplateFile); - - #undef CreateProcess - #define CreateProcess CreateProcessA - - #undef FindFirstFile - #define FindFirstFile FindFirstFileA - WINBASEAPI HANDLE WINAPI FindFirstFileA(LPCSTR lpFileName, LPWIN32_FIND_DATAA lpFindFileData); - - #undef FindNextFile - #define FindNextFile FindNextFileA - WINBASEAPI BOOL WINAPI FindNextFileA(HANDLE hFindFile, LPWIN32_FIND_DATAA lpFindFileData); - - #undef GetModuleFileName - #define GetModuleFileName GetModuleFileNameA - WINBASEAPI DWORD WINAPI GetModuleFileNameA(HMODULE hModule, LPSTR lpFilename, DWORD nSize); - - #undef GetModuleHandle - #define GetModuleHandle GetModuleHandleA - WINBASEAPI HMODULE WINAPI GetModuleHandleA(LPCSTR lpModuleName); - - #undef GetProcAddress - #define GetProcAddress GetProcAddressA - - #undef GetFileAttributes - #define GetFileAttributes GetFileAttributesA - extern DWORD GetFileAttributesA(cchar *path); - - extern void GetSystemTimeAsFileTime(FILETIME *ft); - - #undef LoadLibrary - #define LoadLibrary LoadLibraryA - HINSTANCE WINAPI LoadLibraryA(LPCSTR lpLibFileName); - - #define WSAGetLastError GetLastError - - #define _get_timezone getTimezone - extern int getTimezone(int *secs); - - extern struct tm *localtime_r(const time_t *when, struct tm *tp); - extern struct tm *gmtime_r(const time_t *t, struct tm *tp); -#endif /* WINCE */ - -#ifdef __cplusplus -} -#endif - -#endif /* _h_OSDEP */ - -/* - Copyright (c) Michael O'Brien. All Rights Reserved. - This is proprietary software and requires a commercial license from the author. - */ diff --git a/app/bmc/lib/libgo.so b/app/bmc/lib/libgo.so deleted file mode 100644 index 1eb3c17ed..000000000 Binary files a/app/bmc/lib/libgo.so and /dev/null differ diff --git a/app/bmc/param.c b/app/bmc/param.c deleted file mode 100644 index 81200df4b..000000000 --- a/app/bmc/param.c +++ /dev/null @@ -1,208 +0,0 @@ -/** - * @file env.c - * @author wenyi (wenyi0421@163.com) - * @brief - * @version 0.1 - * @date 2022-09-08 - * - * @copyright Copyright (c) 2022 - * - */ -#include -#include -#include -#include -#include "cjson/cJSON.h" -#include "param.h" - -/********************/ -#define CONFIG_PATH "/mnt/config" - -#define USB_FILE_PATH "usb.json" -#define NODEINFOEN_FILE_PATH "nodeinfoen.json" -/**********************/ - -int get_env_nodeInfo(env_nodeInfo_t *info); - -static env_ctx_t g_env_ctx; -env_ctx_t* env_get_ctx(void) -{ - return &g_env_ctx; -} - -void init_env(void) -{ - memset(&g_env_ctx,0,sizeof(g_env_ctx)); - get_env_usb(&g_env_ctx.usb); - get_env_nodeInfo(&g_env_ctx.nodeen); -} - -#define json_get_int(obj, key, val) \ - do \ - { \ - if (NULL != obj) \ - { \ - cJSON *tmp = cJSON_GetObjectItem(obj, key); \ - if (NULL != tmp) \ - { \ - val = tmp->valueint; \ - } \ - else \ - { \ - printf("json_get_int key:%s is NULL\n", key ? key : "error"); \ - } \ - } \ - else \ - { \ - printf("json_get_int obj is NULL,key:%s\n", key ? key : "error"); \ - } \ - } while (0) - -#define json_get_str(obj, key, val, len) \ - do \ - { \ - if (NULL != obj) \ - { \ - cJSON *tmp = cJSON_GetObjectItem(obj, key); \ - if (NULL != tmp && NULL != tmp->valuestring) \ - { \ - strncpy(val, tmp->valuestring, len); \ - } \ - else \ - { \ - printf("json_get_str key:%s is NULL\n", key ? key : "error"); \ - } \ - } \ - else \ - { \ - printf("json_get_str obj is NULL,key:%s\n", key ? key : "error"); \ - } \ - } while (0) - -static int writefile(char *name, char *data, int len) -{ - char path[128] = {0}; - int ret = 0; - if (NULL == name || NULL == data || len < 0) - { - printf("error todo\n"); - return -1; - } - snprintf(path, sizeof(path), "%s/%s", CONFIG_PATH, name); - FILE *fp = NULL; - fp = fopen(path, "w+"); - if (NULL == fp) - { - printf("fopen file error \n"); - return -2; - } - ret = fwrite(data, sizeof(char), len, fp); - fflush(fp); - fclose(fp); - if (ret != len) - { - printf("fwrite ret = %d != len = %d\n", ret, len); - } - return 0; -} - -static int readfile(char *name, char *data, int *len) -{ - char path[128] = {0}; - int ret = 0; - if (NULL == name || NULL == data || len < 0) - { - printf("error todo\n"); - return -1; - } - snprintf(path, sizeof(path), "%s/%s", CONFIG_PATH, name); - FILE *fp = NULL; - fp = fopen(path, "r"); - if (NULL == fp) - { - printf("fopen file error \n"); - return -2; - } - ret = fread(data, sizeof(char), *len, fp); // todo if len > 4096 fixme - fflush(fp); - fclose(fp); - *len = ret; - return 0; -} - -int set_env_usb(env_usb_t *usb) -{ - cJSON *pRoot = cJSON_CreateObject(); - - /*--json body--*/ - - cJSON_AddNumberToObject(pRoot, "mode", usb->mode); - cJSON_AddNumberToObject(pRoot, "node", usb->node); - /*--json end--*/ - char *szJSON = cJSON_Print(pRoot); - printf("%s\n", szJSON); - writefile(USB_FILE_PATH, szJSON, strlen(szJSON)); - cJSON_Delete(pRoot); - free(szJSON); - szJSON = NULL; - return 0; -} - -int get_env_usb(env_usb_t *usb) -{ - char buff[4096] = {0}; - int len = 4096; - readfile(USB_FILE_PATH, buff, &len); - cJSON *pRoot = cJSON_Parse(buff); - cJSON *pitem = NULL; - if (NULL == pRoot) - { - printf("get env %s no json\n", USB_FILE_PATH); - // todo load back env - } - else - { - json_get_int(pRoot, "mode", usb->mode); - json_get_int(pRoot, "node", usb->node); - } - return 0; -} - - - - -int set_env_nodeInfo(env_nodeInfo_t *info) -{ - cJSON *pRoot = cJSON_CreateObject(); - - /*--json body--*/ - - cJSON_AddNumberToObject(pRoot, "enable", info->enable); - /*--json end--*/ - char *szJSON = cJSON_Print(pRoot); - printf("%s\n", szJSON); - writefile(NODEINFOEN_FILE_PATH, szJSON, strlen(szJSON)); - cJSON_Delete(pRoot); - free(szJSON); - szJSON = NULL; - return 0; -} - -int get_env_nodeInfo(env_nodeInfo_t *info) -{ - char buff[4096] = {0}; - int len = 4096; - readfile(NODEINFOEN_FILE_PATH, buff, &len); - cJSON *pRoot = cJSON_Parse(buff); - cJSON *pitem = NULL; - if (NULL == pRoot) - { - printf("get env %s no json\n", NODEINFOEN_FILE_PATH); - // todo load back env - } - else - { - json_get_int(pRoot, "enable", info->enable); - } - return 0; -} diff --git a/app/bmc/param.h b/app/bmc/param.h deleted file mode 100644 index 55845737c..000000000 --- a/app/bmc/param.h +++ /dev/null @@ -1,44 +0,0 @@ -/** - * @file param.h - * @author wenyi (wenyi0421@163.com) - * @brief - * @version 0.1 - * @date 2022-09-08 - * - * @copyright Copyright (c) 2022 - * - */ - -#ifndef __PARAM_H__ -#define __PARAM_H__ - -typedef struct _env_usb_t -{ - /* data */ - int mode; - int node; -}env_usb_t; - -typedef struct _env_nodeInfo_t -{ - int enable; -}env_nodeInfo_t; - - -/** - * @brief all env - * - */ -typedef struct _env_ctx_t -{ - env_usb_t usb; - env_nodeInfo_t nodeen; -}env_ctx_t; - -env_ctx_t* env_get_ctx(void); -void init_env(void); -int set_env_usb(env_usb_t* usb); -int get_env_usb(env_usb_t* usb); -int set_env_nodeInfo(env_nodeInfo_t *info); - -#endif // !__PARAM_H__ diff --git a/app/bmc/t113_gpio.h b/app/bmc/t113_gpio.h deleted file mode 100755 index 02053aeee..000000000 --- a/app/bmc/t113_gpio.h +++ /dev/null @@ -1,23 +0,0 @@ -/** - * @file t113_gpio.h - * @author wenyi (wenyi0421@163.com) - * @brief T113 GPIO map - * @version 0.1 - * @date 2022-08-14 - * - * @copyright Copyright (c) 2022 - * - */ - - -#ifndef __T113_GPIO_H__ -#define __T113_GPIO_H__ - -#define GPIO_PIN_PB(x) ((x)+32) -#define GPIO_PIN_PC(x) ((x)+64) -#define GPIO_PIN_PD(x) ((x)+96) -#define GPIO_PIN_PE(x) ((x)+128) -#define GPIO_PIN_PF(x) ((x)+160) -#define GPIO_PIN_PG(x) ((x)+192) - -#endif \ No newline at end of file diff --git a/app/bmc/version.h b/app/bmc/version.h deleted file mode 100644 index 43b07875d..000000000 --- a/app/bmc/version.h +++ /dev/null @@ -1,3 +0,0 @@ -/* This file is auto generated. do not modify */ -#define BMCVERSION "1.1.0" -#define BUILDTIME "2023-07-28" diff --git a/app/bmc/webserver.c b/app/bmc/webserver.c deleted file mode 100755 index 61da46327..000000000 --- a/app/bmc/webserver.c +++ /dev/null @@ -1,935 +0,0 @@ -/** - * @file webserver.c - * @author wenyi (wenyi0421@163.com) - * @brief - * @version 0.1 - * @date 2022-08-27 - * - * @copyright Copyright (c) 2022 - * - */ - - -#include //statfs -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -#include "inc/goahead.h" -#include "cjson/cJSON.h" -#include "param.h" -#include "bmc.h" -#include "version.h" - -#include - -#include - -#define SD_PATH "/mnt/sdcard" - - -static int Go_asp_test_disp( int eid, Webs *wp, int argc, char **argv) -{ - int i = 0; - printf("-----------argc %d\n", argc); - - for (i = 0; i < argc; i++) - printf("argv[%d] [%s]\n", i, argv[i]); - - - - // asp_test_Db(); - - websWrite(wp, "%s", argv[0]); - //websFlush(wp, 0); - //websDone(wp); - return 3; -} - -static void Go_asp_test_Action(Webs *wp) -{ - char *name, *address; - - name = websGetVar(wp, "name", NULL); - address = websGetVar(wp, "address", NULL); - websSetStatus(wp, 200); - websWriteHeaders(wp, -1, 0); - websWriteEndHeaders(wp); - websWrite(wp, "

name: %s, address: %s

\n", name, address); - websFlush(wp, 0); - websDone(wp); -} - - - -static int app_webS_PrintJsonErr(Webs *wp, int code,char *errstr) -{ - - /*--json start--*/ - cJSON* pRoot = cJSON_CreateObject(); - cJSON* pArray = cJSON_CreateArray(); - cJSON_AddItemToObject(pRoot, "response", pArray); - cJSON* pItem = NULL; - - - /*--json body--*/ - pItem = cJSON_CreateObject(); - cJSON_AddNumberToObject(pItem, "code", code); - cJSON_AddStringToObject(pItem, "result", errstr); - cJSON_AddItemToArray(pArray, pItem); - - - /*--json end--*/ - char* szJSON = cJSON_Print(pRoot); - // printf("%s\n", szJSON); - - websWrite(wp, szJSON); - websFlush(wp, 0); - websDone(wp); - - cJSON_Delete(pRoot); - - return 0; - -} - -bool check_sdcard_mount_status(void) -{ - char tmp[4096]={0}; - FILE *pp=NULL; - if (access("/dev/mmcblk0p1", 0) && access("/dev/mmcblk0", 0)) { - return false; - } - pp = popen("mount | grep mmcblk", "r"); - if (!pp) { - return false; - } - fgets(tmp, 4096, pp); - pclose(pp); - if (!strstr(tmp, SD_PATH)) { - return false; - } - return true; -} - - -static int get_sdcard_info(Webs* wp) -{ - unsigned long long total; - unsigned long long free; - unsigned long long use; - - struct statfs hfs = {0}; - unsigned long long block_size = 0; - - if(check_sdcard_mount_status()) - { - if(statfs(SD_PATH,&hfs)) - { - printf("get sd error\n"); - return -1; - } - } - - block_size = hfs.f_bsize; - total = (hfs.f_blocks * block_size)>>20; - free = (hfs.f_bavail * block_size)>>20; - use = total - free; - - /*--json start--*/ - cJSON* pRoot = cJSON_CreateObject(); - cJSON* pArray = cJSON_CreateArray(); - cJSON_AddItemToObject(pRoot, "response", pArray); - cJSON* pItem = NULL; - - - /*--json body--*/ - pItem = cJSON_CreateObject(); - cJSON_AddNumberToObject(pItem, "total", total); - cJSON_AddNumberToObject(pItem, "free", free); - cJSON_AddNumberToObject(pItem, "use", use); - cJSON_AddItemToArray(pArray, pItem); - - - /*--json end--*/ - char* szJSON = cJSON_Print(pRoot); - // printf("%s\n", szJSON); - - websWrite(wp, szJSON); - websFlush(wp, 0); - websDone(wp); - - cJSON_Delete(pRoot); - - return 0; -} - - -static int get_usbmode(Webs* wp) -{ - /*--json start--*/ - cJSON* pRoot = cJSON_CreateObject(); - cJSON* pArray = cJSON_CreateArray(); - cJSON_AddItemToObject(pRoot, "response", pArray); - cJSON* pItem = NULL; - - - env_usb_t* usb = &(env_get_ctx()->usb); - - /*--json body--*/ - pItem = cJSON_CreateObject(); - cJSON_AddNumberToObject(pItem, "mode", usb->mode); - cJSON_AddNumberToObject(pItem, "node", usb->node); - cJSON_AddItemToArray(pArray, pItem); - - - /*--json end--*/ - char* szJSON = cJSON_Print(pRoot); - // printf("%s\n", szJSON); - - websWrite(wp, szJSON); - websFlush(wp, 0); - websDone(wp); - - cJSON_Delete(pRoot); - return 0; -} - - -static int reset_node(Webs* wp) -{ - char* node = NULL; - node = websGetVar(wp, "node", NULL); - - if(NULL == node ) - { - app_webS_PrintJsonErr(wp,400,"node argument is not set"); - return -1; - } - - tpi_reset_node(atoi(node)); - - return 0; -} - -static int set_usbmode(Webs* wp) -{ - char* mode = NULL; - char* node = NULL; - mode = websGetVar(wp, "mode", NULL); - node = websGetVar(wp, "node", NULL); - char* boot_pin = websGetVar(wp, "boot_pin", NULL); - - if(NULL == node || NULL == mode) - { - app_webS_PrintJsonErr(wp,400,"mode or node is null"); - return -1; - } - env_usb_t* usb = &(env_get_ctx()->usb); - usb->mode = atoi(mode); - usb->node = atoi(node); - set_env_usb(usb); - - if (NULL == boot_pin) { - tpi_usb_mode_v2(usb->mode,usb->node,1); - } else { - int boot = atoi(boot_pin); - tpi_usb_mode_v2(usb->mode,usb->node, boot); - } - - - return 0; -} - -static int get_nodepower(Webs* wp) -{ - /*--json start--*/ - cJSON* pRoot = cJSON_CreateObject(); - cJSON* pArray = cJSON_CreateArray(); - cJSON_AddItemToObject(pRoot, "response", pArray); - cJSON* pItem = NULL; - - - /*--json body--*/ - pItem = cJSON_CreateObject(); - cJSON_AddNumberToObject(pItem, "node1", tpi_get_node_power(0)); - cJSON_AddNumberToObject(pItem, "node2", tpi_get_node_power(1)); - cJSON_AddNumberToObject(pItem, "node3", tpi_get_node_power(2)); - cJSON_AddNumberToObject(pItem, "node4", tpi_get_node_power(3)); - cJSON_AddItemToArray(pArray, pItem); - - - /*--json end--*/ - char* szJSON = cJSON_Print(pRoot); - printf("json ret:%s\n", szJSON); - - websWrite(wp, szJSON); - websFlush(wp, 0); - websDone(wp); - - cJSON_Delete(pRoot); - return 0; -} - -static int get_nodeInfoType(Webs* wp) -{ - /*--json start--*/ - cJSON* pRoot = cJSON_CreateObject(); - cJSON* pArray = cJSON_CreateArray(); - cJSON_AddItemToObject(pRoot, "response", pArray); - cJSON* pItem = NULL; - - /*--json body--*/ - pItem = cJSON_CreateObject(); - cJSON_AddStringToObject(pItem, "node1", get_nodeType(0)); - cJSON_AddStringToObject(pItem, "node2", get_nodeType(1)); - cJSON_AddStringToObject(pItem, "node3", get_nodeType(2)); - cJSON_AddStringToObject(pItem, "node4", get_nodeType(3)); - cJSON_AddItemToArray(pArray, pItem); - - - /*--json end--*/ - char* szJSON = cJSON_Print(pRoot); - printf("json ret:%s\n", szJSON); - - websWrite(wp, szJSON); - websFlush(wp, 0); - websDone(wp); - - cJSON_Delete(pRoot); - return 0; -} - - - -int comm_getMacAddr(char* ethname, char *macaddr, size_t len) -{ - int fd; - char buffer[20]; - struct ifreq ifr; - - if ((fd = socket (AF_INET, SOCK_DGRAM, 0)) >= 0) - { - strncpy(ifr.ifr_name, ethname, IFNAMSIZ); - ifr.ifr_name[IFNAMSIZ - 1] = '\0'; - if (ioctl(fd, SIOCGIFHWADDR, &ifr) == 0) - { - snprintf(buffer, 20, "%02x:%02x:%02x:%02x:%02x:%02x", - (unsigned char)ifr.ifr_hwaddr.sa_data[0], - (unsigned char)ifr.ifr_hwaddr.sa_data[1], - (unsigned char)ifr.ifr_hwaddr.sa_data[2], - (unsigned char)ifr.ifr_hwaddr.sa_data[3], - (unsigned char)ifr.ifr_hwaddr.sa_data[4], - (unsigned char)ifr.ifr_hwaddr.sa_data[5]); - } - else - { - close(fd); - return(-1); - } - } - else - { - return(-1); - } - - if (strlen(buffer) > len - 1) - { - close(fd); - return(-1); - } - strncpy(macaddr, buffer, len); - - close(fd); - return(0); -} - - - -int comm_getIpAddr(char* ethname, char *ipaddr, size_t len) -{ - int fd; - char buffer[20]; - struct ifreq ifr; - struct sockaddr_in *addr; - - if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) >= 0) - { - strncpy(ifr.ifr_name, ethname, IFNAMSIZ); - ifr.ifr_name[IFNAMSIZ - 1] = '\0'; - if (ioctl(fd, SIOCGIFADDR, &ifr) == 0) - { - addr = (struct sockaddr_in *) & (ifr.ifr_addr); - inet_ntop(AF_INET, &addr->sin_addr, buffer, 20); - } - else - { - close(fd); - return(-1); - } - } - else - { - perror("st_comm_net_card_getIpAddr error :"); - return(-1); - } - - if (strlen(buffer) > len - 1) - { - close(fd); - return(-1); - } - strncpy(ipaddr, buffer, len); - close(fd); - return(0); -} - - - - -static int get_otherInfo(Webs* wp) -{ - /*--json start--*/ - cJSON* pRoot = cJSON_CreateObject(); - cJSON* pArray = cJSON_CreateArray(); - cJSON_AddItemToObject(pRoot, "response", pArray); - cJSON* pItem = NULL; - - /*--json body--*/ - char mac[24]; - char ip[24]; - comm_getMacAddr("eth0",mac,sizeof(mac)); - comm_getIpAddr("eth0",ip,sizeof(ip)); - - pItem = cJSON_CreateObject(); - cJSON_AddStringToObject(pItem, "version", BMCVERSION); - cJSON_AddStringToObject(pItem, "buildtime", BUILDTIME); - cJSON_AddStringToObject(pItem, "ip", ip); - cJSON_AddStringToObject(pItem, "mac", mac); - cJSON_AddItemToArray(pArray, pItem); - - /*--json end--*/ - char* szJSON = cJSON_Print(pRoot); - // printf("json ret:%s\n", szJSON); - - websWrite(wp, szJSON); - websFlush(wp, 0); - websDone(wp); - - cJSON_Delete(pRoot); - return 0; -} - -static int get_uartString(Webs* wp) -{ - char buff[BUFF_MAX_SIZE]={0}; - char *node =NULL; - int num = 0; - node = websGetVar(wp, "node", NULL); - if(NULL!=node) - { - num = atoi(node); - } - - /*--json start--*/ - cJSON* pRoot = cJSON_CreateObject(); - cJSON* pArray = cJSON_CreateArray(); - cJSON_AddItemToObject(pRoot, "response", pArray); - cJSON* pItem = NULL; - - /*--json body--*/ - get_buff(num,buff,BUFF_MAX_SIZE); - pItem = cJSON_CreateObject(); - cJSON_AddStringToObject(pItem, "uart", buff); - cJSON_AddItemToArray(pArray, pItem); - - - /*--json end--*/ - char* szJSON = cJSON_Print(pRoot); - // printf("json ret:%s\n", szJSON); - - websWrite(wp, szJSON); - websFlush(wp, 0); - websDone(wp); - - cJSON_Delete(pRoot); - return 0; -} - - - -static int set_uartCmd(Webs* wp) -{ - int ret = 0; - char* cmd = NULL; - cmd = websGetVar(wp, "cmd", NULL); - char *node =NULL; - int num = 0; - node = websGetVar(wp, "node", NULL); - if(NULL!=node) - { - num = atoi(node); - } - if(num<0||num>3) - { - return -1; - } - if(cmd!=NULL) - { - ret = uart_write(num,cmd,strlen(cmd)); - printf("uart write cmd = %s ret = %d\n",cmd,ret); - } - - return 0; -} - - - -static int set_nodepower(Webs* wp) -{ - int i; - char* var[] = {"node1","node2","node3","node4"}; - char* node1 = NULL; - char* node = NULL; - node1 = websGetVar(wp, "node1", NULL); - node = websGetVar(wp, "node", NULL); - // env_usb_t usb; - for(i=0; i<4; ++i) - { - node = NULL; - node = websGetVar(wp, var[i], NULL); - if(NULL!=node && atoi(node)!=tpi_get_node_power(i)) - { - tpi_node_power(i,atoi(node)); - printf("set node %d,var = %d\n",i,atoi(node)); - } - } - return 0; -} - -static int set_network(Webs* wp) -{ - char* cmd = NULL; - cmd = websGetVar(wp, "cmd", NULL); - if(cmd!=NULL) - { - if(0==strcmp(cmd,"reset")) - { - tpi_rtl_reset(); - } - } - - return 0; -} - -static int set_nodeinfo(Webs* wp) -{ - char* en = NULL; - en = websGetVar(wp, "enable", NULL); - if(en!=NULL) - { - env_nodeInfo_t *info = &env_get_ctx()->nodeen; - info->enable = atoi(en); - set_env_nodeInfo(info); - } - return 0; -} - - -char* updateFilePath = "/tmp/update.bin"; -static int get_ubi_num(void) -{ - int ret = -1; - char cmd[128]={0}; - char line[1024]={0}; - snprintf(cmd,sizeof(cmd),"mount"); - FILE* pp = popen(cmd,"r"); - if(pp) - { - while (fgets(line, 1024, pp)) { - if (strstr(line, "ubi0_5") || strstr(line, "ubi0_6")) { - if(strstr(line, "ubi0_5")) - ret = 6; - if(strstr(line, "ubi0_6")) - ret = 5; - break; - } - } - pclose(pp); - } - return ret; -} - -static const char* swupdate_file = "/mnt/sdcard/update.bin"; -static int swupdate_cmd(void) -{ - char cmd[256] = {0}; - char line[1024] = {0}; - bool update_ret = false; - bool env_status = false; - int ver = get_ubi_num(); - if(-1==ver) - { - printf("error\n"); - return -1; - } - snprintf(cmd,sizeof(cmd),"swupdate -i %s -e stable,upgrade_ubi%d",swupdate_file,ver); - FILE* pp = popen(cmd,"r"); - if(pp) - { - while (fgets(line, 1024, pp)) { - if (strstr(line, "SWUPDATE successful") ) { - update_ret = true; - break; - } - } - pclose(pp); - pp = NULL; - } - // sleep(5); - if(update_ret) - { - int count = 0; - char ubi[16]; - // char printenv[128]; - // snprintf(printenv,sizeof(printenv),"fw_printenv "); - - // snprintf(ubi,sizeof(ubi),"ubi0_%d",ver); - //update bootenv - // snprintf(cmd,sizeof(cmd),"fw_setenv nand_root %s",ubi); - // snprintf(cmd,sizeof(cmd),"/etc/env.sh"); - // printf(" %s\n",cmd); - // system(cmd); - // while(env_status == false) - // { - // system(cmd); - // usleep(50*1000); - // // snprintf(cmd,sizeof(cmd),"fw_printenv ",); - // pp = popen(printenv,"r"); - // if(pp) - // { - // while (fgets(line, 1024, pp)) { - // if (strstr(line, ubi) ) { - // env_status = true; - // break; - // } - // } - // pclose(pp); - // } - // sleep(1); - // if(count++ > 10) - // { - // printf("--------------UPDATE faild--------------------\n"); - // printf("=================system will reboot ====================\n"); - // sleep(3); - // system("reboot"); - // } - // } - sleep(1); - printf("--------------UPDATE successful--------------------\n"); - } - else - { - printf("--------------UPDATE faild--------------------\n"); - } - printf("=================system will reboot ====================\n"); - sprintf(cmd,"rm %s",swupdate_file); - system(cmd); - sleep(3); - system("reboot"); - // reboot(); -} - -static bool isMountSDcard(char* mountPoint) -{ - if(NULL == mountPoint) - return false; - int fd = -1; - char buff[1024]; - if((fd = open("/proc/mounts",O_RDONLY)) < 0) - { - printf("open /proc/mounts error\n"); - return false; - } - while(read(fd,buff,1024)>0) - { - if(strstr(buff,mountPoint)) - { - close(fd); - return true; - } - } - close(fd); - return false; -} - - - -static void uploadFirmware(Webs *wp) -{ - WebsKey *s; - WebsUpload *up; - - char cmd[128]; - char sessionIdBuf[128] = {0}; - int sessionIdBufLen = sizeof(sessionIdBuf); - - - websSetStatus(wp, 200); - websWriteHeaders(wp, -1, 0); - websWriteHeader(wp, "Content-Type", "text/plain"); - - websWriteEndHeaders(wp); - - if(!isMountSDcard("/mnt/sdcard")) - { - websWrite(wp,"{\"response\":[{\"result\":\"err:no sdcard\"}]}"); - websDone(wp); - return ; - } - - if (scaselessmatch(wp->method, "POST")) { - for (s = hashFirst(wp->files); s; s = hashNext(wp->files, s)) { - up = (WebsUpload*)(s->content.value.symbol); - if (rename(up->filename, updateFilePath) < 0) { - error("Cannot rename uploaded file: %s to %s, errno %d", up->filename, updateFilePath, errno); - } - } - websWrite(wp, "\r\nVARS:\r\n"); - for (s = hashFirst(wp->vars); s; s = hashNext(wp->vars, s)) { - websWrite(wp, "%s=%s\r\n", s->name.value.string, s->content.value.string); - } - } - sprintf(cmd,"mv %s %s;sync",updateFilePath,swupdate_file); - system(cmd); - websWrite(wp,"{\"response\":[{\"result\":\"ok\"}]}"); - websDone(wp); - printf("upload Filename=%s\n",up->clientFilename); - swupdate_cmd(); - -} - -static void run_node_to_msd(Webs *wp) -{ - WebsKey *s; - WebsUpload *up; - - char *node = NULL; - uint8_t node_id; - flashing_result res; - - node = websGetVar(wp, "node", NULL); - if (!node) - { - app_webS_PrintJsonErr(wp, 400, "No node specified"); - return; - } - tpi_node_to_msd(atoi(node)); - websWrite(wp,"{\"response\":[{\"result\":\"ok\"}]}"); -} - -static void clear_usb_boot(Webs *wp) -{ - tpi_clear_usbboot(); - websWrite(wp,"{\"response\":[{\"result\":\"ok\"}]}"); -} - -static void req_flash_node(Webs *wp) -{ - WebsKey *s; - WebsUpload *up; - - char *node = NULL; - char *node_flashing_file = NULL; - uint8_t node_id; - flashing_result res; - - node = websGetVar(wp, "node", NULL); - if (!node) - { - app_webS_PrintJsonErr(wp, 400, "No node specified"); - return; - } - - node_flashing_file = websGetVar(wp, "file", NULL); - if (!node_flashing_file) - { - app_webS_PrintJsonErr(wp, 400, "No file specified"); - return; - } - - websSetStatus(wp, 200); - websWriteHeaders(wp, -1, 0); - websWriteHeader(wp, "Content-Type", "text/plain"); - - websWriteEndHeaders(wp); - - if (!isMountSDcard("/mnt/sdcard")) - { - websWrite(wp,"{\"response\":[{\"result\":\"err:no sdcard\"}]}"); - websDone(wp); - return; - } - - // NOTE: code for uploading files (as in uploadFirmware()) omitted, because can't simply - // configure upload path without recompiling. - - node_id = atoi(node); - - res = tpi_flash_node(node_id, node_flashing_file); - - if (res == FR_SUCCESS) - websWrite(wp,"{\"response\":[{\"result\":\"ok\"}]}"); - else - websWrite(wp,"{\"response\":[{\"result\":\"flashing failure: %d\"}]}", res); - - websDone(wp); -} - -static void bmcdemo(Webs *wp) -{ - char *pOpt = NULL; - char *pType = NULL; - - char json_result_buff[1024] = {0}; - - char* url = NULL; - url = websGetUrl(wp); - printf("bmcdemo url=%s\n",url); - - pOpt = websGetVar(wp, "opt", NULL); - pType = websGetVar(wp, "type", NULL); - - websSetStatus(wp, 200); - websWriteHeaders(wp, -1, 0); - websWriteHeader(wp, "Content-Type", "text/plain"); - websWriteEndHeaders(wp); - - if(NULL==pOpt || NULL == pType) - { - app_webS_PrintJsonErr(wp,400,"opt type error"); - return; - } - - if(strcasecmp(pOpt,"get") == 0) - { - printf("this get\n"); - if(0==strcasecmp(pType,"sdcard")) - { - get_sdcard_info(wp); - } - else if(0==strcasecmp(pType,"usb")) - { - get_usbmode(wp); - } - else if(0==strcasecmp(pType,"power")) - { - get_nodepower(wp); - } - else if(0==strcasecmp(pType,"nodeinfo")) - { - get_nodeInfoType(wp); - } - else if(0==strcasecmp(pType,"uart")) - { - get_uartString(wp); - } - else if(0==strcasecmp(pType,"other")) - { - get_otherInfo(wp); - } - // strcpy(json_result_buff,"{\"response\":[{\"result\":\"ok\"}]}"); - // websWrite(wp, "%s", json_result_buff); - // websFlush(wp, 0); - // websDone(wp); - } - else if(0==strcasecmp(pOpt,"set")) - { - printf("this set\n"); - if(0==strcasecmp(pType,"firmware")) - { - uploadFirmware(wp); - } - if(0==strcasecmp(pType,"flash")) - { - req_flash_node(wp); - } - if(0==strcasecmp(pType,"sdcard")) - { - //todo format - // get_sdcard_info(wp); - printf("todo format \n"); - } - else if(0==strcasecmp(pType,"usb")) - { - if(set_usbmode(wp)) - return ; - } - else if(0==strcasecmp(pType,"power")) - { - set_nodepower(wp); - } - else if(0==strcasecmp(pType,"network")) - { - set_network(wp); - } - else if(0==strcasecmp(pType,"nodeinfo")) - { - set_nodeinfo(wp); - } - else if(0==strcasecmp(pType,"uart")) - { - set_uartCmd(wp); - } - else if(0==strcasecmp(pType,"node_to_msd")) - { - run_node_to_msd(wp); - } - else if(0==strcasecmp(pType,"clear_usb_boot")) - { - clear_usb_boot(wp); - } - else if(0==strcasecmp(pType,"reset")) - { - reset_node(wp); - } - - strcpy(json_result_buff,"{\"response\":[{\"result\":\"ok\"}]}"); - websWrite(wp, "%s", json_result_buff); - websFlush(wp, 0); - websDone(wp); - } - else - { - app_webS_PrintJsonErr(wp,401,"opt error"); - } -} - -static go_asp_func_t g_func_reg[] = -{ - {1, "app_WebS_Jst_test", Go_asp_test_disp, NULL}, - {2, "app_WebS_Act_test", NULL, Go_asp_test_Action}, - {2, "bmc", NULL, bmcdemo}, -}; - - -int webstart() -{ - printf("start webserver -\n"); - start_goahead("/mnt", "/mnt/var/www", "http://*:80", "/mnt/route.txt", "/mnt/auth.txt", g_func_reg, sizeof(g_func_reg) / sizeof(go_asp_func_t)); - return 0; -} - - - - diff --git a/app/bmc/webserver.h b/app/bmc/webserver.h deleted file mode 100755 index a816520a6..000000000 --- a/app/bmc/webserver.h +++ /dev/null @@ -1,20 +0,0 @@ -/** - * @file webserver.h - * @author wenyi (wenyi0421@163.com) - * @brief - * @version 0.1 - * @date 2022-08-27 - * - * @copyright Copyright (c) 2022 - * - */ - - -#ifndef __WEBSERVER_H__ -#define __WEBSERVER_H__ - -int webstart(); - - - -#endif diff --git a/tp2bmc/Config.in b/tp2bmc/Config.in index 910189881..e61f3e2ca 100644 --- a/tp2bmc/Config.in +++ b/tp2bmc/Config.in @@ -1,6 +1,4 @@ menu "tpi2 app packages" - source "$BR2_EXTERNAL_TP2BMC_PATH/package/bmc/Config.in" source "$BR2_EXTERNAL_TP2BMC_PATH/package/bmcd/Config.in" source "$BR2_EXTERNAL_TP2BMC_PATH/package/tpi/Config.in" - source "$BR2_EXTERNAL_TP2BMC_PATH/package/tpi_rs/Config.in" endmenu diff --git a/tp2bmc/board/tp2bmc/overlay/bin/curl b/tp2bmc/board/tp2bmc/overlay/bin/curl deleted file mode 100755 index 36105bab1..000000000 Binary files a/tp2bmc/board/tp2bmc/overlay/bin/curl and /dev/null differ diff --git a/tp2bmc/board/tp2bmc/overlay/etc/init.d/S93startup b/tp2bmc/board/tp2bmc/overlay/etc/init.d/S93startup index e19f38d7f..71e4bd281 100755 --- a/tp2bmc/board/tp2bmc/overlay/etc/init.d/S93startup +++ b/tp2bmc/board/tp2bmc/overlay/etc/init.d/S93startup @@ -13,8 +13,5 @@ if [ "$1" = "start" ]; then sleep 1 /etc/setStaticNet.sh - - bmc & - /etc/test_ping.sh & fi diff --git a/tp2bmc/board/tp2bmc/overlay/lib/libgo.so b/tp2bmc/board/tp2bmc/overlay/lib/libgo.so deleted file mode 100644 index 1eb3c17ed..000000000 Binary files a/tp2bmc/board/tp2bmc/overlay/lib/libgo.so and /dev/null differ diff --git a/tp2bmc/board/tp2bmc/overlay/mnt/auth.txt b/tp2bmc/board/tp2bmc/overlay/mnt/auth.txt deleted file mode 100755 index c9ff8b9f5..000000000 --- a/tp2bmc/board/tp2bmc/overlay/mnt/auth.txt +++ /dev/null @@ -1,12 +0,0 @@ -# -# auth.txt - Authorization data -# - -role name=person abilities=breathe -role name=user abilities=view,person -role name=administrator abilities=user,manage - -user name=julie password=9d8873a123eb506e7f8e84d1f2a26916 roles=user -user name=joshua password=2fd6e47ff9bb70c0465fd2f5c8e5305e roles=administrator,purchase -user name=mary password=5b90553bea8ba3686f4239d62801f0f3 roles=user -user name=peter password=7cdba57892649fd95a540683fdf8fba6 roles=user diff --git a/tp2bmc/board/tp2bmc/overlay/mnt/route.txt b/tp2bmc/board/tp2bmc/overlay/mnt/route.txt deleted file mode 100755 index c1992fddf..000000000 --- a/tp2bmc/board/tp2bmc/overlay/mnt/route.txt +++ /dev/null @@ -1,67 +0,0 @@ -# -# route.txt - Route configuration -# -# Schema -# route uri=URI protocol=PROTOCOL methods=METHODS handler=HANDLER redirect=STATUS@URI \ -# extensions=EXTENSIONS abilities=ABILITIES -# -# Abilities are a set of required abilities that the user or request must possess. -# The abilities, extensions, methods and redirect keywords may use comma separated tokens to express a set of -# required options, or use "|" separated tokens for a set of alternative options. This implements AND/OR. -# The protocol keyword may be set to http or https -# Multiple redirect fields are permissable -# -# Redirect over TLS -# route uri=/ protocol=http redirect=https handler=redirect -# -# Form based login pattern -# route uri=/login.html -# route uri=/action/login methods=POST handler=action redirect=200@/ redirect=401@/login.html -# route uri=/action/logout methods=POST handler=action redirect=200@/login.html -# route uri=/ auth=form handler=continue redirect=401@/login.html -# -route uri=/old-alias/ redirect=/alias/atest.html handler=redirect - -# -# Basic and digest authentication required for these directories. -# Require the "manage" ability which only "joshua" has. -# -route uri=/auth/basic/admin/ auth=basic abilities=manage -route uri=/auth/digest/admin/ auth=digest abilities=manage -route uri=/auth/basic/ auth=basic abilities=view -route uri=/auth/digest/ auth=digest abilities=view - -# -# Form-based authentication for content under /auth/form -# The login form is /auth/form/login.html. The page to display when logged-in is /auth/form/index.html -# Everything else under /auth/form is secured and requires the "manage" ability -# -route uri=/auth/form/login.html - -route uri=/action/login methods=POST handler=action redirect=200@/auth/form/index.html redirect=401@/auth/form/login.html -route uri=/action/logout methods=GET|POST handler=action redirect=200@/auth/form/login.html -route uri=/auth/form/ auth=form handler=continue abilities=manage redirect=401@/auth/form/login.html - -# -# Support PUT and DELETE methods only for the BIT_GOAHEAD_PUT_DIR directory -# -route uri=/tmp/ methods=PUT|DELETE - -# -# Require TLS to access anything under /secure -# -route uri=/secure/ protocol=http redirect=https handler=redirect - -# -# Standard routes -# -route uri=/cgi-bin handler=cgi -route uri=/api handler=action -route uri=/ methods=OPTIONS|TRACE handler=options -route uri=/ extensions=jst,asp handler=jst - -# -# Catch-all route without authentication for all other URIs -# -route uri=/ - diff --git a/tp2bmc/board/tp2bmc/overlay/mnt/self.crt b/tp2bmc/board/tp2bmc/overlay/mnt/self.crt deleted file mode 100755 index 17091432a..000000000 --- a/tp2bmc/board/tp2bmc/overlay/mnt/self.crt +++ /dev/null @@ -1,24 +0,0 @@ ------BEGIN CERTIFICATE----- -MIID/TCCAuWgAwIBAgIJANVDnGA7wE2uMA0GCSqGSIb3DQEBCwUAMIGUMQswCQYD -VQQGEwJVUzETMBEGA1UECAwKV2FzaGluZ3RvbjEQMA4GA1UEBwwHU2VhdHRsZTEU -MBIGA1UECgwLRXhhbXBsZS5jb20xFDASBgNVBAsMC0RldmVsb3BtZW50MRIwEAYD -VQQDDAlsb2NhbGhvc3QxHjAcBgkqhkiG9w0BCQEWD2RldkBleGFtcGxlLmNvbTAe -Fw0xNTEwMjkwMDU3MTVaFw0yNTEwMjYwMDU3MTVaMIGUMQswCQYDVQQGEwJVUzET -MBEGA1UECAwKV2FzaGluZ3RvbjEQMA4GA1UEBwwHU2VhdHRsZTEUMBIGA1UECgwL -RXhhbXBsZS5jb20xFDASBgNVBAsMC0RldmVsb3BtZW50MRIwEAYDVQQDDAlsb2Nh -bGhvc3QxHjAcBgkqhkiG9w0BCQEWD2RldkBleGFtcGxlLmNvbTCCASIwDQYJKoZI -hvcNAQEBBQADggEPADCCAQoCggEBAK2UM+JaGgEetPeaI8JG4Qbyyv0CzXzpMetj -K0xjvi5/EaRVyQgvsUDuYiytZS0hsFK0zf0Wvrum+mZNwx7Vzbd0wSTA/1SLfirz -mTZoKr7hBSlsXUDZP62UUqXebmf17om/AUhiS+3iPDUY5HOQxDic65P/KIveu/pG -GJJqrqAPL1M+kpv3FKqIJzEVXc+RCCbTdCEPvM/ujOJWxa34uGB/FfgSPzliqLaB -rYSlrahNlS5R3L2MyC+80IITSmU8pAIsWaJgyCOqIOfQc6ugETIUNusj6olKmivs -Qnco9akXUTE2j5XvRaAoCYXZ+8kIY+JJLXI++R2S+zCk46bevvUCAwEAAaNQME4w -HQYDVR0OBBYEFDrTAkmdc2nKfDYOL2VPw8jQrnWZMB8GA1UdIwQYMBaAFDrTAkmd -c2nKfDYOL2VPw8jQrnWZMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQELBQADggEB -AEIeX5OMIj1qDAD6s6XOkYEV6C9rAHkqW/Skd4yl/DY6TJ1QaPRkG2Ra2Zc9C56m -5xTk4pmWr5+7yFlIQjZSbOVF0fitJKCxAmjfMG/wClnZOPGQCzD6lXAqQnA6etCU -KEg96MXVLz27wrEDZM138JMEV1BEvwMtEX1Uu31v0e3r6vZlJXAKAw9NSzobiq4u -liCdsOPUhVWYi0RukLIGt7p8bfRdG78SvwRJKq9nHig0rimvjQW5nlKNA4HGyaMx -zld+WvKBV1odCrFagDRy94NkuLdbClJw9/BSDfLsIUVQ42ip5+echVt4O9M8ro2B -HgRKX4Vv59qpZ1wR7lnjFT4= ------END CERTIFICATE----- diff --git a/tp2bmc/board/tp2bmc/overlay/mnt/self.key b/tp2bmc/board/tp2bmc/overlay/mnt/self.key deleted file mode 100755 index 987bd7d29..000000000 --- a/tp2bmc/board/tp2bmc/overlay/mnt/self.key +++ /dev/null @@ -1,27 +0,0 @@ ------BEGIN RSA PRIVATE KEY----- -MIIEpAIBAAKCAQEArZQz4loaAR6095ojwkbhBvLK/QLNfOkx62MrTGO+Ln8RpFXJ -CC+xQO5iLK1lLSGwUrTN/Ra+u6b6Zk3DHtXNt3TBJMD/VIt+KvOZNmgqvuEFKWxd -QNk/rZRSpd5uZ/Xuib8BSGJL7eI8NRjkc5DEOJzrk/8oi967+kYYkmquoA8vUz6S -m/cUqognMRVdz5EIJtN0IQ+8z+6M4lbFrfi4YH8V+BI/OWKotoGthKWtqE2VLlHc -vYzIL7zQghNKZTykAixZomDII6og59Bzq6ARMhQ26yPqiUqaK+xCdyj1qRdRMTaP -le9FoCgJhdn7yQhj4kktcj75HZL7MKTjpt6+9QIDAQABAoIBABLdn8IDTv4+Kyca -LrbH419Q9jUHn/PqmI1f6u3TjXEaSH2XAVGNdXN8NVlrwypjlfl3Q0g1t6dHn8GM -xB9O15wP6YooG9hBjQX4Effy3GqApIH7ECujMSOZkl4Kze8osLNx+h626E/Dng2b -VgElg94vV/9u5SZGoCG0iqknRTGKJwoJ68ubrwkamf08H/RCkIEbaNXvOOI4jnuY -lcwAf8M3yKS6z6dLc4rNwuZb0gOt91PZllvqxj6aFTqeiupe/Qm1NcxHb/yAbS20 -XnaD+Y21T/mhbLV4eq7W/JoLpUvyy1Sk9YA2Vux36btm6mPLPdpANvC7A1MYB7JY -R6Ycx+ECgYEA4ZV1R45woALECOUALfwj3T2CdXt8brA47Ky4gzRWxH0ILkUcpDmq -hVBJNwrSegzPYsalvY2AkK5F9XCVP0oqYDfieJeCRj6yxPYMRkaMF9Bt7UcOA5Y8 -ilxGZ/FOaF0Uz3pw9mFUwYd9eNPl5KkuNMp8TcA7SOI3r47MR2LAe9kCgYEAxPut -H0uBHQqdJ/iN5vY7y25MErBa9TqBPG9MoEHX3vtPFrCklUfY0ELYQyY9I5ieU7Ei -97Ug4F+0dnuz+E/xQdw/59FI866uoNYlELgMLDY9LL9QStSJAbYSDYU73Wvr0Y6C -Pel1fjWIKdwWdNSJFI02rI4KTKN2ONJ5QxXGtn0CgYEAwkHmQLyUl/ZJwi8RvIfI -ipiRY4H3YYo3Ovhx2+qSXZoeFVpGk9Vk1nCQ2+lh3uBxJmpSB6127SBl9joBDANe -AoWdbKNr9/m+EIahg1L1CPzf7NinZMdXUv6rUo8mKhEd/p098a1XQ2Dd19MBwas+ -sw87g+jqJJVJxtB9cWvEveECgYBcz/SnPS0toNWhgrRhsX1FAcgoOh3xU8qWzh49 -mCh9cM239CzoBX07y3MYWIkQH5Xh+yFts1M1RQLDnM+UXR5gmMUnle2Ym6K+N4gp -U36wyjGSxuWvDGstejsRUch+MJ5hE5N8Vma8u75XctLF42pfW5X6QcbKi25loY3v -NPB3BQKBgQDeeUHn7vCRm4aTeY/DPkI5uaModZkPjvGZu8pBoWWLnmuxHsYrfJw0 -jrZa1jsknxh1oC5uSlFE7xRcyy5Gr/GvJdaJ9mqqnsXsa/vqYUEYGKpiTyMb1w6f -APj+623cK/5/2Px5dB1pepA6yABpb3Jo/lIiAhCAvDPrcP8GgmJ2rw== ------END RSA PRIVATE KEY----- diff --git a/tp2bmc/configs/tp2bmc_defconfig b/tp2bmc/configs/tp2bmc_defconfig index 5a022f1c8..102c6a09d 100644 --- a/tp2bmc/configs/tp2bmc_defconfig +++ b/tp2bmc/configs/tp2bmc_defconfig @@ -77,7 +77,6 @@ BR2_PACKAGE_ANDROID_TOOLS=y BR2_PACKAGE_AVAHI_DAEMON=y BR2_PACKAGE_AVAHI=y BR2_PACKAGE_BASH=y -BR2_PACKAGE_CJSON=y BR2_PACKAGE_COLLECTD_CURL=y BR2_PACKAGE_COLLECTD=y BR2_PACKAGE_EVTEST=y @@ -88,7 +87,6 @@ BR2_PACKAGE_LIBAIO=y BR2_PACKAGE_LIBCURL_CURL=y BR2_PACKAGE_LIBCURL=y BR2_PACKAGE_LIBEVENT=y -BR2_PACKAGE_LIBGPIOD_TOOLS=y BR2_PACKAGE_LIBGPIOD=y BR2_PACKAGE_LIBTIRPC=y BR2_PACKAGE_LIBUBOOTENV=y @@ -101,6 +99,7 @@ BR2_PACKAGE_NANO=y BR2_PACKAGE_NSS_MDNS=y BR2_PACKAGE_CHRONY=y BR2_PACKAGE_OPENSSH=y +BR2_PACKAGE_OPENSSL=y BR2_PACKAGE_PICOCOM=y BR2_PACKAGE_START_STOP_DAEMON=y BR2_PACKAGE_SWUPDATE_CONFIG="$(BR2_EXTERNAL_TP2BMC_PATH)/board/tp2bmc/swupdate.config" @@ -113,7 +112,5 @@ BR2_PACKAGE_UTIL_LINUX_LIBUUID=y BR2_PACKAGE_UTIL_LINUX_UUIDD=y # Custom packages -BR2_PACKAGE_BMC=y BR2_PACKAGE_BMCD=y BR2_PACKAGE_TPI=y -BR2_PACKAGE_TPI_RS=y diff --git a/tp2bmc/package/bmc/Config.in b/tp2bmc/package/bmc/Config.in deleted file mode 100644 index 47c8fb715..000000000 --- a/tp2bmc/package/bmc/Config.in +++ /dev/null @@ -1,6 +0,0 @@ -config BR2_PACKAGE_BMC - bool "bmc" - depends on BR2_PACKAGE_TPI_RS - depends on BR2_PACKAGE_CJSON - help - This is a bmc diff --git a/tp2bmc/package/bmc/bmc.mk b/tp2bmc/package/bmc/bmc.mk deleted file mode 100644 index 4b4cafad9..000000000 --- a/tp2bmc/package/bmc/bmc.mk +++ /dev/null @@ -1,23 +0,0 @@ -########################################################### -# bmc -########################################################### - -BMC_VERSION:= 1.1.0 -BMC_SITE:= $(TOPDIR)/../app/bmc -BMC_SITE_METHOD:=local -BMC_INSTALL_TARGET:=YES -BMC_DEPENDENCIES = cjson tpi_rs - -define BMC_BUILD_CMDS - $(MAKE) CC="$(TARGET_CC)" LD="$(TARGET_LD)" -C $(@D) all -endef - -define BMC_INSTALL_TARGET_CMDS - $(INSTALL) -D -m 0755 $(@D)/bmc $(TARGET_DIR)/bin -endef - -define BMC_PERMISSIONS - /bin/bmc f 4755 0 0 - - - - - -endef - -$(eval $(generic-package)) diff --git a/tp2bmc/package/tpi_rs/Config.in b/tp2bmc/package/tpi_rs/Config.in deleted file mode 100644 index d716f452f..000000000 --- a/tp2bmc/package/tpi_rs/Config.in +++ /dev/null @@ -1,7 +0,0 @@ -config BR2_PACKAGE_TPI_RS - bool "tpi_rs" - depends on BR2_PACKAGE_HOST_RUSTC_TARGET_ARCH_SUPPORTS - select BR2_PACKAGE_HOST_RUSTC - select BR2_PACKAGE_LIBUSB - help - development of the rust version of the tp2 diff --git a/tp2bmc/package/tpi_rs/tpi_rs.mk b/tp2bmc/package/tpi_rs/tpi_rs.mk deleted file mode 100644 index 7ef79583b..000000000 --- a/tp2bmc/package/tpi_rs/tpi_rs.mk +++ /dev/null @@ -1,38 +0,0 @@ -########################################################### -# -# tpi_rs -# -########################################################### - -TPI_RS_VERSION = bb3636350509b09fcb4b4637b8fd669719206d5a -TPI_RS_SITE = $(call github,turing-machines,bmcd,$(TPI_RS_VERSION)) -TPI_RS_LICENSE = Apache-2.0 -TPI_RS_LICENSE_FILES = LICENSE -TPI_RS_INSTALL_STAGING = YES -TPI_RS_INSTALL_TARGET = NO -TPI_RS_CARGO_ENV := PKG_CONFIG_ALLOW_CROSS=1 # for `libusb1-sys` -TPI_RS_CARGO_ENV += CC_armv7_unknown_linux_gnueabi="arm-linux-gcc" # for `ring` -TPI_RS_DEPENDENCIES = libusb - -# This build step is the default build command (see pkg-cargo.mk), but with TARGET_CONFIGURE_OPTS -# variable removed, as providing environment variable CC="…/arm-buildroot-linux-gnueabi-gcc" causes -# compilation to fail. -define TPI_RS_BUILD_CMDS - cd $(TPI_RS_SRCDIR) && \ - $(TARGET_MAKE_ENV) \ - $(PKG_CARGO_ENV) \ - $(TPI_RS_CARGO_ENV) \ - cargo build \ - --offline \ - $(if $(BR2_ENABLE_DEBUG),,--release) \ - --manifest-path Cargo.toml \ - --locked \ - $(TPI_RS_CARGO_BUILD_OPTS) -endef - -define TPI_RS_INSTALL_STAGING_CMDS - $(INSTALL) -D -m 0644 $(@D)/target/$(RUSTC_TARGET_NAME)/$(if $(BR2_ENABLE_DEBUG),debug,release)/libtpi_rs.a $(STAGING_DIR)/lib - $(INSTALL) -D -m 0644 $(@D)/tpi_rs/tpi_rs.h $(STAGING_DIR)/usr/include -endef - -$(eval $(cargo-package))