1 #ifndef CGI___CGIAPP__HPP
2 #define CGI___CGIAPP__HPP
91 unsigned int GetFCgiIteration(
void)
const {
return (
unsigned int)(m_Iteration.Get()); }
94 virtual bool IsFastCGI(
void)
const;
102 virtual void Init(
void);
109 virtual void Exit(
void);
115 virtual int Run(
void);
167 const char*
const* argv);
216 virtual void OnEvent(EEvent event,
int status);
239 int ifd,
int ofd,
int flags);
244 int ifd,
int ofd,
int flags);
246 void RegisterDiagFactory(
const string&
key,
261 ELogOpt GetLogOpt(
void)
const;
275 virtual string GetDefaultLogPath(
void)
const;
280 virtual void AppStop(
int exit_code);
370 void ProcessHttpReferer(
void);
386 virtual bool x_RunFastCGI(
int*
result,
unsigned int def_iter = 10);
388 string GetFastCGIStandaloneServer(
void)
const;
389 bool GetFastCGIStatLog(
void)
const;
390 unsigned int GetFastCGIIterations(
unsigned int def_iter)
const;
391 bool GetFastCGIComplete_Request_On_Sigterm(
void)
const;
393 unsigned int GetFastCGIWatchFileTimeout(
bool have_watcher)
const;
394 int GetFastCGIWatchFileRestartDelay(
void)
const;
395 bool GetFastCGIChannelErrors(
void)
const;
396 bool GetFastCGIHonorExitRequest(
void)
const;
397 bool GetFastCGIDebug(
void)
const;
398 bool GetFastCGIStopIfFailed(
void)
const;
399 unsigned int GetFastCGIMTMaxThreads(
void)
const;
401 static CTime GetFileModificationTime(
const string& filename);
403 bool CheckMemoryLimit(
void);
406 virtual ICache* GetCacheStorage(
void)
const;
407 virtual bool IsCachingNeeded(
const CCgiRequest& request)
const;
418 eSR_Executable = 111,
442 void x_AddLBCookie();
446 bool x_IsSetProcessor(
void)
const;
465 bool m_ShouldExit =
false;
493 const std::exception* ex = 0);
499 virtual string Compose(
void);
502 virtual void Submit(
const string& message);
505 virtual string Compose_ProgramName (
void);
506 virtual string Compose_Timing (
const CTime& end_time);
507 virtual string Compose_Entries (
void);
508 virtual string Compose_Result (
void);
509 virtual string Compose_ErrMessage (
void);
598 string GetSelfReferer(
void)
const;
615 void x_InitArgs(
void)
const;
626 bool m_OutputBroken =
false;
629 bool m_RequestStartPrinted =
false;
630 bool m_ErrorStatus =
false;
632 bool m_IsResultReady =
true;
643 CArgs&
GetArgs(
void) {
if (!m_CgiArgs) x_InitArgs();
return *m_CgiArgs; }
644 const CArgs&
GetArgs(
void)
const {
if (!m_CgiArgs) x_InitArgs();
return *m_CgiArgs; }
666 string GetRID(
void)
const {
return m_RID; }
705 TClientConnIntSeverity;
Base class for request processors.
static CNcbiApplication * Instance(void)
Singleton method.
Writer-based output stream.
BLOB cache read/write/maintenance interface.
bool operator<(const CEquivRange &A, const CEquivRange &B)
std::ofstream out("events_result.xml")
main entry point for tests
void LogRequest(const TReq &req)
virtual EPreparseArgs PreparseArgs(int argc, const char *const *argv)
Check the command line arguments before parsing them.
virtual int Run(void)=0
Run the application.
virtual void Init(void)
Initialize the application.
virtual void AppStop(int exit_code)
Method to be called before application exit.
virtual const CArgs & GetArgs(void) const
Get parsed command line arguments.
virtual void SetupArgDescriptions(CArgDescriptions *arg_desc)
Setup the command line argument descriptions.
virtual void Exit(void)
Cleanup on application exit.
virtual void AppStart(void)
Method to be called before application start.
void SetHTTPStatus(unsigned int status, const string &reason=kEmptyStr)
EAdminCommand
Admin commands passed through ncbi_admin_cmd argument.
~CCgiProcessorGuard(void)
virtual int OnException(std::exception &e, CNcbiOstream &os)
This method is called if an exception is thrown during the processing of HTTP request.
AutoPtr< char, ArrayDeleter< char > > TBuf
const CNcbiResource & GetResource(void) const
bool GetRequestStartPrinted(void) const
void SetOutputBroken(bool val)
const CCgiContext & GetContext(void) const
Get current server context. Throw exception if the context is not set.
void SetRequestStartPrinted(bool val)
map< string, string, PNocase > TTrailer
void SetErrorStatus(bool val)
shared_ptr< CCgiContext > m_Context
CCgiStreamWrapperWriter * m_Writer
bool GetOutputBroken(void) const
void SetRequestFlags(int flags)
Set cgi parsing flag.
void AbortChunkedTransfer(void)
const CNcbiOstream & GetOutputStream(void) const
friend class CCgiRequestProcessor
CAtomicCounter m_Iteration
virtual void ProcessVersionRequest(CCgiApplication::EVersionType ver_type)
unique_ptr< CNcbiOstream > m_OutputStream
typedef NCBI_PARAM_TYPE(CGI, DisableTrackingCookie) TCGI_DisableTrackingCookie
string m_MediaRangeParams
Media range parameters.
int m_RequestFlags
Bit flags for CCgiRequest.
CCgiContext & GetContext(void)
Get current server context. Throw exception if the context is not set.
CCgiProcessorGuard(CTls< CCgiRequestProcessor > &proc)
void SetRID(const string &val)
virtual bool ProcessAdminRequest(CCgiApplication::EAdminCommand cmd)
bool IsSetArgs(void) const
CCgiApplication(const CCgiApplication &)
CCgiApplication::SAcceptEntry TAcceptEntry
void SetInputStream(CNcbiIstream *in)
unique_ptr< CNcbiResource > m_Resource
CCgiWatchFile(const string &filename, int limit=1024)
void SetCacheStream(CNcbiOstream &stream)
virtual void OnEvent(EEvent event, int status)
This method is called after each request, or when the CGI is forced to skip a request,...
CNcbiOstream & GetOutputStream(void)
virtual void OnEvent(CCgiApplication::EEvent event, int status)
virtual void ProcessHelpRequest(const string &format)
float m_Quality
Quality factor or "1" if not set (or not numeric).
bool GetErrorStatus(void) const
map< string, string > TParams
friend void s_ScheduleFastCGIExit(void)
CTls< CCgiRequestProcessor > * m_Proc
EStreamMode GetWriterMode(void)
void x_OnEvent(EEvent event, int status)
const CCgiApplication & GetApp(void) const
virtual bool ProcessAdminRequest(EAdminCommand cmd)
Process admin command passed through ncbi_admin_cmd argument.
friend class CCgiApplication
void SetRequestId(const string &rid, bool is_done)
void SetHTTPStatus(unsigned int status, const string &reason=kEmptyStr)
Set HTTP status code in the current request context and in the current CHttpResponse if one exists.
CNcbiResource & GetResource(void)
unique_ptr< CCookieAffinity > m_Caf
CCgiApplication::TAcceptEntries TAcceptEntries
virtual int OnException(std::exception &e, CNcbiOstream &os)
void SetWriterMode(EStreamMode mode)
bool IsSetOutputStream(void) const
virtual void FASTCGI_ScheduleExit(void)
Schedule Fast-CGI loop to end as soon as possible, after safely finishing the currently processed req...
virtual bool ValidateSynchronizationToken(void)
CCgiApplication & GetApp(void)
string GetRID(void) const
TDiagFactoryMap m_DiagFactories
ELogOpt
Analyze registry settings ([CGI] Log) and return current logging option.
virtual bool ValidateSynchronizationToken(void)
Validate synchronization token (cross-site request forgery prevention).
const CArgs & GetArgs(void) const
const CCgiContext & GetContext(void) const
friend class CCgiStatistics
void SetRequestId(const string &rid, bool is_done)
virtual void ProcessHelpRequest(const string &format)
Process help request: set content type, print usage informations etc.
bool IsSetInputStream(void) const
CNcbiResource & GetResource(void)
Get server 'resource'. Throw exception if the resource is not set.
void SetContext(shared_ptr< CCgiContext > context)
CCgiApplication & m_CgiApp
const CNcbiResource & GetResource(void) const
Get server 'resource'. Throw exception if the resource is not set.
void SetOutputStream(CNcbiOstream *out)
const CNcbiIstream & GetInputStream(void) const
bool IsSetContext(void) const
virtual void ProcessVersionRequest(EVersionType ver_type)
Process version request: set content type, print version informations etc.
CCgiContext & GetContext(void)
void SetResultReady(bool val)
unsigned int GetFCgiIteration(void) const
Get the # of currently processed HTTP request.
list< SAcceptEntry > TAcceptEntries
CRef< CTls< CCgiRequestProcessor > > m_Processor
Client_Connection_Interruption_Okay
virtual int ProcessRequest(CCgiContext &context)=0
This is the method you should override.
void ParseAcceptHeader(TAcceptEntries &entries) const
Parse "Accept:" header, put entries to the list, more specific first.
map< string, CDiagFactory * > TDiagFactoryMap
unique_ptr< CArgs > m_CgiArgs
CCgiStreamWrapper(CNcbiOstream &out)
Client_Connection_Interruption_Severity
CNcbiIstream & GetInputStream(void)
bool GetResultReady(void) const
CCgiApplication & operator=(const CCgiApplication &)
TParams m_AcceptParams
Accept parameters.
void FinishChunkedTransfer(const TTrailer *trailer)
unique_ptr< CNcbiIstream > m_InputStream
@ eAdmin_HealthZ
Report health for this CGI as kubernetes expects.
@ eAdmin_Health
Report health for this CGI only.
@ eAdmin_HealthDeep
Report health for this CGI and any services used by it.
@ eAdmin_LiveZ
Report if this CGI is alive as kubernetes expects.
@ eAdmin_ReadyZ
Report readyness for this CGI as kubernetes expects.
@ eException
An exception occured during the request processing.
@ eExit
No more iterations, exiting (called the very last)
@ eWaiting
Periodic awakening while waiting for the next request.
@ eError
The HTTP request was processed, non-zero exit code.
@ eEndRequest
HTTP request processed, all results sent to client.
@ eExecutable
FCGI forced to exit as its modif. time has changed.
@ eWatchFile
FCGI forced to exit as its "watch file" has changed.
@ eExitOnFail
[FastCGI].StopIfFailed set, and the iteration failed
@ eSuccess
The HTTP request was processed, with zero exit code.
EDiagSev
Severity level for the posted diagnostics.
#define NCBI_PARAM_DECL_EXPORT(expname, type, section, name)
Same as NCBI_PARAM_DECL but with export specifier (e.g.
#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.
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
IO_PREFIX::istream CNcbiIstream
Portable alias for istream.
void Reset(void)
Reset thread local storage.
#define NCBI_SBUILDINFO_DEFAULT()
const struct ncbi::grid::netcache::search::fields::KEY key
Defines the CNcbiApplication and CAppException classes for creating NCBI applications.
Process information in the NCBI Registry, including working with configuration files.
std::istream & in(std::istream &in_, double &x_)
This class allows to add build info (date and tag) to application version.
static CS_CONTEXT * context
static wxAcceleratorEntry entries[3]