1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
|
/* bzflag
* Copyright (c) 1993-2025 Tim Riker
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the license found in the file
* named COPYING that should have accompanied this file.
*
* THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
// a base class for plugins that want to do HTTP
#ifndef _BZFS_HTTP_H_
#define _BZFS_HTTP_H_
#include "bzfsAPI.h"
class BZF_API bzhttp_SessionData
{
public:
public:
bzhttp_SessionData();
~bzhttp_SessionData();
unsigned int SessionID;
const char* GetPrivateItem ( const char* name );
void SetPrivateItem ( const char * name, const char* value );
void ClearPrivateItem ( const char * name );
void FlushPrivateItems ( void );
const char* GetGlobalItem ( const char* name );
void SetGlobalItem ( const char * name, const char* value );
void ClearGlobalItem ( const char * name );
void *pimple;
};
typedef enum
{
eHTTPUnknown = 0,
eHTTPGet,
eHTTPHead,
eHTTPPost,
eHTTPPut,
eHTTPDelete,
eHTTPTrace,
eHTTPOptions,
eHTTPConnect
} bzhttp_eRequestType;
class BZF_API bzhttp_Request
{
public:
bzhttp_Request();
virtual ~bzhttp_Request();
bzhttp_eRequestType RequestType;
bz_ApiString URL;
bz_ApiString Resource;
bz_ApiString RequesterIP;
bz_ApiString RequesterHost;
bz_ApiString BZID;
bz_ApiString BZIDCallsign;
bz_APIStringList BZIDGroups;
virtual bool UserHasPerm ( const char* perm ) const;
bz_ApiString Body;
virtual void AddHeader ( const char* name, const char* value);
virtual const char* GetHeader ( const char* name) const;
virtual const char* GetHeader ( size_t index ) const;
virtual size_t GetHeaderCount ()const;
virtual void AddCookie ( const char* name, const char* value);
virtual const char* GetCookie ( const char* name) const;
virtual const char* GetCookie ( size_t index ) const;
virtual size_t GetCookieCount () const;
virtual void AddParamater ( const char* name, const char* value);
virtual const char* GetParamater ( const char* name) const;
virtual const char* GetParamater ( size_t index ) const;
virtual size_t GetParamaterCount () const;
virtual bool InBZIDGroup (const char *) const
{
return false;
}
bzhttp_SessionData *Session;
int Version;
protected:
void *pimple;
};
typedef enum
{
e200OK,
e301Redirect,
e302Found,
e401Unauthorized,
e403Forbiden,
e404NotFound,
e418IAmATeapot,
e500ServerError
} bzhttp_eReturnCode;
typedef enum
{
eText,
eOctetStream,
eBinary,
eHTML,
eCSS,
eXML,
eJSON,
eOther
} bzhttp_eDocumentType;
class BZF_API bzhttp_Response
{
public:
bzhttp_Response();
virtual ~bzhttp_Response();
bzhttp_eReturnCode ReturnCode;
bzhttp_eDocumentType DocumentType;
bool ForceNoCache;
bz_ApiString RedirectLocation;
bz_ApiString MimeType;
bz_ApiString MD5Hash;
bz_ApiString CookieDomain;
bz_ApiString CookiePath;
virtual void AddHeader ( const char* name, const char* value);
virtual void AddCookies ( const char* name, const char* value);
virtual void AddBodyData ( const char* value);
virtual void AddBodyData ( const void* value, size_t size);
int Version;
void *pimple;
};
typedef enum
{
eNoPage = 0,
eWaitForIt,
ePageDone
} bzhttp_ePageGenStatus;
typedef enum
{
eNoAuth = 0,
eHTTPBasic,
eHTTPOther,
eBZID
} bzhttp_eAuthenticationMethod;
typedef enum
{
eAuthFail = 0,
eAuthOK,
eNotAuthedYet
} bzhttp_eAuthenticationStatus;
class BZF_API bzhttp_VDir
{
public:
bzhttp_VDir();
virtual ~bzhttp_VDir();
virtual const char* VDirName() = 0;
virtual const char* VDirDescription()
{
return NULL;
}
virtual bzhttp_ePageGenStatus GeneratePage ( const bzhttp_Request& request, bzhttp_Response &response ) = 0;
virtual bool SupportPut ( void )
{
return false;
}
virtual bool AllowResourceDownloads ( void )
{
return false;
}
bz_ApiString BaseURL;
bz_APIStringList ResourceDirs;
bzhttp_eAuthenticationMethod RequiredAuthentiction;
bz_ApiString OtherAuthenicationMethod;
bz_ApiString HTTPAuthenicationRelalm;
// server groups are automatically included
bz_APIStringList BZIDAuthenicationGroups;
bool CacheAuthentication;
virtual bzhttp_eAuthenticationStatus AuthenticateHTTPUser ( const char* /*ipAddress*/, const char* /*user*/,
const char* /*password*/, const bzhttp_Request& /*request*/ )
{
return eAuthFail;
}
virtual bool GenerateNoAuthPage ( const bzhttp_Request& /*request*/, bzhttp_Response &/*response*/ )
{
return false;
}
// data sizes
int MaxRequestSize;
int MaxRequestBody;
void AddMimeType(const char* extension, const char* mime );
void AddStandardTypes ();
void* pimple;
};
BZF_API bool bzhttp_RegisterVDir (bz_Plugin* plugin, bzhttp_VDir *vdir );
BZF_API bool bzhttp_RemoveVDir (bz_Plugin* plugin, bzhttp_VDir *vdir );
BZF_API bool bzhttp_RemoveAllVdirs (bz_Plugin* plugin );
// templates
class BZF_API bzhttp_TemplateMetaData
{
public:
bzhttp_TemplateMetaData();
bzhttp_TemplateMetaData( const bzhttp_TemplateMetaData& /*r*/);
virtual ~bzhttp_TemplateMetaData();
const char * Get ( const char* key, unsigned int index = 0 );
unsigned int Count ( const char* key );
void Add ( const char* key, const char* val );
protected:
void *pimple;
};
class BZF_API bzhttp_TemplateCallback
{
public:
virtual ~bzhttp_TemplateCallback() {};
virtual bz_ApiString GetTemplateKey(const char* /* key */)
{
return bz_ApiString("");
}
virtual bool GetTemplateLoop(const char* /* key */, const char* /*param*/)
{
return false;
}
virtual bool GetTemplateIF(const char* /* key */, const char* /*param*/)
{
return false;
}
bzhttp_TemplateMetaData* MetaData;
};
BZF_API bz_ApiString bzhttp_RenderTemplate ( const char* file, bzhttp_TemplateCallback* callback,
const char* pathSet = NULL );
BZF_API bz_ApiString bzhttp_RenderTemplateFromText ( const char* text, bzhttp_TemplateCallback* callback,
const char* pathSet = NULL );
BZF_API bzhttp_TemplateMetaData bzhttp_GetTemplateMetaData( const char* file );
// path utilities
BZF_API bool bzhttp_AddSearchPath ( const char* pathSet, const char* path );
BZF_API const char* bzhttp_FindFile ( const char* pathSet, const char* filename );
#endif //_BZFS_HTTP_H_
// Local Variables: ***
// mode: C++ ***
// tab-width: 4 ***
// c-basic-offset: 4 ***
// indent-tabs-mode: nil ***
// End: ***
// ex: shiftwidth=4 tabstop=4
|