1 #ifndef CGI___NCBICGI__HPP
2 #define CGI___NCBICGI__HPP
82 const string& GetName(
void)
const;
100 EWriteMethod wmethod = eHTTPResponse,
107 void CopyAttributes(
const CCgiCookie& cookie);
112 void SetValue (
const string&
str);
113 void SetDomain (
const string&
str);
114 void SetPath (
const string&
str);
115 void SetExpDate(
const tm& exp_date);
116 void SetExpTime(
const CTime& exp_time);
117 void SetSecure (
bool secure);
118 void SetHttpOnly(
bool http_only);
122 const string& GetValue (
void)
const;
123 const string& GetDomain (
void)
const;
124 const string& GetPath (
void)
const;
126 string GetExpDate(
void)
const;
128 bool GetExpDate(tm* exp_date)
const;
129 bool GetSecure(
void)
const;
130 bool GetHttpOnly(
void)
const;
145 fInvalid_Name = 1<<0,
146 fInvalid_Value = 1<<1,
147 fInvalid_Any = fInvalid_Name | fInvalid_Value
170 static void x_CheckField(
const string&
str,
172 const char* banned_symbols,
173 const string* cookie_name =
NULL);
174 static string x_EncodeCookie(
const string&
str,
197 return cookie.
Write(os);
242 EOnBadCookie on_bad_cookie = eOnBadCookie_SkipAndError,
248 bool Empty(
void)
const;
251 void SetUrlEncodeFlag(
EUrlEncode encode_flag);
260 EOnBadCookie on_bad_cookie = eOnBadCookie_SkipAndError);
265 EOnBadCookie on_bad_cookie);
275 void Add(
const string&
str,
276 EOnBadCookie on_bad_cookie = eOnBadCookie_SkipAndError);
280 const string& domain,
const string& path);
282 const string& domain,
const string& path)
const;
295 TCRange GetAll(
void)
const;
307 size_t Remove(
const string& name,
bool destroy=
true);
323 void SetAllCookiesSecure(
bool value);
327 void SetAllCookiesHttpOnly(
bool value);
336 static ECheckResult x_CheckField(
const string&
str,
338 const char* banned_symbols,
339 EOnBadCookie on_bad_cookie,
340 const string* cookie_name =
NULL);
366 return cookies.
Write(os);
426 unsigned int position,
const string&
type)
427 : m_Value(
value), m_Filename(filename), m_ContentType(
type),
428 m_Position(position) { }
431 m_Value(
data.m_Value), m_Filename(
data.m_Filename),
432 m_ContentType(
data.m_ContentType),
433 m_Position(
data.m_Position)
445 unsigned int position = 0,
450 unsigned int position = 0,
454 : m_Data(e.m_Data) { }
472 if (m_Data->m_Reader.get()) { x_ForceComplete(); }
473 return m_Data->m_Value;
476 { x_ForceUnique();
return m_Data->m_Value; }
478 { x_ForceUnique(); m_Data->m_Value = v; }
480 { x_ForceUnique(); m_Data->m_Reader.reset(
r); }
482 { x_ForceUnique(); m_Data->m_Reader.reset(
new CStreamReader(is, own)); }
504 CStringUTF8 GetValueAsUTF8(EOnCharsetError on_error =
505 eCharsetError_Ignore)
const;
509 {
return m_Data->m_Filename; }
511 { x_ForceUnique();
return m_Data->m_Filename; }
513 { x_ForceUnique(); m_Data->m_Filename =
f; }
518 {
return m_Data->m_Position; }
520 { x_ForceUnique();
return m_Data->m_Position; }
522 { x_ForceUnique(); m_Data->m_Position = p; }
526 {
return m_Data->m_ContentType; }
528 { x_ForceUnique();
return m_Data->m_ContentType; }
530 { x_ForceUnique(); m_Data->m_ContentType =
f; }
532 operator const string&()
const {
return GetValue(); }
533 operator string&() {
return SetValue(); }
538 bool empty()
const {
return GetValue().empty(); }
539 const char*
c_str()
const {
return GetValue().c_str(); }
540 int compare(
const string& s)
const {
return GetValue().compare(s); }
541 int compare(
const char* s)
const {
return GetValue().compare(s); }
543 {
return GetValue().substr(
i,
n); }
545 {
return GetValue().find(s, pos); }
547 {
return GetValue().find(s, pos); }
549 {
return GetValue().find(c, pos); }
551 {
return GetValue().find_first_of(s, pos); }
553 {
return GetValue().find_first_of(s, pos); }
567 return !(*
this == v);
572 return GetValue() == v;
577 return !(*
this == v);
582 return GetValue() == v;
587 return !(*
this == v);
593 if ( !m_Data->ReferencedOnlyOnce() ) {
594 if (m_Data->m_Reader.get()) { x_ForceComplete(); }
595 m_Data =
new SData(*m_Data);
599 void x_ForceComplete()
const;
602 string x_GetCharset(
void)
const;
655 const string& filename,
656 bool is_index =
false) = 0;
665 void AddEntry(
const string& name,
667 const string& filename,
668 bool is_index)
override;
706 fIndexesNotEntries = (1 << 0),
708 fIgnoreQueryString = (1 << 1),
710 fOwnEnvironment = (1 << 2),
712 fDoNotParseContent = (1 << 3),
714 fCaseInsensitiveArgs = (1 << 4),
716 fCookies_Unencoded = (1 << 5),
718 fCookies_SpaceAsHex = (1 << 6),
720 fSaveRequestContent = (1 << 7),
723 fIgnorePageHitId = (1 << 8),
725 fSkipDiagProperties = (1 << 9),
727 fSetDiagProperties = 0,
729 fParseInputOnDemand = (1 << 10),
731 fSemicolonIsNotArgDelimiter = (1 << 11),
734 fDisableTrackingCookie = (1 << 12),
738 fIncludePreparsedEntries = (1 << 13),
740 fDisableParsingAsIndex = (1 << 14),
747 size_t errbuf_size = 256);
750 const char*
const* argv,
751 const char*
const* envp = 0,
755 size_t errbuf_size = 256);
758 size_t errbuf_size = 256);
764 static const string GetPropertyName(
ECgiProp prop);
767 const string& GetProperty(
ECgiProp prop)
const;
777 const string& GetRandomProperty(
const string&
key,
bool http =
true)
const;
782 size_t GetContentLength(
void)
const;
786 const string& GetContent(
void)
const;
808 const CCgiEntry& GetEntry(
const string& name,
bool* is_found = 0)
const;
823 CCgiEntry* GetPossiblyUnparsedEntry(
const string& name);
826 void ParseRemainingContent(
void);
839 eDontCreateIfNotExist,
846 CCgiSession& GetSession(ESessionCreateMode
mode = eCreateIfNotExist)
const;
856 int GetInputFD(
void)
const;
863 void SetInputStream(
CNcbiIstream* is,
bool own =
false,
int fd = -1);
885 const char*
const* GetClientTrackingEnv(
void)
const;
900 string GetCGIEntriesStr(
void)
const;
902 bool CalcChecksum(
string& checksum,
string& content)
const;
918 const string& GetRequestMethodName(
void)
const;
920 ERequestMethod GetRequestMethod(
void)
const;
961 const string& x_GetPropertyByName(
const string& name)
const;
1069 : m_EncodeFlag(
NStr::eUrlEnc_SkipMarkChars),
1073 m_AllHttpOnly(
false)
1083 m_AllHttpOnly(
false)
1095 m_AllHttpOnly(
false)
1138 if (
m_Data->m_Reader.get()) {
1139 return m_Data->m_Reader.release();
1149 if (
m_Data->m_Reader.get()) {
1164 unique_ptr<IReader> reader(
data.m_Reader.release());
bool operator!=(const _Ht_iterator< _Val, _Nonconst_traits< _Val >, _Key, _HF, _ExK, _EqK, _All > &__x, const _Ht_iterator< _Val, _Const_traits< _Val >, _Key, _HF, _ExK, _EqK, _All > &__y)
Note about the "buf_size" parameter for streams in this API.
@ fOwnReader
Own the underlying reader.
A very basic data-read interface.
container_type::const_iterator const_iterator
container_type::iterator iterator
parent_type::iterator iterator
parent_type::const_iterator const_iterator
bool operator<(const CEquivRange &A, const CEquivRange &B)
bool operator==(const CEquivRange &A, const CEquivRange &B)
bool Empty(const CNcbiOstrstream &src)
static const char * str(char *buf, int n)
@ eNoOwnership
No ownership is assumed.
set< CCgiCookie *, CCgiCookie::PLessCPtr > TSet
SIZE_TYPE find(char c, SIZE_TYPE pos=0) const
void SetFilename(const string &f)
SIZE_TYPE find(const string &s, SIZE_TYPE pos=0) const
int GetInputFD(void) const
Returns file descriptor of input stream, or -1 if unavailable.
const CNcbiEnvironment * m_Env
set of environment variables
CNcbiIstream * GetValueStream()
Get the value as a stream, potentially on the fly – in which case the caller takes ownership of the s...
CCgiEntry(const char *value, const string &filename=kEmptyStr, unsigned int position=0, const string &type=kEmptyStr)
const TCgiIndexes & GetIndexes(void) const
Get a set of indexes(decoded) received from the client.
string x_RetrieveSessionId() const
void SetSecure(bool secure)
pair< TCIter, TCIter > TCRange
TCgiEntries::iterator TCgiEntriesI
TCgiEntries::const_iterator TCgiEntriesCI
static bool x_GetString(string *str, const string &val)
CCgiRequest(const CCgiRequest &)
prohibit default initialization and assignment
int m_InputFD
input file descriptor, if available.
const TCgiEntries & GetEntries(void) const
Get a set of entries(decoded) received from the client.
NStr::EUrlEncode m_EncodeFlag
map< string, string > TCgiProperties
SIZE_TYPE find(const char *s, SIZE_TYPE pos=0) const
unsigned int & SetPosition()
void SetPath(const string &str)
void SetValue(const string &str)
All SetXXX(const string&) methods beneath:
const string & GetName(void) const
The cookie name cannot be changed during its whole timelife.
CCgiCookie * Find(const string &name, const string &domain, const string &path)
Return NULL if cannot find this exact cookie.
const string & GetValue(void) const
All "const string& GetXXX(...)" methods beneath return reference to "NcbiEmptyString" if the requeste...
CCgiEntryReaderContext * m_EntryReaderContext
string & SetContentType()
void x_SetSession(CCgiSession &session)
int compare(const string &s) const
CExtraEntryCollector(void)
SIZE_TYPE find_first_of(const char *s, SIZE_TYPE pos=0) const
EWriteMethod
Whether the cookie is sent as a part of HTTP request or HTTP response.
TCgiIndexes m_Indexes
set of the request ISINDEX-like indexes(already retrieved; cached)
multimap< string, CCgiEntry, PNocase_Conditional > TCgiEntries
void SetExpDate(const tm &exp_date)
TSet::const_iterator TCIter
void SetUrlEncodeFlag(EUrlEncode encode_flag)
pair< TIter, TIter > TRange
void SetValue(IReader *r)
const string & GetValue() const
Get the value as a string, (necessarily) prefetching it all if applicable; the result remains availab...
ECgiProp
Set of "standard" HTTP request properties.
void SetValue(CNcbiIstream &is, EOwnership own=eNoOwnership)
int compare(const char *s) const
CDiagContext_Extra::TExtraArgs m_Args
void x_ForceComplete() const
const CCgiCookies & GetCookies(void) const
Retrieve the request cookies.
CNcbiIstream * m_Input
input stream
void SetTrackingCookie(const string &cookie_value)
Store/retrieve tracking cookie value.
const string & GetContentType() const
May be available for some fields of POSTed forms.
const CNcbiEnvironment & GetEnvironment() const
CNcbiOstream & Write(CNcbiOstream &os, EWriteMethod wmethod=eHTTPResponse, EUrlEncode flag=eUrlEncode_SkipMarkChars) const
Compose and write to output stream "os":
string substr(SIZE_TYPE i=0, SIZE_TYPE n=NPOS) const
bool Remove(CCgiCookie *cookie, bool destroy=true)
Remove "cookie" from this set; deallocate it if "destroy" is true Return FALSE if can not find "cooki...
TCgiEntries m_Entries
set of the request FORM-like entries(already retrieved; cached)
list< string > TCgiIndexes
void Clear(void)
Remove all stored cookies.
CNcbiOstream & Write(CNcbiOstream &os, CCgiCookie::EWriteMethod wmethod=CCgiCookie::eHTTPResponse) const
Printout all cookies into the stream "os".
void SetHttpOnly(bool http_only)
void SetValue(const string &v)
CDiagContext_Extra::TExtraArgs & GetArgs(void)
CCgiCookies(void)
Empty set of cookies.
void ResetInvalid(TInvalidFlag flag)
IReader * GetValueReader()
Get the value via a reader, potentially on the fly – in which case the caller takes ownership of the ...
unique_ptr< CTrackingEnvHolder > m_TrackingEnvHolder
CCgiCookies(const CCgiCookies &)
prohibit default initialization and assignment
const string & GetTrackingCookie(void) const
NCBI_XCGI_EXPORT
Parameter to control error handling of incoming cookies.
const char * c_str() const
CCgiCookie * Add(const string &name, const string &value, const string &domain=kEmptyStr, const string &path=kEmptyStr, EOnBadCookie on_bad_cookie=eOnBadCookie_SkipAndError)
All Add() functions: if the added cookie has the same {name, domain, path} as an already existing one...
const string & GetFilename() const
Only available for certain fields of POSTed forms.
unique_ptr< CNcbiEnvironment > m_OwnEnv
virtual void AddEntry(const string &name, const string &value, const string &filename, bool is_index=false)=0
bool GetHttpOnly(void) const
SData(const string &value, const string &filename, unsigned int position, const string &type)
CCgiCookies m_Cookies
set of the request cookies(already retrieved; cached)
CCgiEntry(const CCgiEntry &e)
string operator+(const CCgiEntry &e, const string &s)
const string & GetPath(void) const
unique_ptr< string > m_Content
Original request content or NULL if fSaveRequestContent is not set.
SIZE_TYPE find_first_of(const string &s, SIZE_TYPE pos=0) const
EOnBadCookie
How to handle badly formed cookies.
static const size_t kContentLengthUnknown
Get content length using value of the property 'eCgi_ContentLength'.
TInvalidFlag m_InvalidFlag
void SetInvalid(TInvalidFlag flag)
~CCgiCookies(void)
Destructor.
CCgiEntry & operator=(const CCgiEntry &e)
TInvalidFlag IsInvalid(void) const
SIZE_TYPE size() const
commonly-requested string:: operations...
bool GetAllCookiesSecure(void) const
bool GetSecure(void) const
virtual ~CEntryCollector_Base(void)
static void x_CheckField(const string &str, EFieldType ftype, const char *banned_symbols, const string *cookie_name=NULL)
bool GetAllCookiesHttpOnly(void) const
ERequestMethod
Standard request methods.
int TFlags
Startup initialization.
void SetContentType(const string &f)
void SetSecure(bool secure)
Set secure connection flag.
const CCgiCookie * TCPtr
Predicate for the cookie comparison.
CNcbiIstream * GetInputStream(void) const
Return pointer to the input stream.
unsigned int GetPosition() const
CGI parameter number – automatic image name parameter is #0, explicit parameters start at #1.
const string & GetDomain(void) const
void SetDomain(const string &str)
unique_ptr< IReader > m_Reader
size_t m_ErrBufSize
Request initialization error buffer size; when initialization code hits unexpected EOF it will try to...
bool Empty(void) const
Return TRUE if this set contains no cookies.
~CExtraEntryCollector(void) override
CCgiEntry(const string &value=kEmptyStr, const string &filename=kEmptyStr, unsigned int position=0, const string &type=kEmptyStr)
CNcbiOstream & operator<<(CNcbiOstream &os, const CCgiCookie &cookie)
EOnCharsetError
Action to perform if the explicit charset is not supported.
EUrlEncode GetUrlEncodeFlag(void) const
@ eCgi_HttpIfModifiedSince
@ eOnBadCookie_StoreAndError
Report error, store bad cookie as-is.
@ eOnBadCookie_ThrowException
Throw exception, ignore bad cookie.
@ eOnBadCookie_SkipAndError
Report error, ignore bad cookie.
@ eOnBadCookie_Skip
Silently ignore bad cookie.
@ eCreateIfNotExist
If Session does not exist the new one will be created.
@ eCharsetError_Ignore
Ignore unknown charset (try to autodetect)
@ eUrlEncode_SkipMarkChars
SDiagMessage::TExtraArgs TExtraArgs
void Write(CObjectOStream &out, TConstObjectPtr object, const CTypeRef &type)
#define NCBI_PARAM_ENUM_DECL_EXPORT(expname, type, section, name)
Same as NCBI_PARAM_ENUM_DECL but with export specifier (e.g.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
void g_ExtractReaderContents(IReader &reader, string &s)
Append all IReader contents to a given string.
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
IO_PREFIX::istream CNcbiIstream
Portable alias for istream.
NCBI_NS_STD::string::size_type SIZE_TYPE
EUrlEncode
URL-encode flags.
enum ENcbiOwnership EOwnership
Ownership relations between objects.
range(_Ty, _Ty) -> range< _Ty >
const struct ncbi::grid::netcache::search::fields::KEY key
const GenericPointer< typename T::ValueType > T2 value
double r(size_t dimension_, const Int4 *score_, const double *prob_, double theta_)
Reader-writer based streams.
API to parse user agent strings.
void Serialize(CNcbiOstream &, const CRawScoreVector< Key, Score > &)
Generics These throw an exception; we must implement serialization for each type.
void Deserialize(CNcbiIstream &istr, CRawScoreVector< Key, Score > &)
static wxAcceleratorEntry entries[3]