Ejemplo n.º 1
0
static HTTPResponse *_errorResponse(WOAppReq *app, WOURLComponents *wc, HTTPRequest *req)
{
   HTTPResponse *resp;
   const char *redirect_url = &app->redirect_url[0];

   WOLog(WO_ERR,"Request handling error: %s",_errors[app->error]);

   if (app->redirect_url[0] == 0)
      redirect_url = adaptor_valueForKey(WOERRREDIR);

   /*
    *	try to do the right thing...
    */
   if (redirect_url != NULL) {
      resp = resp_redirectedResponse(redirect_url);
   } else if (app->error == err_notFound) {
      if (ac_authorizeAppListing(wc))
         resp = WOAdaptorInfo(NULL, wc);
      else {
         resp = resp_errorResponse(NOT_FOUND_APP, HTTP_NOT_FOUND);
         if (resp->statusMsg)	WOFREE(resp->statusMsg);
         resp->statusMsg = WOSTRDUP("File Not Found");
      }
   } else
       resp = resp_errorResponse(_errors[app->error], HTTP_SERVER_ERROR);

   if (resp)
   {
      st_add(resp->headers, "Cache-Control", "no-cache, private, no-store, must-revalidate, max-age=0", 0);
      st_add(resp->headers, "Expires", "Thu, 01 Jan 1970 00:00:00 GMT", 0);
      st_add(resp->headers, "date", "Thu, 01 Jan 1970 00:00:00 GMT", 0);
      st_add(resp->headers, "pragma", "no-cache", 0);
   }
   return resp;
}
Ejemplo n.º 2
0
static DWORD die(EXTENSION_CONTROL_BLOCK *p, const char *msg, int status)
{
   HTTPResponse *resp;
   WOLog(WO_ERR,"Sending aborting request - %s",msg);
   resp = resp_errorResponse(msg, status);
   return die_resp(p, resp);
}
Ejemplo n.º 3
0
static int die(Session *sn, Request *rq, const char *msg, int status)
{
   HTTPResponse *resp;

   log_error(0,"WebObjects",NULL,NULL,"Aborting request - %s",msg);
   resp = resp_errorResponse(msg, status);
   return die_resp(sn, rq, resp);
}
Ejemplo n.º 4
0
/*
 *	finish the job that the api stubs started..
 */
static HTTPResponse *_collectRequestInformation(WOAppReq *app, WOURLComponents *wc, const char *url, int urlVersion, HTTPRequest *req)
{
   const char *urlerr;
   /*
    *	we need to complete the URL parsing...
    */
   if ((urlVersion == 4) || (urlVersion == 3)) {
      urlerr = WOParseAndCheckURL(wc, url, urlVersion, req->shouldProcessUrl);
   } else {
      urlerr = "Unsupported URL version";
      WOLog(WO_WARN, "Unsupported URL version (%d) on %s", urlVersion, app->name);
   }

   if (urlerr != NULL)
      return resp_errorResponse(urlerr, HTTP_BAD_REQUEST);

   /*
    *	pick up the app name & host (if any) & instance
    */
   if (wc->applicationName.length == 0)
       return resp_errorResponse(NO_APPNAME, HTTP_BAD_REQUEST);

   strncpy(app->name, wc->applicationName.start, wc->applicationName.length);
   app->name[wc->applicationName.length] = '\0';
   if (app->name[wc->applicationName.length - 1] == '/')	/* garbage? */
       app->name[wc->applicationName.length - 1] = '\0';

       if (wc->applicationHost.length > 0) {
          strncpy(app->host, wc->applicationHost.start, wc->applicationHost.length);
          app->host[wc->applicationHost.length] = '\0';
       } else
       app->host[0] = '\0';

       /*
        *	is the session/application information in the URL?
        *	if not, look in the cookies for the application instance number
        *	in the cookies.
        */
       app->instance[0] = 0; /* default to any instance */
       if (wc->applicationNumber.length > 0) {
          if (wc->applicationNumber.length < WA_MAX_INSTANCE_NUMBER_LENGTH)
          {
             memcpy(app->instance, wc->applicationNumber.start, wc->applicationNumber.length);
             app->instance[wc->applicationNumber.length] = 0;
          }
       } else {
          const char *cookie, *woinst;

          cookie = req_HeaderForKey(req, COOKIE);
          if (cookie && ((woinst = strstr(cookie, INST_COOKIE)) != NULL)) {
             const char *instid = &woinst[sizeof(INST_COOKIE)-1];
             int len = 0;
             while (len < WA_MAX_INSTANCE_NUMBER_LENGTH && instid[len] != ';' && instid[len])
                len++;
             if (len < WA_MAX_INSTANCE_NUMBER_LENGTH)
             {
                memcpy(app->instance, instid, len);
                app->instance[len] = 0;
             }

			 // remove any quotes from the instance number
#ifdef _MSC_VER // SWK Start VC can't define attributes here using '{' fixed it
			 {
#endif
			 char *before, *after;
			 before = after = app->instance;
			 while(*before){
			 	if((*before == '\'') || (*before == '"')){
					before++;
				}
				*after++ = *before++;
			 }
			 *after = 0;
#ifdef _MSC_VER // SWK End
			 }
#endif
             WOLog(WO_INFO,"Cookie instance %s from %s",app->instance,cookie);
          }
       }

       app->urlVersion = (wc->webObjectsVersion.start) ?
       atoi(wc->webObjectsVersion.start) : CURRENT_WOF_VERSION_MAJOR;

       /*
        *	Add the adaptor identifier header.
        *  WOFramework checks for the presence of this header, so the name should not change.
        *  (The value of the header is ignored by WOFramework.)
        */
       req_addHeader(req, "x-webobjects-adaptor-version", WA_adaptorName, 0);

       return NULL;  /* no errors */
}
Ejemplo n.º 5
0
static void prepareAndSendErrorResponse(const char *msg, int status)
{
   HTTPResponse *resp = resp_errorResponse(msg, status);
   sendErrorResponse(resp);
}