Tanl Linguistic Pipeline |
00001 /* 00002 ** IXE 00003 ** Common/util.h 00004 ** ---------------------------------------------------------------------- 00005 ** Copyright (c) 2000 Ideare SpA. All rights reserved. 00006 ** Copyright (c) 2000 Giuseppe Attardi (attardi@di.unipi.it). 00007 ** ---------------------------------------------------------------------- 00008 ** 00009 ** This file is part of IXE. 00010 ** 00011 ** IXE is free software; you can redistribute it and/or modify it 00012 ** under the terms of the GNU General Public License, version 3, 00013 ** as published by the Free Software Foundation. 00014 ** 00015 ** IXE is distributed in the hope that it will be useful, 00016 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 ** GNU General Public License for more details. 00019 ** 00020 ** You should have received a copy of the GNU General Public License 00021 ** along with this program. If not, see <http://www.gnu.org/licenses/>. 00022 ** ---------------------------------------------------------------------- 00023 */ 00024 00025 #ifndef IXE_util_H 00026 #define IXE_util_H 00027 00028 // Settings 00029 #include "platform.h" 00030 00031 // local 00032 #include "include/ixe.h" 00033 #include "text/less.h" 00034 00035 // standard 00036 #include <cctype> 00037 #include <cerrno> 00038 #include <climits> 00039 #include <cstring> 00040 #include <map> 00041 00042 // to avoid including WinSock2.h here, we introduce Timeval, 00043 // or else timeval will become ambiguous (in IXE and global namespaces) 00044 typedef struct timeval Timeval; 00045 00046 // From RFC 2616: 00047 // http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.2 00048 // 00049 // The HTTP protocol does not place any a priori limit on the length of a URI. 00050 // Servers MUST be able to handle the URI of any resource they serve, and 00051 // SHOULD be able to handle URIs of unbounded length if they provide GET-based 00052 // forms that could generate such URIs. A server SHOULD return 414 (Request-URI 00053 // Too Long) status if a URI is longer than the server can handle (see section 00054 // 10.4.15). 00055 00056 // However, from 00057 // http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/Q208/4/27.ASP&NoWebContent=1 00058 // 00059 // Internet Explorer has a maximum uniform resource locator (URL) length of 00060 // 2,083 characters, with a maximum path length of 2,048 characters. 00061 // This limit applies to both POST and GET request URLs. 00062 00063 // Max length for a URL 00064 #define URL_MAX 2*2048 00065 00066 namespace IXE { 00067 00086 #ifdef _SYS_RESOURCE_H 00087 template <class T> 00088 rlim_t max_out_limit(T resource) 00089 { 00090 struct rlimit r; 00091 ::getrlimit(resource, &r); 00092 r.rlim_cur = r.rlim_max; 00093 ::setrlimit(resource, &r); 00094 return r.rlim_max; 00095 } 00096 #endif 00097 00098 //============================================================================= 00099 00100 struct FileAction { 00101 virtual void operator() (char const* pathname) = 0; 00102 }; 00103 00107 void mapDir(char const* pathname, FileAction& action, 00108 bool recurse_subdirectories = true, bool follow_symbolic_links = true, 00109 int verbosity = 0); 00110 00111 //============================================================================= 00117 //============================================================================= 00118 00119 #define FOR_EACH(T, C, I) \ 00120 for (T::const_iterator I = (C).begin(); I != (C).end(); ++I) 00121 00122 #define TO_EACH(T, C, I) \ 00123 for (T::iterator I = (C).begin(); I != (C).end(); ++I) 00124 00125 #define TRANSFORM_EACH(T, C, I) \ 00126 for (T::iterator I = (C).begin(); I != (C).end(); ++I) 00127 00128 int url_decode(char* dest, char const* src, int len = 0); 00129 char* url_encode(char const* s); 00130 int url_encode(char* dst, char const* s); 00131 void reverseURLdomain(char* revDomain, char const* url, Size len); 00132 void unreverseURLdomain(char* domain, char const* revDomain); 00133 Size availableMemory(); 00134 void cgi_parse(std::map<char const*, char const*>& keyMap, char* qstart); 00135 00136 00137 // pad file to align 00138 #ifdef BYTE_ALIGN 00139 #define PAD_FILE(o, size) 00140 #else 00141 #define PAD_FILE(o, size) \ 00142 { int pad = (size - (o.tellp() % size)) % size; \ 00143 if (pad) { const long z = 0; \ 00144 o.write(reinterpret_cast<const char*>(&z), pad); } } 00145 #endif 00146 00147 } // namespace IXE 00148 00149 #endif /* IXE_util_H */