📄 mpr.h
字号:
/* * @file mpr.h * @brief Header for the Mbedthis Portable Runtime (MPR) Base. * @copy default * * Copyright (c) Mbedthis Software LLC, 2003-2006. All Rights Reserved. * * This software is distributed under commercial and open source licenses. * You may use the GPL open source license described below or you may acquire * a commercial license from Mbedthis Software. You agree to be fully bound * by the terms of either license. Consult the LICENSE.TXT distributed with * this software for full details. * * This software is open source; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the License, or (at your * option) any later version. See the GNU General Public License for more * details at: http://www.mbedthis.com/downloads/gplLicense.html * * This program is distributed WITHOUT ANY WARRANTY; without even the * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * This GPL license does NOT permit incorporating this software into * proprietary programs. If you are unable to comply with the GPL, you must * acquire a commercial license to use this software. Commercial licenses * for this software and support services are available from Mbedthis * Software at http://www.mbedthis.com * * @end *//******************************* Documentation ********************************//* * See mpr.dox for additional documentation. *//******************************************************************************/#ifndef _h_MPR#define _h_MPR 1/***********************************Includes **********************************/#include "mprOs.h"/******************************************************************************/#ifdef __cplusplusextern "C" {#endif/********************************** Constants *********************************/#if BLD_FEATURE_SQUEEZE#if BREW || DOXYGEN/* * Maximum length of a file path name. Reduced from the system maximum to * save memory space. */#define MPR_MAX_FNAME 64 /**< Reasonable filename size */#define MPR_MAX_PATH 64 /**< Reasonable path name size */#define MPR_DEFAULT_STACK (16 * 1024) /**< Default stack size */#else#define MPR_MAX_FNAME 128 /**< Reasonable filename size */#define MPR_MAX_PATH 256 /**< Reasonable path name size */#define MPR_DEFAULT_STACK (32 * 1024) /**< Default stack size */#endif/* * Reasonable length of a file name used by the product. Use where you know * the expected file name and it is certain to be less than this limit. */#define MPR_DEFAULT_ALLOC 64 /**< Default small alloc size */#define MPR_DEFAULT_HASH_SIZE 23 /**< Default size of hash table */ #define MPR_MAX_ARGC 32 /**< Reasonable max of args */#define MPR_MAX_STRING 512 /**< Maximum (stack) string size */#define MPR_MAX_LOG_STRING 512 /**< Maximum log message */#define MPR_MAX_URL 256 /**< Reasonable size of a URL */#define MPR_BUFSIZE 512 /**< Reasonable size for buffers */#define MPR_SLAB_STR_MAX 32 /**< Size of string slab blocks */#define MPR_SLAB_STR_INC 32 /**< Pre-allocate increment */#define MPR_SLAB_DEFAULT_INC 8 /**< Default pre-allocate inc */#define MPR_ARRAY_INCR 8 /**< Default array growth inc */#define MPR_BUF_INCR 1024 /**< Default array growth inc */#define MPR_MAX_BUF (1024*4096) /**< Default array growth inc */#define MPR_BLK_HDR_SIZE ((sizeof(struct MprBlk) + 3) & ~3)#else#define MPR_MAX_FNAME 256#define MPR_MAX_PATH 1024#define MPR_DEFAULT_ALLOC 256#define MPR_DEFAULT_HASH_SIZE 43#define MPR_DEFAULT_STACK (64 * 1024)#define MPR_MAX_ARGC 128#define MPR_MAX_STRING 4096#define MPR_MAX_LOG_STRING 8192#define MPR_MAX_URL 1024#define MPR_BUFSIZE 1024#define MPR_SLAB_STR_MAX 32#define MPR_SLAB_STR_INC 64#define MPR_SLAB_DEFAULT_INC 16#define MPR_ARRAY_INCR 16#define MPR_BUF_INCR 1024#define MPR_MAX_BUF (1024*4096)#define MPR_BLK_HDR_SIZE ((sizeof(struct MprBlk) + 15) & ~15)#endif/** * Maximum size of a host name string */#define MPR_MAX_IP_NAME 64/** * Maximum size of an IP address */#define MPR_MAX_IP_ADDR 16/** * Maximum size of an IP address including port number */#define MPR_MAX_IP_ADDR_PORT 32#define MPR_MAX_SLAB 16 /* Slabs from 32-512 bytes */#define MPR_MAX_TIME_SYNC (10 * 1000) /* Time sync adjustments *//** * @overview Memory context type * @description Blocks of memory are allocated using a memory context * as the parent with the \ref MprApp structure being the root of the * tree. Any allocated memory block may serve as the memory context for * subsequent memory allocations. Freeing a block via \ref mprFree will * release the allocated block and all child blocks. * @stability Prototype. * @library libmpr. * @see mprInit, mprAlloc, mprFree */typedef const void *MprCtx;/* * Allocated memory destructor type */typedef int (*MprDestructor)(void *);/******************************** Error Codes *********************************//* * Standard MPR return and error codes */#define MPR_ERR_OK (0) /**< Success */#define MPR_ERR_BASE (-200)/**< Base error code */#define MPR_ERR_GENERAL (MPR_ERR_BASE - 1) /**< General error */#define MPR_ERR_ABORTED (MPR_ERR_BASE - 2) /**< Action aborted */#define MPR_ERR_ALREADY_EXISTS (MPR_ERR_BASE - 3) /**< Item already exists */#define MPR_ERR_BAD_ARGS (MPR_ERR_BASE - 4) /**< Bad arguments or paramaeters */#define MPR_ERR_BAD_FORMAT (MPR_ERR_BASE - 5) /**< Bad input format */#define MPR_ERR_BAD_HANDLE (MPR_ERR_BASE - 6) #define MPR_ERR_BAD_STATE (MPR_ERR_BASE - 7) /**< Module is in a bad state */#define MPR_ERR_BAD_SYNTAX (MPR_ERR_BASE - 8) /**< Input has bad syntax */#define MPR_ERR_BAD_TYPE (MPR_ERR_BASE - 9) #define MPR_ERR_BAD_VALUE (MPR_ERR_BASE - 10) #define MPR_ERR_BUSY (MPR_ERR_BASE - 11) #define MPR_ERR_CANT_ACCESS (MPR_ERR_BASE - 12) /**< Can't access the file or resource */#define MPR_ERR_CANT_COMPLETE (MPR_ERR_BASE - 13) #define MPR_ERR_CANT_CREATE (MPR_ERR_BASE - 14) /**< Can't create the file or resource */#define MPR_ERR_CANT_INITIALIZE (MPR_ERR_BASE - 15) #define MPR_ERR_CANT_OPEN (MPR_ERR_BASE - 16) /**< Can't open the file or resource */#define MPR_ERR_CANT_READ (MPR_ERR_BASE - 17) /**< Can't read from the file or resource */#define MPR_ERR_CANT_WRITE (MPR_ERR_BASE - 18) /**< Can't write to the file or resource */#define MPR_ERR_DELETED (MPR_ERR_BASE - 19) #define MPR_ERR_NETWORK (MPR_ERR_BASE - 20) #define MPR_ERR_NOT_FOUND (MPR_ERR_BASE - 21) #define MPR_ERR_NOT_INITIALIZED (MPR_ERR_BASE - 22) /**< Module or resource is not initialized */#define MPR_ERR_NOT_READY (MPR_ERR_BASE - 23) #define MPR_ERR_READ_ONLY (MPR_ERR_BASE - 24) /**< The operation timed out */#define MPR_ERR_TIMEOUT (MPR_ERR_BASE - 25) #define MPR_ERR_TOO_MANY (MPR_ERR_BASE - 26) #define MPR_ERR_WONT_FIT (MPR_ERR_BASE - 27) #define MPR_ERR_WOULD_BLOCK (MPR_ERR_BASE - 28) #define MPR_ERR_CANT_ALLOCATE (MPR_ERR_BASE - 29) // MOB -- rename NO_MEMORY#define MPR_ERR_MEMORY (MPR_ERR_BASE - 30) #define MPR_ERR_CANT_DELETE (MPR_ERR_BASE - 31) #define MPR_ERR_MAX (MPR_ERR_BASE - 32) /* * Standard logging trace levels are 0 to 9 with 0 being the most verbose. * the These are ored with the error source and type flags. The MPR_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 MPR_ERROR 1 /**< Hard error trace level */#define MPR_WARN 2 /**< Soft warning trace level */#define MPR_CONFIG 2 /**< Configuration settings trace level. */#define MPR_INFO 3 /**< Informational trace only */#define MPR_DEBUG 4 /**< Debug information trace level */#define MPR_VERBOSE 9 /**< Highest level of trace */#define MPR_LEVEL_MASK 0xf /**< Level mask *//* * Error source flags */#define MPR_ERROR_SRC 0x10 /**< Originated from mprError */#define MPR_LOG_SRC 0x20 /**< Originated from mprLog */#define MPR_ASSERT_SRC 0x40 /**< Originated from mprAssert */#define MPR_FATAL_SRC 0x80 /**< Fatal error. Log and exit *//* * Log message type flags. Specify what kind of log / error message it is. * Listener handlers examine this flag to determine if they should process * the message.Assert messages are trapped when in DEV mode. Otherwise ignored. */#define MPR_LOG_MSG 0x100 /**< Log trace message - not an error */#define MPR_ERROR_MSG 0x200 /**< General error */#define MPR_ASSERT_MSG 0x400 /**< Assert flags -- trap in debugger */#define MPR_USER_MSG 0x800 /**< User message *//* * Log output modifiers */#define MPR_RAW 0x1000 /**< Raw trace output *//* * Error line number information. */#define MPR_LINE(s) #s#define MPR_LINE2(s) MPR_LINE(s)#define MPR_LINE3 MPR_LINE2(__LINE__)#define MPR_LOC __FILE__ ":" MPR_LINE3/* * Macros to pass file and line number information * Use MPR_LOC_ARGS in normal user code. * Use MPR_LOC_DEC in declarations. * Use MPR_LOC_PASS in layered APIs to pass original line info down. */#if BLD_FEATURE_ALLOC_LEAK_TRACK#define MPR_LOC_ARGS(ctx) ctx, MPR_LOC#define MPR_LOC_DEC(ctx, loc) MprCtx ctx, const char *loc#define MPR_LOC_PASS(ctx, loc) ctx, loc#else#define MPR_LOC_ARGS(ctx) ctx#define MPR_LOC_DEC(ctx, loc) MprCtx ctx #define MPR_LOC_PASS(ctx, loc) ctx#endif/******************************* Debug and Assert *****************************/extern void mprBreakpoint(const char *loc, const char *msg);#if BLD_FEATURE_ASSERT #define mprAssert(C) if (C) ; else mprStaticAssert(MPR_LOC, #C)#else #define mprAssert(C) if (1) ; else#endif/********************************* Safe Strings *******************************//* * Unsafe functions that should not be used. Define UNSAFE_STRINGS_OK before * including mpr.h if you really want to use these functions. A better approach * is to undefine them just prior to using them in your C/C++ source file. */#if BLD_FEATURE_SAFE_STRINGS#if BLD_FEATURE_PHP4_MODULE || BLD_FEATURE_PHP5_MODULE #ifndef UNSAFE_FUNCTIONS_OK #define UNSAFE_FUNCTIONS_OK 1 #endif#endif#ifndef UNSAFE_FUNCTIONS_OK #define sprintf UseMprSprintfInstead #define fprintf UseMprFprintfInstead #define vsprintf UseMprVsprintfInstead #define strtok UseMprStrTokInstead #define gethostbyname UseMprGetHostByNameInstead #define ctime UseMprCtimeInstead #define asctime UseMprAsctimeInstead #define localtime UseMprLocaltimeInstead #define gmtime UseMprGmtimeInstead #define malloc UseMprMallocInstead #define free UseMprFreeInstead #define realloc UseMprReallocInstead #define strncpy UseMprStrcpyInstead #define inet_ntoa UseMprInetToStrInstead#if !BREW #define printf UseMprPrintfInstead#endif #if FUTURE #define strlen UseMprStrlenInstead #define strcpy UseMprStrcpyInstead #endif#endif /* UNSAFE_FUNCTIONS_OK */#endif /* BLD_FEATURE_SAFE_STRINGS *//******************************************************************************/struct MprBuf;typedef int (*MprBufProc)(struct MprBuf* bp, void *arg);/** * @overview Dynamic buffer structure * @description MprBuf is a flexible, dynamic growable buffer structure. It * utilizes a ring buffer mechanism and is suitable for high performance * buffering in a variety of situations. * @stability Prototype. * @library libmpr. * @see mprCreateBuf, mprFree, MprArray */typedef struct MprBuf { uchar *buf; /* Actual buffer for data */ uchar *endbuf; /* Pointer one past the end of buffer */ uchar *start; /* Pointer to next data char */ uchar *end; /* Pointer one past the last data chr */ int buflen; /* Current size of buffer */ int maxsize; /* Max size the buffer can ever grow */ int growBy; /* Next growth increment to use */ MprBufProc refillProc; /* Auto-refill procedure */ void *refillArg; /* Refill arg */} MprBuf;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -