Пример #1
0
static void
traceHandlerCalled(TSession * const abyssSessionP) {

    const char * methodDesc;
    const TRequestInfo * requestInfoP;

    fprintf(stderr, "xmlrpc_server_abyss URI path handler called.\n");

    SessionGetRequestInfo(abyssSessionP, &requestInfoP);

    fprintf(stderr, "URI = '%s'\n", requestInfoP->uri);

    switch (requestInfoP->method) {
    case m_unknown: methodDesc = "unknown";   break;
    case m_get:     methodDesc = "get";       break;
    case m_put:     methodDesc = "put";       break;
    case m_head:    methodDesc = "head";      break;
    case m_post:    methodDesc = "post";      break;
    case m_delete:  methodDesc = "delete";    break;
    case m_trace:   methodDesc = "trace";     break;
    case m_options: methodDesc = "m_options"; break;
    default:        methodDesc = "?";
    }
    fprintf(stderr, "HTTP method = '%s'\n", methodDesc);

    if (requestInfoP->query)
        fprintf(stderr, "query (component of URL)='%s'\n",
                requestInfoP->query);
    else
        fprintf(stderr, "URL has no query component\n");
}
Пример #2
0
bool
AbyssServer::Session::hasReferer() const {

    const TRequestInfo * requestInfoP;

    SessionGetRequestInfo(this->implP->cSessionP, &requestInfoP);

    return requestInfoP->referer != NULL;
}
Пример #3
0
bool
AbyssServer::Session::hasUseragent() const {

    const TRequestInfo * requestInfoP;

    SessionGetRequestInfo(this->implP->cSessionP, &requestInfoP);

    return requestInfoP->useragent != NULL;
}
Пример #4
0
bool
AbyssServer::Session::hasFrom() const {

    const TRequestInfo * requestInfoP;

    SessionGetRequestInfo(this->implP->cSessionP, &requestInfoP);

    return requestInfoP->from != NULL;
}
Пример #5
0
bool
AbyssServer::Session::uriHasQuery() const {

    const TRequestInfo * requestInfoP;

    SessionGetRequestInfo(this->implP->cSessionP, &requestInfoP);

    return requestInfoP->query != NULL;
}
Пример #6
0
unsigned short
AbyssServer::Session::port() const {

    const TRequestInfo * requestInfoP;

    SessionGetRequestInfo(this->implP->cSessionP, &requestInfoP);

    return requestInfoP->port;
}
Пример #7
0
bool
AbyssServer::Session::keepalive() const {

    const TRequestInfo * requestInfoP;

    SessionGetRequestInfo(this->implP->cSessionP, &requestInfoP);

    return requestInfoP->keepalive;
}
Пример #8
0
bool
AbyssServer::Session::userIsAuthenticated() const {

    const TRequestInfo * requestInfoP;

    SessionGetRequestInfo(this->implP->cSessionP, &requestInfoP);

    return requestInfoP->user != NULL;
}
Пример #9
0
string const
AbyssServer::Session::requestLine() const {

    const TRequestInfo * requestInfoP;

    SessionGetRequestInfo(this->implP->cSessionP, &requestInfoP);

    assert(requestInfoP->requestline);

    return string(requestInfoP->requestline);
}
Пример #10
0
string const
AbyssServer::Session::referer() const {

    const TRequestInfo * requestInfoP;

    SessionGetRequestInfo(this->implP->cSessionP, &requestInfoP);

    if (requestInfoP->referer)
        return string(requestInfoP->from);
    else
        throwf("Request header does not have a 'referer' field");
}
Пример #11
0
string const
AbyssServer::Session::host() const {

    const TRequestInfo * requestInfoP;

    SessionGetRequestInfo(this->implP->cSessionP, &requestInfoP);

    if (requestInfoP->host)
        return string(requestInfoP->host);
    else
        throwf("Request does not specify a host");
}
Пример #12
0
string const
AbyssServer::Session::uriQuery() const {

    const TRequestInfo * requestInfoP;

    SessionGetRequestInfo(this->implP->cSessionP, &requestInfoP);

    if (requestInfoP->query)
        return string(requestInfoP->query);
    else
        throwf("Request URI has no query part");
}
Пример #13
0
string const
AbyssServer::Session::useragent() const {

    const TRequestInfo * requestInfoP;

    SessionGetRequestInfo(this->implP->cSessionP, &requestInfoP);

    if (requestInfoP->from)
        return string(requestInfoP->useragent);
    else
        throwf("Request header does not have a 'useragent' field");
}
Пример #14
0
string const
AbyssServer::Session::user() const {

    const TRequestInfo * requestInfoP;

    SessionGetRequestInfo(this->implP->cSessionP, &requestInfoP);

    if (requestInfoP->user)
        return string(requestInfoP->user);
    else
        throwf("Request header does not identify a user or "
               "server could not authenticate the identity");
}
Пример #15
0
AbyssServer::Session::Method
AbyssServer::Session::method() const {

    const TRequestInfo * requestInfoP;

    SessionGetRequestInfo(this->implP->cSessionP, &requestInfoP);

    switch (requestInfoP->method) {
    case m_unknown: return METHOD_UNKNOWN;
    case m_get:     return METHOD_GET;
    case m_put:     return METHOD_PUT;
    case m_head:    return METHOD_HEAD;
    case m_post:    return METHOD_POST;
    case m_delete:  return METHOD_DELETE;
    case m_trace:   return METHOD_TRACE;
    case m_options: return METHOD_OPTIONS;
    }
}
Пример #16
0
/**************************************
* DispatchRequest
*       Busca el handler para procesar la peticion
**************************************/
int XmlRpcServer::DispatchRequest(TSession *ses)
{
	TRequestInfo *req;

	//Get request info
	SessionGetRequestInfo(ses,(const TRequestInfo**)&req);

	//Log it
	Log("-Dispatching [%s]\n",req->uri);


	//Obtenemos la uri
	string uri = req->uri;

	//Vamos a buscar en orden inverso
	LstHandlers::reverse_iterator it;

	//Check stop
	if (uri.find("/stop")==0)
	{
		//Stop
		Stop();
		//Devolvemos el error
		SendResponse(ses,200,SHUTDOWNMSG,strlen(SHUTDOWNMSG));
		//Exit
		return 1;
	}
	
	//Recorremos la lista
	for (it=lstHandlers.rbegin();it!=lstHandlers.rend();it++)	
	{
		//Si la uri empieza por la base del handler
		if (uri.find((*it).first)==0)
			//Ejecutamos el handler
			return (*it).second->ProcessRequest(req,ses);
	}

	//Devolvemos el error
	SendError(ses,404);

	//Exit
	return 1;
}
Пример #17
0
vector<string> const
AbyssServer::Session::uriPathNameSegment() const {

    const TRequestInfo * requestInfoP;

    SessionGetRequestInfo(this->implP->cSessionP, &requestInfoP);

    string const requestInfoUri(requestInfoP->uri);

    vector<string> retval;

    retval.reserve(10);  // A guess

    // There seems to be a weird design in which if the URI has an empty
    // path name, requestInfoP->uri is "*".  According to the RFC,
    // all URIs have a path name, and it may be empty.

    if (requestInfoUri == "*") {
        // empty path; no segments
    } else {
        string const pathName(requestInfoUri);

        if (pathName.length() < 1 || pathName[0] != '/')
            throwf("INTERNAL ERROR: SessionGetRequestInfo returned "
                   "'uri' field that does not begin with a slash: '%s'",
                   pathName.c_str());

        for (size_t p = 1; p < pathName.length(); ) {
            size_t const slashPos(pathName.find('/', p));

            size_t const segEnd(slashPos == string::npos ?
                                pathName.length() : slashPos);

            retval.push_back(pathName.substr(p, segEnd - p));

            p = slashPos == string::npos ? segEnd : slashPos + 1;
        }
    }
    return retval;
}
Пример #18
0
string const
AbyssServer::Session::uriPathName() const {
/*-----------------------------------------------------------------------------
   The path name from the URI for the HTTP request in this session.

   If the path name is empty (e.g. for URI http://example.com), this is a null
   string (in contrast to the Abyss C interface, in which it is "*").

   According to the URI RFC, RFC 3986, if the path name is
   "http://example.com/example.html", the path name is "/example.html" (note
   the leading slash), and that is what we return.
-----------------------------------------------------------------------------*/
    const TRequestInfo * requestInfoP;

    SessionGetRequestInfo(this->implP->cSessionP, &requestInfoP);

    string const requestInfoUri(requestInfoP->uri);

    // There seems to be a weird design in which if the URI has a null
    // string path name, requestInfoP->uri is "*".  According to the RFC,
    // all URIs have a path name, and it may be a null string.

    return requestInfoUri == "*" ? "" : requestInfoUri;
}