00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef _URL_H
00014 #define _URL_H
00015
00021 #include <support/String.h>
00022 #include <support/Value.h>
00023
00024 #if _SUPPORTS_NAMESPACE
00025 namespace palmos {
00026 namespace support {
00027 #endif
00028
00033 struct URLData;
00034
00035 class SUrl
00036 {
00037 public:
00038 SUrl();
00039 ~SUrl();
00040
00047 SUrl(const SUrl&);
00048
00049 SUrl(const char *urlString, bool escape_all = false);
00050
00051
00052
00053
00054
00055
00056 SUrl(const char *scheme, const char *hostname, int port , bool escape_all = false, bool hierarchal =false );
00057 SUrl(const SUrl& baseURL, const char *relativePath, bool escape_all = false);
00058 SUrl(const SValue &value, status_t *status=NULL);
00059
00060 bool IsValid() const;
00061 static bool IsSchemeSupported(const char *scheme);
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078 status_t SetInternetStyleSchemeSupport(char queryBeginChar = '?',
00079 char queryAssignmentChar = '=',
00080 char querySeperatorChar = '&');
00081
00082
00083 SString AsString() const;
00084 SValue AsValue() const;
00085 inline operator SValue() const { return AsValue(); }
00086
00087 status_t SetTo(const SUrl& url);
00088 status_t SetTo(const char *urlString, bool escape_all = false);
00089 status_t SetTo(const SUrl& baseURL, const char *relativePath, bool escape_all = false);
00090 status_t SetTo(const SValue &value);
00091
00096 bool Equals(const char*) const;
00097 bool Equals(const SUrl& url) const;
00098 bool operator==(const SUrl& url) const;
00099 bool operator==(const char *urlString) const;
00100 bool operator!=(const SUrl& url) const;
00101
00103 SUrl& operator=(const char *url_string);
00104 SUrl& operator=(const SUrl& url);
00105
00106 status_t SetHostName(const char *hostname);
00107 status_t SetUserName(const char *user);
00108 status_t SetPassword(const char *password);
00109 status_t SetFragment(const char *fragment);
00110
00111
00112
00113
00114 status_t SetAction(const char *action);
00115 status_t SetPath(const char *path, bool escape_all=false);
00116 status_t SetPort(int port);
00117
00118 const char* GetHostName() const;
00119 const char* GetUserName() const;
00120 const char* GetPassword() const;
00121 const char* GetFragment() const;
00122 const char *GetAction() const;
00123 const char* GetPath() const;
00124 unsigned short GetPort() const;
00125
00126 const char* GetScheme() const;
00127
00128
00129 const char* GetExtension() const;
00130 const char* GetQuery() const;
00131
00132
00134 status_t SetQuery(const char *query, bool escape_all = false);
00135 status_t AddQueryParameter(const char *name, const char *value, bool escape_all = false);
00136 status_t ReplaceQueryParameter(const char* name, const char* value,
00137 bool addIfNotPresent = true, bool escape_all = false);
00138 status_t RemoveQueryParameter(const char* name);
00139 status_t GetQueryParameter(const char* name, SString* out_value) const;
00140
00141
00153 void GetUnescapedFileName(char *out, int size) const;
00154 void GetUnescapedPath(char *out, int size) const;
00155 void GetUnescapedQuery(char *out, int size) const;
00156
00157
00158 void Reset();
00159
00160
00161
00162
00195 static char *EscapePathString(bool escape_all, char *outString, const char *inString,
00196 size_t inLen = 0x7fffffff);
00197 static char *EscapeQueryString(bool escape_all, char *outString, const char *inString,
00198 size_t inLen = 0x7fffffff);
00199
00203 static int GetEscapedLength(const char *unescaped_string,size_t inLen = 0x7fffffff );
00204
00205 void Print(SString *dump=NULL) const;
00206 private:
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224 status_t ParseMailToURL(const char *src, bool escape_all);
00225 status_t ParseJavaScriptURL(const char *url);
00226 status_t ParseInternetURL(const char *_src, bool escape_all);
00227
00228
00229 status_t SetToInternal(const SUrl &base, const char *relativePath, bool escape_all);
00230
00231
00232 char* NormalizePath();
00233
00234
00235 static char* EscapeString(bool escaped, char *outString, const char *inString, size_t inLen,
00236 const unsigned int *validMap, const unsigned int *escapeMap);
00237
00257 status_t SetNthString(int16_t setIndex, const char *newString, int32_t newStringLen = -1);
00258
00259 status_t CreateUrlDataFromUrl(int32_t extraSpace, const URLData *refUrlData, const char *urlString, bool escape_all=false);
00260 status_t CreateUrlData(int32_t extraSpace, const char *scheme, const char* urlString, bool escape_all=false);
00261
00262 status_t SetPathInternal(const char *path, int32_t length, bool escape_all);
00263
00264 status_t SetQueryInternal(const char *query,int32_t length, bool escape_all);
00265
00266 status_t GetQueryParameterInternal(const char *query, const char *name,
00267 const char **namePP, int32_t *nameLengthP,
00268 const char **valuePP, int32_t *valueLengthP) const;
00269
00270 status_t ComposeEscapedQuery(const char *name, const char *value,
00271 bool escape_all, SString *outStrP) const ;
00272
00273 status_t UnEscapedQuery(const char *query, int32_t length, SString *outStrP) const ;
00274
00275
00276
00277 URLData *fData;
00278 size_t fDataLen;
00279 size_t fExtraSpace;
00280 };
00281
00284 #if _SUPPORTS_NAMESPACE
00285 } }
00286 #endif
00287
00288 #endif