Annotation of parser3/src/include/pa_common.h, revision 1.97
1.15 paf 1: /** @file
1.16 paf 2: Parser: commonly used functions.
3:
1.93 paf 4: Copyright (c) 2001-2003 ArtLebedev Group (http://www.artlebedev.com)
1.74 paf 5: Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.1 paf 6: */
7:
8: #ifndef PA_COMMON_H
9: #define PA_COMMON_H
1.78 paf 10:
1.97 ! paf 11: static const char * const IDENT_COMMON_H="$Date: 2003/11/10 06:51:06 $";
1.1 paf 12:
1.33 paf 13: #include "pa_string.h"
1.93 paf 14: #include "pa_hash.h"
1.1 paf 15:
1.87 paf 16: class Value;
1.94 paf 17: typedef Hash<const String::Body , Value*> HashStringValue;
1.64 paf 18:
19: // replace system s*nprintf with our versions
1.69 paf 20: #undef vsnprintf
1.93 paf 21: int __vsnprintf(char *, size_t, const char* , va_list);
1.64 paf 22: #define vsnprintf __vsnprintf
23: #undef snprintf
1.93 paf 24: int __snprintf(char *, size_t, const char* , ...);
1.64 paf 25: #define snprintf __snprintf
1.63 paf 26:
1.21 paf 27: #if _MSC_VER
1.56 paf 28: /*
1.93 paf 29: inline int open( const char* filename, int oflag ) { return _open(filename, oflag); }
1.56 paf 30: inline int close( int handle ) { return _close(handle); }
31: inline int read( int handle, void *buffer, unsigned int count ) { return _read(handle,buffer,count); }
32: inline int write( int handle, const void *buffer, unsigned int count ) { return _write(handle,buffer,count); }
1.93 paf 33: inline int stat( const char* path, struct _stat *buffer ) { return _stat(path, buffer); }
1.56 paf 34: inline long lseek( int handle, long offset, int origin ) { return _lseek(handle, offset, origin); }
35: */
1.17 paf 36:
37: //access
38: #define F_OK 0
39: #define X_OK 1
40: #define W_OK 2
41: #define R_OK 4
42:
1.20 paf 43: #ifndef strcasecmp
44: # define strcasecmp _stricmp
45: #endif
46: #ifndef strncasecmp
47: # define strncasecmp _strnicmp
48: #endif
49: #ifndef mkdir
50: # define mkdir(path, mode) _mkdir(path)
51: #endif
1.17 paf 52:
1.20 paf 53: #ifndef putenv
54: # define putenv _putenv
1.1 paf 55: #endif
1.2 paf 56:
1.17 paf 57: #endif
1.59 paf 58:
1.54 parser 59: /** under WIN32 "t" mode fixes DOS chars OK,
60: can't say that about other systems/ line break styles
61: */
1.57 paf 62: void fix_line_breaks(
1.93 paf 63: char *str,
64: size_t& length///< may change! used to speedup next actions
65: );
1.95 paf 66:
67: int pa_lock_shared_blocking(int fd);
68: int pa_lock_exclusive_blocking(int fd);
69: int pa_lock_exclusive_nonblocking(int fd);
70: int pa_unlock(int fd);
1.93 paf 71:
72: typedef void (*File_read_action)(
73: struct stat& finfo,
74: int f,
75: const String& file_spec, const char* fname, bool as_text,
76: void *context);
1.83 paf 77:
78: /**
79: shared-lock specified file,
80: do actions under lock.
81: if fail_on_read_problem is true[default] throws an exception
82:
83: @returns true if read OK
84: */
1.93 paf 85: bool file_read_action_under_lock(const String& file_spec,
86: const char* action_name, File_read_action action, void *context,
1.83 paf 87: bool as_text=false,
88: bool fail_on_read_problem=true);
1.15 paf 89: /**
1.93 paf 90: read specified text file using
1.15 paf 91: if fail_on_read_problem is true[default] throws an exception
1.83 paf 92:
1.93 paf 93: WARNING: charset is used for http header case conversion, it's not a charset of input file!
94:
1.83 paf 95: @returns true if read OK
1.15 paf 96: */
1.93 paf 97: char *file_read_text(Request_charsets& charsets,
1.25 paf 98: const String& file_spec,
1.85 paf 99: bool fail_on_read_problem=true,
1.93 paf 100: HashStringValue* options=0/*, HashStringValue* * out_fields=0*/);
101:
102: struct File_read_result {
103: bool success;
104: char* str; size_t length;
105: HashStringValue* headers;
106: };
1.17 paf 107:
108: /**
1.93 paf 109: read specified file using
1.29 paf 110: if fail_on_read_problem is true[default] throws an exception
1.83 paf 111:
1.93 paf 112: WARNING: charset is used for http header case conversion, it's not a charset of input file!
113:
1.83 paf 114: @returns true if read OK
1.29 paf 115: */
1.93 paf 116: File_read_result file_read(Request_charsets& charsets,
117: const String& file_spec,
1.29 paf 118: bool as_text,
1.93 paf 119: HashStringValue* options=0,
1.83 paf 120: bool fail_on_read_problem=true);
121:
122: typedef void (*File_write_action)(int f, void *context);
1.29 paf 123:
124: /**
1.71 paf 125: lock specified file exclusively,
126: do actions under lock.
127: throws an exception in case of problems
1.72 paf 128:
129: if block=false does non-blocking lock
130: @returns true if locked OK, or false if non-blocking locking failed
1.71 paf 131: */
1.72 paf 132: bool file_write_action_under_lock(
1.71 paf 133: const String& file_spec,
1.93 paf 134: const char* action_name, File_write_action action, void *context,
1.71 paf 135: bool as_text=false,
1.72 paf 136: bool do_append=false,
1.77 paf 137: bool do_block=true,
138: bool fail_on_lock_problem=true);
1.71 paf 139:
140: /**
141: write data to specified file,
1.17 paf 142: throws an exception in case of problems
143: */
1.70 paf 144: void file_write(
1.25 paf 145: const String& file_spec,
1.93 paf 146: const char* data, size_t size,
1.58 paf 147: bool as_text,
1.67 paf 148: bool do_append=false);
1.26 paf 149:
150: /**
151: delete specified file
152: throws an exception in case of problems
153: */
1.96 paf 154: bool file_delete(const String& file_spec, bool fail_on_problem=true);
1.47 parser 155: /**
156: move specified file
157: throws an exception in case of problems
158: */
1.70 paf 159: void file_move(const String& old_spec, const String& new_spec);
1.27 paf 160:
1.93 paf 161: bool entry_exists(const char* fname, struct stat *afinfo=0);
1.82 paf 162: bool entry_exists(const String& file_spec);
1.27 paf 163: bool file_readable(const String& file_spec);
1.41 paf 164: bool dir_readable(const String& file_spec);
1.93 paf 165: const String* file_readable(const String& path, const String& name);
1.36 paf 166: bool file_executable(const String& file_spec);
1.37 paf 167:
1.48 parser 168: bool file_stat(const String& file_spec,
1.46 parser 169: size_t& rsize,
170: time_t& ratime,
171: time_t& rmtime,
1.48 parser 172: time_t& rctime,
173: bool fail_on_read_problem=true);
1.15 paf 174:
175: /**
1.18 paf 176: scans for @a delim[default \n] in @a *row_ref,
177: @return piece of line before it or end of string, if no @a delim found
178: assigns @a *row_ref to point right after delimiter if there were one
179: or to zero if no @a delim were found.
1.15 paf 180: */
1.7 paf 181: char *getrow(char **row_ref,char delim='\n');
1.76 paf 182: char *lsplit(char *string, char delim);
1.7 paf 183: char *lsplit(char **string_ref,char delim);
1.8 paf 184: char *rsplit(char *string, char delim);
1.93 paf 185: const char* format(double value, char *fmt);
1.10 paf 186:
1.30 paf 187: size_t stdout_write(const void *buf, size_t size);
1.14 paf 188:
1.93 paf 189: char *unescape_chars(const char* cp, int len);
1.23 paf 190:
191: #ifdef WIN32
192: void back_slashes_to_slashes(char *s);
1.35 paf 193: //void slashes_to_back_slashes(char *s);
1.23 paf 194: #endif
195:
1.28 paf 196: #ifndef _qsort
197: # define _qsort(names,cnt,sizeof_names,func_addr) \
198: qsort(names,cnt,sizeof_names,func_addr)
199: #endif
1.34 paf 200:
1.93 paf 201: bool StrEqNc(const char* s1, const char* s2, bool strict=true);
1.45 parser 202:
203: #define SECS_PER_DAY (60*60*24)
204: int getMonthDays(int year, int month);
1.52 parser 205:
206: void remove_crlf(char *start, char *end);
1.90 paf 207:
1.93 paf 208: #ifdef PA_SAFE_MODE
209: void check_safe_mode(struct stat finfo, const String& file_spec, const char* fname);
210: #endif
211:
212: // globals
213:
214: extern const String file_status_name;
1.1 paf 215:
216: #endif
E-mail: