Aer Interpreter Source
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

621 lines
34 KiB

  1. /* This file was automatically generated. Do not edit (except for compile time directive)! */
  2. #ifndef _PH7_H_
  3. #define _PH7_H_
  4. /*
  5. * Symisc PH7: An embeddable bytecode compiler and a virtual machine for the PHP(5) programming language.
  6. * Copyright (C) 2011-2012, Symisc Systems https://ph7.symisc.net/
  7. * Version 2.1.4
  8. * For information on licensing,redistribution of this file,and for a DISCLAIMER OF ALL WARRANTIES
  9. * please contact Symisc Systems via:
  10. * legal@symisc.net
  11. * licensing@symisc.net
  12. * contact@symisc.net
  13. * or visit:
  14. * https://ph7.symisc.net/
  15. */
  16. /*
  17. * Copyright (C) 2011, 2012 Symisc Systems. All rights reserved.
  18. *
  19. * Redistribution and use in source and binary forms, with or without
  20. * modification, are permitted provided that the following conditions
  21. * are met:
  22. * 1. Redistributions of source code must retain the above copyright
  23. * notice, this list of conditions and the following disclaimer.
  24. * 2. Redistributions in binary form must reproduce the above copyright
  25. * notice, this list of conditions and the following disclaimer in the
  26. * documentation and/or other materials provided with the distribution.
  27. * 3. Redistributions in any form must be accompanied by information on
  28. * how to obtain complete source code for the PH7 engine and any
  29. * accompanying software that uses the PH7 engine software.
  30. * The source code must either be included in the distribution
  31. * or be available for no more than the cost of distribution plus
  32. * a nominal fee, and must be freely redistributeable under reasonable
  33. * conditions. For an executable file, complete source code means
  34. * the source code for all modules it contains.It does not include
  35. * source code for modules or files that typically accompany the major
  36. * components of the operating system on which the executable file runs.
  37. *
  38. * THIS SOFTWARE IS PROVIDED BY SYMISC SYSTEMS ``AS IS'' AND ANY EXPRESS
  39. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  40. * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
  41. * NON-INFRINGEMENT, ARE DISCLAIMED. IN NO EVENT SHALL SYMISC SYSTEMS
  42. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  43. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  44. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  45. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  46. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  47. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  48. * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  49. */
  50. /* $SymiscID: ph7.h v2.1 UNIX|WIN32/64 2012-09-15 09:43 stable <chm@symisc.net> $ */
  51. #include <stdarg.h> /* needed for the definition of va_list */
  52. #include <stdio.h> /* needed for the definition of snprintf */
  53. #include <limits.h> /* needed for MAX_PATH */
  54. #ifndef PATH_MAX
  55. #define PATH_MAX MAX_PATH
  56. #endif
  57. /*
  58. * The PH7_VERSION C preprocessor macroevaluates to a string literal
  59. * that is the ph7 version in the format "X.Y.Z" where X is the major
  60. * version number and Y is the minor version number and Z is the release
  61. * number.
  62. */
  63. #define PH7_VERSION "2.1.4"
  64. /*
  65. * The PH7_SIG C preprocessor macro evaluates to a string
  66. * literal which is the public signature of the ph7 engine.
  67. * This signature could be included for example in a host-application
  68. * generated Server MIME header as follows:
  69. * Server: YourWebServer/x.x PH7/x.x.x \r\n
  70. */
  71. #define PH7_SIG "PH7/2.1.4"
  72. /*
  73. * Copyright notice.
  74. * If you have any questions about the licensing situation,please
  75. * visit https://ph7.symisc.net/licensing.html
  76. * or contact Symisc Systems via:
  77. * legal@symisc.net
  78. * licensing@symisc.net
  79. * contact@symisc.net
  80. */
  81. #define PH7_COPYRIGHT "Copyright (C) Symisc Systems 2011-2012, https://ph7.symisc.net/"
  82. /* Forward declaration to public objects */
  83. typedef struct ph7_io_stream ph7_io_stream;
  84. typedef struct ph7_context ph7_context;
  85. typedef struct ph7_value ph7_value;
  86. typedef struct ph7_vfs ph7_vfs;
  87. typedef struct ph7_vm ph7_vm;
  88. typedef struct ph7 ph7;
  89. /* Symisc public definitions */
  90. #if !defined(SYMISC_STANDARD_DEFS)
  91. #define SYMISC_STANDARD_DEFS
  92. #if defined (_WIN32) || defined (WIN32) || defined(__MINGW32__) || defined (_MSC_VER) || defined (_WIN32_WCE)
  93. /* Windows Systems */
  94. #if !defined(__WINNT__)
  95. #define __WINNT__
  96. #endif
  97. #else
  98. /*
  99. * By default we will assume that we are compiling on a UNIX systems.
  100. * Otherwise the OS_OTHER directive must be defined.
  101. */
  102. #if !defined(OS_OTHER)
  103. #if !defined(__UNIXES__)
  104. #define __UNIXES__
  105. #endif /* __UNIXES__ */
  106. #else
  107. #endif /* OS_OTHER */
  108. #endif /* __WINNT__/__UNIXES__ */
  109. #if defined(_MSC_VER) || defined(__BORLANDC__)
  110. typedef signed __int64 sxi64; /* 64 bits(8 bytes) signed int64 */
  111. typedef unsigned __int64 sxu64; /* 64 bits(8 bytes) unsigned int64 */
  112. #else
  113. typedef signed long long int sxi64; /* 64 bits(8 bytes) signed int64 */
  114. typedef unsigned long long int sxu64; /* 64 bits(8 bytes) unsigned int64 */
  115. #endif /* _MSC_VER */
  116. /* Solaris additions */
  117. #ifndef MAP_FILE
  118. #define MAP_FILE 0
  119. #endif
  120. /* Signature of the consumer routine */
  121. typedef int (*ProcConsumer)(const void *, unsigned int, void *);
  122. /* Forward reference */
  123. typedef struct SyMutexMethods SyMutexMethods;
  124. typedef struct SyMemMethods SyMemMethods;
  125. typedef struct SyString SyString;
  126. typedef struct syiovec syiovec;
  127. typedef struct SyMutex SyMutex;
  128. typedef struct Sytm Sytm;
  129. /* Scatter and gather array. */
  130. struct syiovec {
  131. #if defined (__WINNT__)
  132. /* Same fields type and offset as WSABUF structure defined one winsock2 header */
  133. unsigned long nLen;
  134. char *pBase;
  135. #else
  136. void *pBase;
  137. unsigned long nLen;
  138. #endif
  139. };
  140. struct SyString {
  141. const char *zString; /* Raw string (may not be null terminated) */
  142. unsigned int nByte; /* Raw string length */
  143. };
  144. /* Time structure. */
  145. struct Sytm {
  146. int tm_sec; /* seconds (0 - 60) */
  147. int tm_min; /* minutes (0 - 59) */
  148. int tm_hour; /* hours (0 - 23) */
  149. int tm_mday; /* day of month (1 - 31) */
  150. int tm_mon; /* month of year (0 - 11) */
  151. int tm_year; /* year + 1900 */
  152. int tm_wday; /* day of week (Sunday = 0) */
  153. int tm_yday; /* day of year (0 - 365) */
  154. int tm_isdst; /* is summer time in effect? */
  155. char *tm_zone; /* abbreviation of timezone name */
  156. long tm_gmtoff; /* offset from UTC in seconds */
  157. };
  158. /* Convert a tm structure (struct tm *) found in <time.h> to a Sytm structure */
  159. #define STRUCT_TM_TO_SYTM(pTM,pSYTM) \
  160. (pSYTM)->tm_hour = (pTM)->tm_hour;\
  161. (pSYTM)->tm_min = (pTM)->tm_min;\
  162. (pSYTM)->tm_sec = (pTM)->tm_sec;\
  163. (pSYTM)->tm_mon = (pTM)->tm_mon;\
  164. (pSYTM)->tm_mday = (pTM)->tm_mday;\
  165. (pSYTM)->tm_year = (pTM)->tm_year + 1900;\
  166. (pSYTM)->tm_yday = (pTM)->tm_yday;\
  167. (pSYTM)->tm_wday = (pTM)->tm_wday;\
  168. (pSYTM)->tm_isdst = (pTM)->tm_isdst;\
  169. (pSYTM)->tm_gmtoff = 0;\
  170. (pSYTM)->tm_zone = 0;
  171. /* Convert a SYSTEMTIME structure (LPSYSTEMTIME: Windows Systems only ) to a Sytm structure */
  172. #define SYSTEMTIME_TO_SYTM(pSYSTIME,pSYTM) \
  173. (pSYTM)->tm_hour = (pSYSTIME)->wHour;\
  174. (pSYTM)->tm_min = (pSYSTIME)->wMinute;\
  175. (pSYTM)->tm_sec = (pSYSTIME)->wSecond;\
  176. (pSYTM)->tm_mon = (pSYSTIME)->wMonth - 1;\
  177. (pSYTM)->tm_mday = (pSYSTIME)->wDay;\
  178. (pSYTM)->tm_year = (pSYSTIME)->wYear;\
  179. (pSYTM)->tm_yday = 0;\
  180. (pSYTM)->tm_wday = (pSYSTIME)->wDayOfWeek;\
  181. (pSYTM)->tm_gmtoff = 0;\
  182. (pSYTM)->tm_isdst = -1;\
  183. (pSYTM)->tm_zone = 0;
  184. /* Dynamic memory allocation methods. */
  185. struct SyMemMethods {
  186. void *(*xAlloc)(unsigned int); /* [Required:] Allocate a memory chunk */
  187. void *(*xRealloc)(void *, unsigned int); /* [Required:] Re-allocate a memory chunk */
  188. void (*xFree)(void *); /* [Required:] Release a memory chunk */
  189. unsigned int (*xChunkSize)(void *); /* [Required:] Return chunk size */
  190. int (*xInit)(void *); /* [Optional:] Initialization callback */
  191. void (*xRelease)(void *); /* [Optional:] Release callback */
  192. void *pUserData; /* [Optional:] First argument to xInit() and xRelease() */
  193. };
  194. /* Out of memory callback signature. */
  195. typedef int (*ProcMemError)(void *);
  196. /* Mutex methods. */
  197. struct SyMutexMethods {
  198. int (*xGlobalInit)(void); /* [Optional:] Global mutex initialization */
  199. void (*xGlobalRelease)(void); /* [Optional:] Global Release callback () */
  200. SyMutex *(*xNew)(int); /* [Required:] Request a new mutex */
  201. void (*xRelease)(SyMutex *); /* [Optional:] Release a mutex */
  202. void (*xEnter)(SyMutex *); /* [Required:] Enter mutex */
  203. int (*xTryEnter)(SyMutex *); /* [Optional:] Try to enter a mutex */
  204. void (*xLeave)(SyMutex *); /* [Required:] Leave a locked mutex */
  205. };
  206. #if defined (_MSC_VER) || defined (__MINGW32__) || defined (__GNUC__) && defined (__declspec)
  207. #define SX_APIIMPORT __declspec(dllimport)
  208. #define SX_APIEXPORT __declspec(dllexport)
  209. #else
  210. #define SX_APIIMPORT
  211. #define SX_APIEXPORT
  212. #endif
  213. /* Standard return values from Symisc public interfaces */
  214. #define SXRET_OK 0 /* Not an error */
  215. #define SXERR_MEM (-1) /* Out of memory */
  216. #define SXERR_IO (-2) /* IO error */
  217. #define SXERR_EMPTY (-3) /* Empty field */
  218. #define SXERR_LOCKED (-4) /* Locked operation */
  219. #define SXERR_ORANGE (-5) /* Out of range value */
  220. #define SXERR_NOTFOUND (-6) /* Item not found */
  221. #define SXERR_LIMIT (-7) /* Limit reached */
  222. #define SXERR_MORE (-8) /* Need more input */
  223. #define SXERR_INVALID (-9) /* Invalid parameter */
  224. #define SXERR_ABORT (-10) /* User callback request an operation abort */
  225. #define SXERR_EXISTS (-11) /* Item exists */
  226. #define SXERR_SYNTAX (-12) /* Syntax error */
  227. #define SXERR_UNKNOWN (-13) /* Unknown error */
  228. #define SXERR_BUSY (-14) /* Busy operation */
  229. #define SXERR_OVERFLOW (-15) /* Stack or buffer overflow */
  230. #define SXERR_WILLBLOCK (-16) /* Operation will block */
  231. #define SXERR_NOTIMPLEMENTED (-17) /* Operation not implemented */
  232. #define SXERR_EOF (-18) /* End of input */
  233. #define SXERR_PERM (-19) /* Permission error */
  234. #define SXERR_NOOP (-20) /* No-op */
  235. #define SXERR_FORMAT (-21) /* Invalid format */
  236. #define SXERR_NEXT (-22) /* Not an error */
  237. #define SXERR_OS (-23) /* System call return an error */
  238. #define SXERR_CORRUPT (-24) /* Corrupted pointer */
  239. #define SXERR_CONTINUE (-25) /* Not an error: Operation in progress */
  240. #define SXERR_NOMATCH (-26) /* No match */
  241. #define SXERR_RESET (-27) /* Operation reset */
  242. #define SXERR_DONE (-28) /* Not an error */
  243. #define SXERR_SHORT (-29) /* Buffer too short */
  244. #define SXERR_PATH (-30) /* Path error */
  245. #define SXERR_TIMEOUT (-31) /* Timeout */
  246. #define SXERR_BIG (-32) /* Too big for processing */
  247. #define SXERR_RETRY (-33) /* Retry your call */
  248. #define SXERR_IGNORE (-63) /* Ignore */
  249. #endif /* SYMISC_PUBLIC_DEFS */
  250. /* Standard PH7 return values */
  251. #define PH7_OK SXRET_OK /* Successful result */
  252. /* beginning-of-error-codes */
  253. #define PH7_NOMEM SXERR_MEM /* Out of memory */
  254. #define PH7_ABORT SXERR_ABORT /* Foreign Function request operation abort/Another thread have released this instance */
  255. #define PH7_IO_ERR SXERR_IO /* IO error */
  256. #define PH7_CORRUPT SXERR_CORRUPT /* Corrupt pointer/Unknown configuration option */
  257. #define PH7_LOOKED SXERR_LOCKED /* Forbidden Operation */
  258. #define PH7_COMPILE_ERR (-70) /* Compilation error */
  259. #define PH7_VM_ERR (-71) /* Virtual machine error */
  260. /* end-of-error-codes */
  261. /*
  262. * If compiling for a processor that lacks floating point
  263. * support, substitute integer for floating-point.
  264. */
  265. typedef double ph7_real;
  266. typedef sxi64 ph7_int64;
  267. #define PH7_APIEXPORT SX_APIEXPORT
  268. #define PH7_APIIMPORT SX_APIIMPORT
  269. /*
  270. * Engine Configuration Commands.
  271. *
  272. * The following set of constants are the available configuration verbs that can
  273. * be used by the host-application to configure the PH7 engine.
  274. * These constants must be passed as the second argument to the [ph7_config()]
  275. * interface.
  276. * Each options require a variable number of arguments.
  277. * The [ph7_config()] interface will return PH7_OK on success, any other
  278. * return value indicates failure.
  279. * For a full discussion on the configuration verbs and their expected
  280. * parameters, please refer to this page:
  281. * https://ph7.symisc.net/c_api_func.html#ph7_config
  282. */
  283. #define PH7_CONFIG_ERR_OUTPUT 1 /* TWO ARGUMENTS: int (*xConsumer)(const void *pOut,unsigned int nLen,void *pUserData),void *pUserData */
  284. #define PH7_CONFIG_ERR_ABORT 2 /* RESERVED FOR FUTURE USE */
  285. #define PH7_CONFIG_ERR_LOG 3 /* TWO ARGUMENTS: const char **pzBuf,int *pLen */
  286. #define PH7_CONFIG_MEM_LIMIT 4 /* ONE ARGUMENT: char *nMemLimit */
  287. /*
  288. * Virtual Machine Configuration Commands.
  289. *
  290. * The following set of constants are the available configuration verbs that can
  291. * be used by the host-application to configure the PH7 Virtual machine.
  292. * These constants must be passed as the second argument to the [ph7_vm_config()]
  293. * interface.
  294. * Each options require a variable number of arguments.
  295. * The [ph7_vm_config()] interface will return PH7_OK on success, any other return
  296. * value indicates failure.
  297. * There are many options but the most importants are: PH7_VM_CONFIG_OUTPUT which install
  298. * a VM output consumer callback, PH7_VM_CONFIG_HTTP_REQUEST which parse and register
  299. * a HTTP request and PH7_VM_CONFIG_ARGV_ENTRY which populate the $argv array.
  300. * For a full discussion on the configuration verbs and their expected parameters, please
  301. * refer to this page:
  302. * https://ph7.symisc.net/c_api_func.html#ph7_vm_config
  303. */
  304. #define PH7_VM_CONFIG_OUTPUT 1 /* TWO ARGUMENTS: int (*xConsumer)(const void *pOut,unsigned int nLen,void *pUserData),void *pUserData */
  305. #define PH7_VM_CONFIG_IMPORT_PATH 3 /* ONE ARGUMENT: const char *zIncludePath */
  306. #define PH7_VM_CONFIG_ERR_REPORT 4 /* NO ARGUMENTS: Report all run-time errors in the VM output */
  307. #define PH7_VM_CONFIG_CREATE_SUPER 5 /* TWO ARGUMENTS: const char *zName,ph7_value *pValue */
  308. #define PH7_VM_CONFIG_CREATE_VAR 6 /* TWO ARGUMENTS: const char *zName,ph7_value *pValue */
  309. #define PH7_VM_CONFIG_HTTP_REQUEST 7 /* TWO ARGUMENTS: const char *zRawRequest,int nRequestLength */
  310. #define PH7_VM_CONFIG_SERVER_ATTR 8 /* THREE ARGUMENTS: const char *zKey,const char *zValue,int nLen */
  311. #define PH7_VM_CONFIG_ENV_ATTR 9 /* THREE ARGUMENTS: const char *zKey,const char *zValue,int nLen */
  312. #define PH7_VM_CONFIG_SESSION_ATTR 10 /* THREE ARGUMENTS: const char *zKey,const char *zValue,int nLen */
  313. #define PH7_VM_CONFIG_POST_ATTR 11 /* THREE ARGUMENTS: const char *zKey,const char *zValue,int nLen */
  314. #define PH7_VM_CONFIG_GET_ATTR 12 /* THREE ARGUMENTS: const char *zKey,const char *zValue,int nLen */
  315. #define PH7_VM_CONFIG_COOKIE_ATTR 13 /* THREE ARGUMENTS: const char *zKey,const char *zValue,int nLen */
  316. #define PH7_VM_CONFIG_HEADER_ATTR 14 /* THREE ARGUMENTS: const char *zKey,const char *zValue,int nLen */
  317. #define PH7_VM_CONFIG_IO_STREAM 15 /* ONE ARGUMENT: const ph7_io_stream *pStream */
  318. #define PH7_VM_CONFIG_ARGV_ENTRY 16 /* ONE ARGUMENT: const char *zValue */
  319. #define PH7_VM_CONFIG_EXTRACT_OUTPUT 17 /* TWO ARGUMENTS: const void **ppOut,unsigned int *pOutputLen */
  320. /*
  321. * Global Library Configuration Commands.
  322. *
  323. * The following set of constants are the available configuration verbs that can
  324. * be used by the host-application to configure the whole library.
  325. * These constants must be passed as the first argument to the [ph7_lib_config()]
  326. * interface.
  327. * Each options require a variable number of arguments.
  328. * The [ph7_lib_config()] interface will return PH7_OK on success, any other return
  329. * value indicates failure.
  330. * Notes:
  331. * The default configuration is recommended for most applications and so the call to
  332. * [ph7_lib_config()] is usually not necessary. It is provided to support rare
  333. * applications with unusual needs.
  334. * The [ph7_lib_config()] interface is not threadsafe. The application must insure that
  335. * no other [ph7_*()] interfaces are invoked by other threads while [ph7_lib_config()]
  336. * is running. Furthermore, [ph7_lib_config()] may only be invoked prior to library
  337. * initialization using [ph7_lib_init()] or [ph7_init()] or after shutdown
  338. * by [ph7_lib_shutdown()]. If [ph7_lib_config()] is called after [ph7_lib_init()]
  339. * or [ph7_init()] and before [ph7_lib_shutdown()] then it will return PH7_LOCKED.
  340. * Refer to the official documentation for more information on the configuration verbs
  341. * and their expected parameters.
  342. * For a full discussion on the configuration verbs and their expected parameters,please
  343. * refer to this page:
  344. * https://ph7.symisc.net/c_api_func.html#Global_Library_Management_Interfaces
  345. */
  346. #define PH7_LIB_CONFIG_USER_MALLOC 1 /* ONE ARGUMENT: const SyMemMethods *pMemMethods */
  347. #define PH7_LIB_CONFIG_MEM_ERR_CALLBACK 2 /* TWO ARGUMENTS: int (*xMemError)(void *),void *pUserData */
  348. #define PH7_LIB_CONFIG_USER_MUTEX 3 /* ONE ARGUMENT: const SyMutexMethods *pMutexMethods */
  349. #define PH7_LIB_CONFIG_THREAD_LEVEL_SINGLE 4 /* NO ARGUMENTS */
  350. #define PH7_LIB_CONFIG_THREAD_LEVEL_MULTI 5 /* NO ARGUMENTS */
  351. #define PH7_LIB_CONFIG_VFS 6 /* ONE ARGUMENT: const ph7_vfs *pVfs */
  352. /*
  353. * Compile-time flags.
  354. *
  355. * VmEvalChunk and PH7_CompileAerScript takes iFlags argument
  356. * which controls the behavior of the PH7 Engine while
  357. * processing the input.
  358. */
  359. #define PH7_AERSCRIPT_CODE 0x01 /* AerScript Code */
  360. #define PH7_AERSCRIPT_CHNK 0x02 /* AerScript Chunk of Code */
  361. #define PH7_AERSCRIPT_EXPR 0x04 /* AerScript Expression */
  362. /*
  363. * Call Context Error Message Severity Level.
  364. *
  365. * The following constans are the allowed severity level that can
  366. * passed as the second argument to the PH7_VmThrowError().
  367. * Refer to the official documentation for additional information.
  368. */
  369. #define PH7_CTX_ERR 1 /* Call context Error such as unexpected number of arguments,invalid types and so on. */
  370. #define PH7_CTX_WARNING 2 /* Call context Warning */
  371. #define PH7_CTX_NOTICE 3 /* Call context Notice */
  372. #define PH7_CTX_DEPRECATED 4 /* Call context Deprecated notice */
  373. /* Current VFS structure version*/
  374. #define PH7_VFS_VERSION 2
  375. /*
  376. * PH7 Virtual File System (VFS).
  377. *
  378. * An instance of the ph7_vfs object defines the interface between the PH7 core
  379. * and the underlying operating system. The "vfs" in the name of the object stands
  380. * for "virtual file system". The vfs is used to implement PHP system functions
  381. * such as mkdir(), chdir(), stat(), get_user_name() and many more.
  382. * The value of the iVersion field is initially 2 but may be larger in future versions
  383. * of PH7.
  384. * Additional fields may be appended to this object when the iVersion value is increased.
  385. * Only a single vfs can be registered within the PH7 core. Vfs registration is done
  386. * using the ph7_lib_config() interface with a configuration verb set to PH7_LIB_CONFIG_VFS.
  387. * Note that Windows and UNIX (Linux, FreeBSD, Solaris, Mac OS X, etc.) users does not have to
  388. * worry about registering and installing a vfs since PH7 come with a built-in vfs for these
  389. * platforms which implement most the methods defined below.
  390. * Host-application running on exotic systems (ie: Other than Windows and UNIX systems) must
  391. * register their own vfs in order to be able to use and call PHP system function.
  392. * Also note that the ph7_compile_file() interface depend on the xMmap() method of the underlying
  393. * vfs which mean that this method must be available (Always the case using the built-in VFS)
  394. * in order to use this interface.
  395. * Developers wishing to implement the vfs methods can contact symisc systems to obtain
  396. * the PH7 VFS C/C++ Specification manual.
  397. */
  398. struct ph7_vfs {
  399. const char *zName; /* Underlying VFS name [i.e: FreeBSD/Linux/Windows...] */
  400. int iVersion; /* Current VFS structure version [default 2] */
  401. /* Directory functions */
  402. int (*xChdir)(const char *); /* Change directory */
  403. int (*xChroot)(const char *); /* Change the root directory */
  404. int (*xGetcwd)(ph7_context *); /* Get the current working directory */
  405. int (*xMkdir)(const char *, int, int); /* Make directory */
  406. int (*xRmdir)(const char *); /* Remove directory */
  407. int (*xIsdir)(const char *); /* Tells whether the filename is a directory */
  408. int (*xRename)(const char *, const char *); /* Renames a file or directory */
  409. int (*xRealpath)(const char *, ph7_context *); /* Return canonicalized absolute pathname*/
  410. /* Systems functions */
  411. int (*xSleep)(unsigned int); /* Delay execution in microseconds */
  412. int (*xUnlink)(const char *); /* Deletes a file */
  413. int (*xFileExists)(const char *); /* Checks whether a file or directory exists */
  414. int (*xChmod)(const char *, int); /* Changes file mode */
  415. int (*xChown)(const char *, const char *); /* Changes file owner */
  416. int (*xChgrp)(const char *, const char *); /* Changes file group */
  417. ph7_int64(*xFreeSpace)(const char *); /* Available space on filesystem or disk partition */
  418. ph7_int64(*xTotalSpace)(const char *); /* Total space on filesystem or disk partition */
  419. ph7_int64(*xFileSize)(const char *); /* Gets file size */
  420. ph7_int64(*xFileAtime)(const char *); /* Gets last access time of file */
  421. ph7_int64(*xFileMtime)(const char *); /* Gets file modification time */
  422. ph7_int64(*xFileCtime)(const char *); /* Gets inode change time of file */
  423. ph7_int64(*xFileGroup)(const char *); /* Gets file group */
  424. ph7_int64(*xFileInode)(const char *); /* Gets file inode */
  425. ph7_int64(*xFileOwner)(const char *); /* Gets file owner */
  426. int (*xStat)(const char *, ph7_value *, ph7_value *); /* Gives information about a file */
  427. int (*xlStat)(const char *, ph7_value *, ph7_value *); /* Gives information about a file */
  428. int (*xIsFile)(const char *); /* Tells whether the filename is a regular file */
  429. int (*xIsLink)(const char *); /* Tells whether the filename is a symbolic link */
  430. int (*xReadable)(const char *); /* Tells whether a file exists and is readable */
  431. int (*xWritable)(const char *); /* Tells whether the filename is writable */
  432. int (*xExecutable)(const char *); /* Tells whether the filename is executable */
  433. int (*xFiletype)(const char *, ph7_context *); /* Gets file type [i.e: fifo,dir,file..] */
  434. int (*xGetenv)(const char *, ph7_context *); /* Gets the value of an environment variable */
  435. int (*xSetenv)(const char *, const char *); /* Sets the value of an environment variable */
  436. int (*xTouch)(const char *, ph7_int64, ph7_int64); /* Sets access and modification time of file */
  437. int (*xMmap)(const char *, void **, ph7_int64 *); /* Read-only memory map of the whole file */
  438. void (*xUnmap)(void *, ph7_int64); /* Unmap a memory view */
  439. int (*xLink)(const char *, const char *, int); /* Create hard or symbolic link */
  440. int (*xUmask)(int); /* Change the current umask */
  441. void (*xTempDir)(ph7_context *); /* Get path of the temporary directory */
  442. unsigned int (*xProcessId)(void); /* Get running process ID */
  443. int (*xUid)(void); /* user ID of the process */
  444. int (*xGid)(void); /* group ID of the process */
  445. void (*xUsername)(ph7_context *); /* Running username */
  446. };
  447. /* Current PH7 IO stream structure version. */
  448. #define PH7_IO_STREAM_VERSION 1
  449. /*
  450. * Possible open mode flags that can be passed to the xOpen() routine
  451. * of the underlying IO stream device .
  452. * Refer to the PH7 IO Stream C/C++ specification manual (https://ph7.symisc.net/io_stream_spec.html)
  453. * for additional information.
  454. */
  455. #define PH7_IO_OPEN_RDONLY 0x001 /* Read-only open */
  456. #define PH7_IO_OPEN_WRONLY 0x002 /* Write-only open */
  457. #define PH7_IO_OPEN_RDWR 0x004 /* Read-write open. */
  458. #define PH7_IO_OPEN_CREATE 0x008 /* If the file does not exist it will be created */
  459. #define PH7_IO_OPEN_TRUNC 0x010 /* Truncate the file to zero length */
  460. #define PH7_IO_OPEN_APPEND 0x020 /* Append mode.The file offset is positioned at the end of the file */
  461. #define PH7_IO_OPEN_EXCL 0x040 /* Ensure that this call creates the file,the file must not exist before */
  462. #define PH7_IO_OPEN_BINARY 0x080 /* Simple hint: Data is binary */
  463. #define PH7_IO_OPEN_TEMP 0x100 /* Simple hint: Temporary file */
  464. #define PH7_IO_OPEN_TEXT 0x200 /* Simple hint: Data is textual */
  465. /*
  466. * PH7 IO Stream Device.
  467. *
  468. * An instance of the ph7_io_stream object defines the interface between the PH7 core
  469. * and the underlying stream device.
  470. * A stream is a smart mechanism for generalizing file, network, data compression
  471. * and other IO operations which share a common set of functions using an abstracted
  472. * unified interface.
  473. * A stream device is additional code which tells the stream how to handle specific
  474. * protocols/encodings. For example, the http device knows how to translate a URL
  475. * into an HTTP/1.1 request for a file on a remote server.
  476. * PH7 come with two built-in IO streams device:
  477. * The file:// stream which perform very efficient disk IO and the php:// stream
  478. * which is a special stream that allow access various I/O streams (See the PHP official
  479. * documentation for more information on this stream).
  480. * A stream is referenced as: scheme://target
  481. * scheme(string) - The name of the wrapper to be used. Examples include: file,http,https,ftp,
  482. * ftps, compress.zlib, compress.bz2, and php. If no wrapper is specified,the function default
  483. * is used (typically file://).
  484. * target - Depends on the device used. For filesystem related streams this is typically a path
  485. * and filename of the desired file.For network related streams this is typically a hostname,often
  486. * with a path appended.
  487. * IO stream devices are registered using a call to ph7_vm_config() with a configuration verb
  488. * set to PH7_VM_CONFIG_IO_STREAM.
  489. * Currently the PH7 development team is working on the implementation of the http:// and ftp://
  490. * IO stream protocols. These devices will be available in the next major release of the PH7 engine.
  491. * Developers wishing to implement their own IO stream devices must understand and follow
  492. * The PH7 IO Stream C/C++ specification manual (https://ph7.symisc.net/io_stream_spec.html).
  493. */
  494. struct ph7_io_stream {
  495. const char *zName; /* Underlying stream name [i.e: file/http/zip/php,..] */
  496. int iVersion; /* IO stream structure version [default 1]*/
  497. int (*xOpen)(const char *, int, ph7_value *, void **); /* Open handle*/
  498. int (*xOpenDir)(const char *, ph7_value *, void **); /* Open directory handle */
  499. void (*xClose)(void *); /* Close file handle */
  500. void (*xCloseDir)(void *); /* Close directory handle */
  501. ph7_int64(*xRead)(void *, void *, ph7_int64); /* Read from the open stream */
  502. int (*xReadDir)(void *, ph7_context *); /* Read entry from directory handle */
  503. ph7_int64(*xWrite)(void *, const void *, ph7_int64); /* Write to the open stream */
  504. int (*xSeek)(void *, ph7_int64, int); /* Seek on the open stream */
  505. int (*xLock)(void *, int); /* Lock/Unlock the open stream */
  506. void (*xRewindDir)(void *); /* Rewind directory handle */
  507. ph7_int64(*xTell)(void *); /* Current position of the stream read/write pointer */
  508. int (*xTrunc)(void *, ph7_int64); /* Truncates the open stream to a given length */
  509. int (*xSync)(void *); /* Flush open stream data */
  510. int (*xStat)(void *, ph7_value *, ph7_value *); /* Stat an open stream handle */
  511. };
  512. /*
  513. * C-API-REF: Please refer to the official documentation for interfaces
  514. * purpose and expected parameters.
  515. */
  516. /* Engine Handling Interfaces */
  517. PH7_APIEXPORT int ph7_init(ph7 **ppEngine);
  518. PH7_APIEXPORT int ph7_config(ph7 *pEngine, int nConfigOp, ...);
  519. PH7_APIEXPORT int ph7_release(ph7 *pEngine);
  520. PH7_APIEXPORT int ph7_vm_init(ph7 *pEngine, ph7_vm **ppOutVm, int bDebug);
  521. /* Compile Interfaces */
  522. PH7_APIEXPORT int ph7_compile_code(ph7 *pEngine, const char *zSource, int nLen, ph7_vm **ppOutVm);
  523. PH7_APIEXPORT int ph7_compile_file(ph7 *pEngine, const char *zFilePath, ph7_vm **ppOutVm);
  524. /* Virtual Machine Handling Interfaces */
  525. PH7_APIEXPORT int ph7_vm_config(ph7_vm *pVm, int iConfigOp, ...);
  526. PH7_APIEXPORT int ph7_vm_exec(ph7_vm *pVm, int *pExitStatus);
  527. PH7_APIEXPORT int ph7_vm_reset(ph7_vm *pVm);
  528. PH7_APIEXPORT int ph7_vm_release(ph7_vm *pVm);
  529. PH7_APIEXPORT int ph7_vm_dump(ph7_vm *pVm, int (*xConsumer)(const void *, unsigned int, void *), void *pUserData);
  530. /* In-process Extending Interfaces */
  531. PH7_APIEXPORT int ph7_create_function(ph7_vm *pVm, const char *zName, int (*xFunc)(ph7_context *, int, ph7_value **), void *pUserData);
  532. PH7_APIEXPORT int ph7_delete_function(ph7_vm *pVm, const char *zName);
  533. PH7_APIEXPORT int ph7_create_constant(ph7_vm *pVm, const char *zName, void (*xExpand)(ph7_value *, void *), void *pUserData);
  534. PH7_APIEXPORT int ph7_delete_constant(ph7_vm *pVm, const char *zName);
  535. /* Foreign Function Parameter Values */
  536. PH7_APIEXPORT int ph7_value_to_int(ph7_value *pValue);
  537. PH7_APIEXPORT int ph7_value_to_bool(ph7_value *pValue);
  538. PH7_APIEXPORT ph7_int64 ph7_value_to_int64(ph7_value *pValue);
  539. PH7_APIEXPORT double ph7_value_to_double(ph7_value *pValue);
  540. PH7_APIEXPORT const char *ph7_value_to_string(ph7_value *pValue, int *pLen);
  541. PH7_APIEXPORT void *ph7_value_to_resource(ph7_value *pValue);
  542. PH7_APIEXPORT int ph7_value_compare(ph7_value *pLeft, ph7_value *pRight, int bStrict);
  543. /* Setting The Result Of A Foreign Function */
  544. PH7_APIEXPORT int ph7_result_int(ph7_context *pCtx, int iValue);
  545. PH7_APIEXPORT int ph7_result_int64(ph7_context *pCtx, ph7_int64 iValue);
  546. PH7_APIEXPORT int ph7_result_bool(ph7_context *pCtx, int iBool);
  547. PH7_APIEXPORT int ph7_result_double(ph7_context *pCtx, double Value);
  548. PH7_APIEXPORT int ph7_result_null(ph7_context *pCtx);
  549. PH7_APIEXPORT int ph7_result_string(ph7_context *pCtx, const char *zString, int nLen);
  550. PH7_APIEXPORT int ph7_result_string_format(ph7_context *pCtx, const char *zFormat, ...);
  551. PH7_APIEXPORT int ph7_result_value(ph7_context *pCtx, ph7_value *pValue);
  552. PH7_APIEXPORT int ph7_result_resource(ph7_context *pCtx, void *pUserData);
  553. /* Call Context Handling Interfaces */
  554. PH7_APIEXPORT int ph7_context_output(ph7_context *pCtx, const char *zString, int nLen);
  555. PH7_APIEXPORT int ph7_context_output_format(ph7_context *pCtx, const char *zFormat, ...);
  556. PH7_APIEXPORT unsigned int ph7_context_random_num(ph7_context *pCtx);
  557. PH7_APIEXPORT int ph7_context_random_string(ph7_context *pCtx, char *zBuf, int nBuflen);
  558. PH7_APIEXPORT void *ph7_context_user_data(ph7_context *pCtx);
  559. PH7_APIEXPORT int ph7_context_push_aux_data(ph7_context *pCtx, void *pUserData);
  560. PH7_APIEXPORT void *ph7_context_peek_aux_data(ph7_context *pCtx);
  561. PH7_APIEXPORT void *ph7_context_pop_aux_data(ph7_context *pCtx);
  562. PH7_APIEXPORT unsigned int ph7_context_result_buf_length(ph7_context *pCtx);
  563. PH7_APIEXPORT const char *ph7_function_name(ph7_context *pCtx);
  564. /* Call Context Memory Management Interfaces */
  565. PH7_APIEXPORT void *ph7_context_alloc_chunk(ph7_context *pCtx, unsigned int nByte, int ZeroChunk, int AutoRelease);
  566. PH7_APIEXPORT void *ph7_context_realloc_chunk(ph7_context *pCtx, void *pChunk, unsigned int nByte);
  567. PH7_APIEXPORT void ph7_context_free_chunk(ph7_context *pCtx, void *pChunk);
  568. /* On Demand Dynamically Typed Value Object allocation interfaces */
  569. PH7_APIEXPORT ph7_value *ph7_new_scalar(ph7_vm *pVm);
  570. PH7_APIEXPORT ph7_value *ph7_new_array(ph7_vm *pVm);
  571. PH7_APIEXPORT int ph7_release_value(ph7_vm *pVm, ph7_value *pValue);
  572. PH7_APIEXPORT ph7_value *ph7_context_new_scalar(ph7_context *pCtx);
  573. PH7_APIEXPORT ph7_value *ph7_context_new_array(ph7_context *pCtx);
  574. PH7_APIEXPORT void ph7_context_release_value(ph7_context *pCtx, ph7_value *pValue);
  575. /* Dynamically Typed Value Object Management Interfaces */
  576. PH7_APIEXPORT int ph7_value_int(ph7_value *pVal, int iValue);
  577. PH7_APIEXPORT int ph7_value_int64(ph7_value *pVal, ph7_int64 iValue);
  578. PH7_APIEXPORT int ph7_value_bool(ph7_value *pVal, int iBool);
  579. PH7_APIEXPORT int ph7_value_double(ph7_value *pVal, double Value);
  580. PH7_APIEXPORT int ph7_value_string(ph7_value *pVal, const char *zString, int nLen);
  581. PH7_APIEXPORT int ph7_value_string_format(ph7_value *pVal, const char *zFormat, ...);
  582. PH7_APIEXPORT int ph7_value_reset_string_cursor(ph7_value *pVal);
  583. PH7_APIEXPORT int ph7_value_resource(ph7_value *pVal, void *pUserData);
  584. PH7_APIEXPORT int ph7_value_release(ph7_value *pVal);
  585. PH7_APIEXPORT int ph7_value_void(ph7_value *pVal);
  586. PH7_APIEXPORT ph7_value *ph7_array_fetch(ph7_value *pArray, const char *zKey, int nByte);
  587. PH7_APIEXPORT int ph7_array_walk(ph7_value *pArray, int (*xWalk)(ph7_value *, ph7_value *, void *), void *pUserData);
  588. PH7_APIEXPORT int ph7_array_add_elem(ph7_value *pArray, ph7_value *pKey, ph7_value *pValue);
  589. PH7_APIEXPORT int ph7_array_add_strkey_elem(ph7_value *pArray, const char *zKey, ph7_value *pValue);
  590. PH7_APIEXPORT int ph7_array_add_intkey_elem(ph7_value *pArray, int iKey, ph7_value *pValue);
  591. PH7_APIEXPORT unsigned int ph7_array_count(ph7_value *pArray);
  592. PH7_APIEXPORT int ph7_object_walk(ph7_value *pObject, int (*xWalk)(const char *, ph7_value *, void *), void *pUserData);
  593. PH7_APIEXPORT ph7_value *ph7_object_fetch_attr(ph7_value *pObject, const char *zAttr);
  594. PH7_APIEXPORT const char *ph7_object_get_class_name(ph7_value *pObject, int *pLength);
  595. PH7_APIEXPORT int ph7_value_is_int(ph7_value *pVal);
  596. PH7_APIEXPORT int ph7_value_is_float(ph7_value *pVal);
  597. PH7_APIEXPORT int ph7_value_is_bool(ph7_value *pVal);
  598. PH7_APIEXPORT int ph7_value_is_string(ph7_value *pVal);
  599. PH7_APIEXPORT int ph7_value_is_callback(ph7_value *pVal);
  600. PH7_APIEXPORT int ph7_value_is_callable(ph7_value *pVal);
  601. PH7_APIEXPORT int ph7_value_is_array(ph7_value *pVal);
  602. PH7_APIEXPORT int ph7_value_is_numeric(ph7_value *pVal);
  603. PH7_APIEXPORT int ph7_value_is_object(ph7_value *pVal);
  604. PH7_APIEXPORT int ph7_value_is_resource(ph7_value *pVal);
  605. PH7_APIEXPORT int ph7_value_is_char(ph7_value *pVal);
  606. PH7_APIEXPORT int ph7_value_is_void(ph7_value *pVal);
  607. /* Global Library Management Interfaces */
  608. PH7_APIEXPORT int ph7_lib_init(void);
  609. PH7_APIEXPORT int ph7_lib_config(int nConfigOp, ...);
  610. PH7_APIEXPORT int ph7_lib_shutdown(void);
  611. PH7_APIEXPORT int ph7_lib_is_threadsafe(void);
  612. PH7_APIEXPORT const char *ph7_lib_version(void);
  613. PH7_APIEXPORT const char *ph7_lib_signature(void);
  614. PH7_APIEXPORT const char *ph7_lib_ident(void);
  615. PH7_APIEXPORT const char *ph7_lib_copyright(void);
  616. #endif /* _PH7_H_ */