1 /* 2 +----------------------------------------------------------------------+ 3 | Copyright (c) The PHP Group | 4 +----------------------------------------------------------------------+ 5 | This source file is subject to version 3.01 of the PHP license, | 6 | that is bundled with this package in the file LICENSE, and is | 7 | available through the world-wide-web at the following url: | 8 | http://www.php.net/license/3_01.txt | 9 | If you did not receive a copy of the PHP license and are unable to | 10 | obtain it through the world-wide-web, please send a note to | 11 | license@php.net so we can mail you a copy immediately. | 12 +----------------------------------------------------------------------+ 13 | Author: Israel Ekpo <iekpo@php.net> | 14 +----------------------------------------------------------------------+ 15 */ 16 17 #ifndef SOLR_STRING_H 18 #define SOLR_STRING_H 19 20 #include <main/php.h> 21 #include <Zend/zend_alloc.h> 22 23 #define SOLR_STRING_PERSISTENT 0 24 #define SOLR_STRING_START_SIZE 64 25 #define SOLR_STRING_INCREMENT_SIZE 128 26 27 #define SOLR_STRING_LONG_BUFFER_SIZE 16 28 #define SOLR_STRING_UNSIGNED_LONG_BUFFER_SIZE 32 29 30 #include "php_solr_api.h" 31 32 #ifdef SOLR_DEBUG 33 /* #define SOLR_MEM_DEBUG 1 Uncomment if you need memdebug enabled */ 34 #endif 35 36 #ifdef SOLR_MEM_DEBUG 37 38 #define SOLR_MEM_DEBUG_DC , const char * mm_function, char * mm_filename, int mm_line 39 #define SOLR_MEM_DEBUG_CC , mm_function, mm_filename, mm_line 40 #define SOLR_MEM_DEBUG_RC , __func__, __FILE__, __LINE__ 41 42 #else 43 44 #define SOLR_MEM_DEBUG_DC 45 #define SOLR_MEM_DEBUG_CC 46 #define SOLR_MEM_DEBUG_RC 47 48 #endif 49 50 /** 51 * solr_char_t 52 * 53 * iekpo 2009/08/28 54 * 55 * Decided to create this type just in case there is a special need in the 56 * future to use unsigned char instead of plain char to transport character 57 * arrays within the library. 58 * 59 * Having this typedef will allow us to toggle easily between plain char and 60 * unsigned char, without having to do a massive search and replace. 61 * 62 * There may be a few cases where casting may be needed to handle cases where 63 * the sign of the variable is now the opposite. 64 */ 65 typedef char solr_char_t; 66 67 /* Structure to store solr strings */ 68 typedef struct _solr_string { 69 70 solr_char_t *str; /* The buffer to store the character array. */ 71 72 size_t len; /* The current length of the solr_string_t object */ 73 74 size_t cap; /* The current capacity of the solr_string_t object */ 75 76 } solr_string_t; 77 78 #define SOLR_STRING_INITIALIZER {.str = ((solr_char_t *)0), .len = 0U, .cap = 0U} 79 80 /* Appends a string constant to a solr_string_t */ 81 #define solr_string_append_const(dest, str) solr_string_appends((dest), (solr_char_t *) str, sizeof(str)-1) 82 83 /* Appends one solr_string_t to another */ 84 #define solr_string_append_solr_string(dest, src) solr_string_appends((dest), (src)->str, (src)->len) 85 86 /* Initializes the solr_string_t structure to empty values */ 87 #define solr_string_init(dest) \ 88 { \ 89 (dest)->str = (solr_char_t *) 0x00; \ 90 (dest)->len = 0U; \ 91 (dest)->cap = 0U; \ 92 } 93 94 #define solr_strndup estrndup 95 96 #define solr_strdup estrdup 97 98 #define solr_strlen strlen 99 100 #define solr_string_appends(dest, src, len) solr_string_appends_ex((dest), (src), (len) SOLR_MEM_DEBUG_RC) 101 102 #define solr_string_appendc(dest, ch) solr_string_appendc_ex((dest), (ch) SOLR_MEM_DEBUG_RC) 103 104 #define solr_string_append_long(dest, long_val) solr_string_append_long_ex((dest), (long_val) SOLR_MEM_DEBUG_RC) 105 106 #define solr_string_append_unsigned_long(dest, long_val) solr_string_append_unsigned_long((dest), (long_val) SOLR_MEM_DEBUG_RC) 107 108 #define solr_string_set(dest, value, length) solr_string_set_ex((dest), (value), (length) SOLR_MEM_DEBUG_RC) 109 110 #define solr_string_free(dest) solr_string_free_ex((dest) SOLR_MEM_DEBUG_RC) 111 112 PHP_SOLR_API void solr_string_appends_ex(solr_string_t *dest, const solr_char_t *src, size_t length SOLR_MEM_DEBUG_DC); 113 114 PHP_SOLR_API void solr_string_appendc_ex(solr_string_t *dest, solr_char_t ch SOLR_MEM_DEBUG_DC); 115 116 PHP_SOLR_API void solr_string_append_long_ex(solr_string_t *dest, long int long_val SOLR_MEM_DEBUG_DC); 117 118 PHP_SOLR_API void solr_string_append_unsigned_long_ex(solr_string_t *dest, unsigned long int long_val SOLR_MEM_DEBUG_DC); 119 120 PHP_SOLR_API void solr_string_remove_last_char(solr_string_t *dest); 121 122 PHP_SOLR_API int solr_string_equal(const solr_string_t *a, const solr_string_t *b); 123 124 PHP_SOLR_API void solr_destory_solr_string_zv(zval *solr_string_zv); 125 126 PHP_SOLR_API void solr_string_free_ex(solr_string_t *dest SOLR_MEM_DEBUG_DC); 127 128 PHP_SOLR_API void solr_string_set_ex(solr_string_t *dest, const solr_char_t *value, size_t length SOLR_MEM_DEBUG_DC); 129 130 /* destroy data element of hashtable of solr_string_t */ 131 #ifdef PHP_7 132 #define solr_destroy_solr_string solr_destory_solr_string_zv /* frees a solr_string_t within a zval */ 133 #else 134 #define solr_destroy_solr_string solr_string_free 135 #endif 136 137 #endif /* SOLR_STRING_H */ 138 139 /* 140 * Local variables: 141 * tab-width: 4 142 * c-basic-offset: 4 143 * End: 144 * vim600: fdm=marker 145 * vim: noet sw=4 ts=4 146 */ 147