HTP
0.3
|
00001 /*************************************************************************** 00002 * Copyright 2009-2010 Open Information Security Foundation 00003 * Copyright 2010-2011 Qualys, Inc. 00004 * 00005 * Licensed to You under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 ***************************************************************************/ 00017 00023 #ifndef _BSTR_H 00024 #define _BSTR_H 00025 00026 typedef struct bstr_t bstr_t; 00027 typedef bstr_t bstr; 00028 00029 #include <stdio.h> 00030 #include <stdlib.h> 00031 #include <stdint.h> 00032 #include <string.h> 00033 00034 #include "bstr_builder.h" 00035 00036 #ifdef __cplusplus 00037 extern "C" { 00038 #endif 00039 00040 // IMPORTANT This binary string library is used internally by the parser and you should 00041 // not rely on it in your code. The interface and the implementation may change 00042 // without warning. 00043 00044 struct bstr_t { 00046 size_t len; 00047 00051 size_t size; 00052 00058 char *ptr; 00059 }; 00060 00061 00062 // Defines 00063 00064 #define bstr_len(X) ((*(bstr_t *)(X)).len) 00065 #define bstr_size(X) ((*(bstr_t *)(X)).size) 00066 #define bstr_ptr(X) ( ((*(bstr_t *)(X)).ptr == NULL) ? ((char *)(X) + sizeof(bstr_t)) : (char *)(*(bstr_t *)(X)).ptr ) 00067 00068 00069 // Functions 00070 00071 bstr *bstr_alloc(size_t newsize); 00072 void bstr_free(bstr **s); 00073 bstr *bstr_expand(bstr *s, size_t newsize); 00074 00075 bstr *bstr_dup(const bstr *b); 00076 bstr *bstr_dup_ex(const bstr *b, size_t offset, size_t len); 00077 bstr *bstr_dup_c(const char *); 00078 bstr *bstr_dup_mem(const char *data, size_t len); 00079 00080 bstr *bstr_dup_lower(const bstr *); 00081 00082 int bstr_chr(const bstr *, int); 00083 int bstr_rchr(const bstr *, int); 00084 00085 int bstr_cmp(const bstr *, const bstr *); 00086 int bstr_cmp_nocase(const bstr *, const bstr *); 00087 int bstr_cmp_c(const bstr *, const char *); 00088 int bstr_cmp_c_nocase(const bstr *, const char *); 00089 int bstr_cmp_ex(const char *, size_t, const char *, size_t); 00090 int bstr_cmp_nocase_ex(const char *, size_t, const char *, size_t); 00091 00092 00093 bstr *bstr_to_lowercase(bstr *); 00094 00095 bstr *bstr_add(bstr *, const bstr *); 00096 bstr *bstr_add_c(bstr *, const char *); 00097 bstr *bstr_add_mem(bstr *, const char *, size_t); 00098 00099 bstr *bstr_add_noex(bstr *, const bstr *); 00100 bstr *bstr_add_c_noex(bstr *, const char *); 00101 bstr *bstr_add_mem_noex(bstr *, const char *, size_t); 00102 00103 int bstr_index_of(const bstr *haystack, const bstr *needle); 00104 int bstr_index_of_nocase(const bstr *haystack, const bstr *needle); 00105 int bstr_index_of_c(const bstr *haystack, const char *needle); 00106 int bstr_index_of_c_nocase(const bstr *haystack, const char *needle); 00107 int bstr_index_of_mem(const bstr *haystack, const char *data, size_t len); 00108 int bstr_index_of_mem_nocase(const bstr *haystack, const char *data, size_t len); 00109 00110 int bstr_begins_with_mem(const bstr *haystack, const char *data, size_t len); 00111 int bstr_begins_with_mem_nocase(const bstr *haystack, const char *data, size_t len); 00112 int bstr_begins_with(const bstr *haystack, const bstr *needle); 00113 int bstr_begins_with_c(const bstr *haystack, const char *needle); 00114 int bstr_begins_with_nocase(const bstr *haystack, const bstr *needle); 00115 int bstr_begins_withc_nocase(const bstr *haystack, const char *needle); 00116 00117 unsigned char bstr_char_at(const bstr *s, size_t pos); 00118 00119 void bstr_chop(bstr *b); 00120 void bstr_util_adjust_len(bstr *s, size_t newlen); 00121 int64_t bstr_util_mem_to_pint(const char *data, size_t len, int base, size_t *lastlen); 00122 char *bstr_util_memdup_to_c(const char *data, size_t len); 00123 char *bstr_util_strdup_to_c(const bstr *); 00124 00125 #ifdef __cplusplus 00126 } 00127 #endif 00128 00129 #endif /* _BSTR_H */