Annotation of parser3/src/include/pa_common.h, revision 1.93
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.93 ! paf 11: static const char* IDENT_COMMON_H="$Date: 2003/04/11 16:05:43 $";
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.93 ! paf 17: typedef Hash<const StringBody , 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.72 paf 59: /// yields to OS for secs secs and usecs milliseconds
60: int pa_sleep(unsigned long secs, unsigned long usecs);
1.54 parser 61:
62: /** under WIN32 "t" mode fixes DOS chars OK,
63: can't say that about other systems/ line break styles
64: */
1.57 paf 65: void fix_line_breaks(
1.93 ! paf 66: char *str,
! 67: size_t& length///< may change! used to speedup next actions
! 68: );
! 69:
! 70: typedef void (*File_read_action)(
! 71: struct stat& finfo,
! 72: int f,
! 73: const String& file_spec, const char* fname, bool as_text,
! 74: void *context);
1.83 paf 75:
76: /**
77: shared-lock specified file,
78: do actions under lock.
79: if fail_on_read_problem is true[default] throws an exception
80:
81: @returns true if read OK
82: */
1.93 ! paf 83: bool file_read_action_under_lock(const String& file_spec,
! 84: const char* action_name, File_read_action action, void *context,
1.83 paf 85: bool as_text=false,
86: bool fail_on_read_problem=true);
1.15 paf 87: /**
1.93 ! paf 88: read specified text file using
1.15 paf 89: if fail_on_read_problem is true[default] throws an exception
1.83 paf 90:
1.93 ! paf 91: WARNING: charset is used for http header case conversion, it's not a charset of input file!
! 92:
1.83 paf 93: @returns true if read OK
1.15 paf 94: */
1.93 ! paf 95: char *file_read_text(Request_charsets& charsets,
1.25 paf 96: const String& file_spec,
1.85 paf 97: bool fail_on_read_problem=true,
1.93 ! paf 98: HashStringValue* options=0/*, HashStringValue* * out_fields=0*/);
! 99:
! 100: struct File_read_result {
! 101: bool success;
! 102: char* str; size_t length;
! 103: HashStringValue* headers;
! 104: };
1.17 paf 105:
106: /**
1.93 ! paf 107: read specified file using
1.29 paf 108: if fail_on_read_problem is true[default] throws an exception
1.83 paf 109:
1.93 ! paf 110: WARNING: charset is used for http header case conversion, it's not a charset of input file!
! 111:
1.83 paf 112: @returns true if read OK
1.29 paf 113: */
1.93 ! paf 114: File_read_result file_read(Request_charsets& charsets,
! 115: const String& file_spec,
1.29 paf 116: bool as_text,
1.93 ! paf 117: HashStringValue* options=0,
1.83 paf 118: bool fail_on_read_problem=true);
119:
120: typedef void (*File_write_action)(int f, void *context);
1.29 paf 121:
122: /**
1.71 paf 123: lock specified file exclusively,
124: do actions under lock.
125: throws an exception in case of problems
1.72 paf 126:
127: if block=false does non-blocking lock
128: @returns true if locked OK, or false if non-blocking locking failed
1.71 paf 129: */
1.72 paf 130: bool file_write_action_under_lock(
1.71 paf 131: const String& file_spec,
1.93 ! paf 132: const char* action_name, File_write_action action, void *context,
1.71 paf 133: bool as_text=false,
1.72 paf 134: bool do_append=false,
1.77 paf 135: bool do_block=true,
136: bool fail_on_lock_problem=true);
1.71 paf 137:
138: /**
139: write data to specified file,
1.17 paf 140: throws an exception in case of problems
141: */
1.70 paf 142: void file_write(
1.25 paf 143: const String& file_spec,
1.93 ! paf 144: const char* data, size_t size,
1.58 paf 145: bool as_text,
1.67 paf 146: bool do_append=false);
1.26 paf 147:
148: /**
149: delete specified file
150: throws an exception in case of problems
151: */
1.70 paf 152: bool file_delete(const String& file_spec, bool fail_on_read_problem=true);
1.47 parser 153: /**
154: move specified file
155: throws an exception in case of problems
156: */
1.70 paf 157: void file_move(const String& old_spec, const String& new_spec);
1.27 paf 158:
1.93 ! paf 159: bool entry_exists(const char* fname, struct stat *afinfo=0);
1.82 paf 160: bool entry_exists(const String& file_spec);
1.27 paf 161: bool file_readable(const String& file_spec);
1.41 paf 162: bool dir_readable(const String& file_spec);
1.93 ! paf 163: const String* file_readable(const String& path, const String& name);
1.36 paf 164: bool file_executable(const String& file_spec);
1.37 paf 165:
1.48 parser 166: bool file_stat(const String& file_spec,
1.46 parser 167: size_t& rsize,
168: time_t& ratime,
169: time_t& rmtime,
1.48 parser 170: time_t& rctime,
171: bool fail_on_read_problem=true);
1.15 paf 172:
173: /**
1.18 paf 174: scans for @a delim[default \n] in @a *row_ref,
175: @return piece of line before it or end of string, if no @a delim found
176: assigns @a *row_ref to point right after delimiter if there were one
177: or to zero if no @a delim were found.
1.15 paf 178: */
1.7 paf 179: char *getrow(char **row_ref,char delim='\n');
1.76 paf 180: char *lsplit(char *string, char delim);
1.7 paf 181: char *lsplit(char **string_ref,char delim);
1.8 paf 182: char *rsplit(char *string, char delim);
1.93 ! paf 183: const char* format(double value, char *fmt);
1.10 paf 184:
1.30 paf 185: size_t stdout_write(const void *buf, size_t size);
1.14 paf 186:
1.93 ! paf 187: char *unescape_chars(const char* cp, int len);
1.23 paf 188:
189: #ifdef WIN32
190: void back_slashes_to_slashes(char *s);
1.35 paf 191: //void slashes_to_back_slashes(char *s);
1.23 paf 192: #endif
193:
1.28 paf 194: #ifndef _qsort
195: # define _qsort(names,cnt,sizeof_names,func_addr) \
196: qsort(names,cnt,sizeof_names,func_addr)
197: #endif
1.34 paf 198:
1.93 ! paf 199: bool StrEqNc(const char* s1, const char* s2, bool strict=true);
1.45 parser 200:
201: #define SECS_PER_DAY (60*60*24)
202: int getMonthDays(int year, int month);
1.52 parser 203:
204: void remove_crlf(char *start, char *end);
1.90 paf 205:
1.93 ! paf 206: #ifdef PA_SAFE_MODE
! 207: void check_safe_mode(struct stat finfo, const String& file_spec, const char* fname);
! 208: #endif
! 209:
! 210: // globals
! 211:
! 212: extern const String file_status_name;
1.1 paf 213:
214: #endif
E-mail: