コード例 #1
0
ファイル: web_agent.c プロジェクト: dromero91/openam
int send_data(const char *msg, Session *sn, Request *rq) {
    int len = msg != NULL?strlen(msg):0;
    int retVal = REQ_ABORTED;

    if(len > 0) {
        char buf[50];
        buf[0] = '\0';
        sprintf(buf, "%d", len);
        protocol_status(sn, rq, PROTOCOL_OK, NULL); 
        param_free(pblock_remove("content-type", rq->srvhdrs));
        pblock_nvinsert("content-type", "text/html", rq->srvhdrs); 
        pblock_nvinsert("content-length", buf, rq->srvhdrs); 
    
        /* Send the headers to the client*/
        protocol_start_response(sn, rq);
    
        /* Write the output using net_write*/
        if (IO_ERROR == net_write(sn->csd, (char *)msg, len)) {
            retVal = REQ_EXIT; 
        } else {
            retVal = net_flush(sn->csd);
        }

    }
    return retVal; 
}
コード例 #2
0
ファイル: web_agent.c プロジェクト: dromero91/openam
static int process_new_notification(pblock *param,
                                    Session *sn,
                                    Request *rq,
                                    void* agent_config)
{
    handle_notification(sn, rq, agent_config);

    /* Use the protocol_status function to set the status of the
     * response before calling protocol_start_response.
     */
    protocol_status(sn, rq, PROTOCOL_OK, NULL);

    /* Although we would expect the ObjectType stage to
     * set the content-type, set it here just to be
     * completely sure that it gets set to text/html.
     */
    param_free(pblock_remove("content-type", rq->srvhdrs));
    pblock_nvinsert("content-type", "text/html", rq->srvhdrs);

    pblock_nvinsert("content-length", "2", rq->srvhdrs);

    /* Send the headers to the client*/
    protocol_start_response(sn, rq);

    /* Write the output using net_write*/
    if (IO_ERROR == net_write(sn->csd, "OK", 2)) {
        return REQ_EXIT;
    }
    return REQ_PROCEED;
}
コード例 #3
0
ファイル: WebObjects.c プロジェクト: LaurentDavery/wonder
static int sendResponse(Session *sn, Request *rq, HTTPResponse *resp)
{
   pb_param *pb_entry;

   /*
    *	collect up the headers
    */
   pb_entry = pblock_remove(CONTENT_TYPE,rq->srvhdrs);			/* remove default */
   param_free(pb_entry);			/* aB. Need to free parameters we remove from pblocks !!! */
   st_perform(resp->headers,gethdr,rq);

   /*
    *	ensure a content length
    */
   if (pblock_findval(CONTENT_LENGTH, rq->srvhdrs) == NULL) {
      char length[64];
      util_itoa(resp->content_length,length);
      pblock_nvinsert(CONTENT_LENGTH,length, rq->srvhdrs);
   }

   protocol_status(sn, rq, resp->status, resp->statusMsg);

   if (protocol_start_response(sn, rq) == REQ_NOACTION) {
      WOLog(WO_ERR,"protocol_start_response() returned REQ_NOACTION (!?)");
      return REQ_PROCEED;
   }

   if (resp->content_length)
      if (net_write(sn->csd, resp->content, resp->content_length) == IO_ERROR) {
         WOLog(WO_ERR,"Failed to send content to client");
         return REQ_EXIT;
      }

         return REQ_PROCEED;
}
コード例 #4
0
ファイル: web_agent.c プロジェクト: dromero91/openam
/**
 * This function is used for sending a 302 redirect in the browser.
 */
static void do_url_redirect(Session *sn, Request *rq, char* redirect_url)
{
    /* Set the return code to 302 Redirect */
    protocol_status(sn, rq, PROTOCOL_REDIRECT, NULL);

    /* set the new URL to redirect */
    pblock_nvinsert("escape", "no", rq->vars);

    param_free(pblock_remove("Location", rq->srvhdrs));
    pblock_nvinsert("Location", redirect_url, rq->srvhdrs);
    protocol_start_response(sn, rq);
}
コード例 #5
0
int service_reconfig(pblock *pb, Session *sn, Request *rq)
{
    param_free(pblock_remove("content-type", rq->srvhdrs));
    pblock_nvinsert("content-type", "text/html", rq->srvhdrs);
    protocol_status(sn, rq, PROTOCOL_OK, NULL);
    protocol_start_response(sn, rq);

    PR_fprintf(sn->csd, "<html><head><title>"
                        "Dynamic Reconfiguration"
                        "</title></head><body>\n"
                        "<H2>Dynamic Reconfiguration</H2>\n"
                        "<p>pid: %d</p>\n", getpid());

    // Asynchronous reconfiguration
    WebServer::RequestReconfiguration();

    PR_fprintf(sn->csd, "</body></html>");

    return REQ_PROCEED;
}
コード例 #6
0
int service_dumpstats(pblock *pb, Session *sn, Request *rq)
{
    char *refresh, *refresh_val = NULL;

    /* See if client asked for automatic refresh in query string */
    if ((refresh = pblock_findval("query", rq->reqpb)) != NULL ) {
        if (!strncmp("refresh", refresh, 7)) {
             refresh_val = strchr(refresh, '=');
             if (refresh_val)
                 refresh_val++;
        }
    }

    param_free(pblock_remove("content-type", rq->srvhdrs));
    pblock_nvinsert("content-type", "text/plain", rq->srvhdrs);
    if (refresh_val)
        pblock_nvinsert("refresh", refresh_val, rq->srvhdrs);
    httpfilter_buffer_output(sn, rq, PR_TRUE);
    protocol_status(sn, rq, PROTOCOL_OK, NULL);
    protocol_start_response(sn,rq);

    PR_fprintf(sn->csd, PRODUCT_DAEMON_BIN" pid: %d\n", getpid());

    StatsHeaderNode *hdr = StatsManager::getHeader();

    if (!hdr) {
        PR_fprintf(sn->csd, "\nStatistics disabled\n");
        return REQ_PROCEED;
    }
    int rv = REQ_PROCEED;
#ifdef XP_WIN32
    rv = write_stats_dump(sn->csd, hdr);
#else
    if (hdr && (hdr->hdrStats.maxProcs == 1)) {
        rv = write_stats_dump(sn->csd, hdr);
    } else {
        StatsManager::serviceDumpStats(sn->csd, NULL);
    }
#endif
    return rv;
}
コード例 #7
0
ファイル: web_agent.c プロジェクト: dromero91/openam
static int do_redirect(Session *sn, Request *rq, am_status_t status,
        am_policy_result_t *policy_result,
        const char *original_url, const char* method,
        void* agent_config) {
    int retVal = REQ_ABORTED;
    char *redirect_url = NULL;
    const am_map_t advice_map = policy_result->advice_map;
    am_status_t ret = AM_SUCCESS;

    ret = am_web_get_url_to_redirect(status, advice_map,
            original_url, method,
            AM_RESERVED, &redirect_url, agent_config);

    if (ret == AM_SUCCESS && redirect_url != NULL) {
        char *advice_txt = NULL;
        if (B_FALSE == am_web_use_redirect_for_advice(agent_config) && policy_result->advice_string != NULL) {
            // Composite advice is sent as a POST
            ret = am_web_build_advice_response(policy_result, redirect_url,
                    &advice_txt);
            am_web_log_debug("do_redirect(): policy status=%s,",
                    "response[%s]", am_status_to_string(status),
                    advice_txt);
            if (ret == AM_SUCCESS) {
                retVal = send_data(advice_txt, sn, rq);
            } else {
                am_web_log_error("do_redirect(): Error while building "
                        "advice response body:%s",
                        am_status_to_string(ret));
                retVal = REQ_EXIT;
            }
        } else {
            // No composite advice or composite advice is redirected
            am_web_log_debug("do_redirect() policy status = %s, ",
                    "redirection URL is %s",
                    am_status_to_string(status), redirect_url);

            // we need to modify the redirect_url with the policy advice
            if (B_TRUE == am_web_use_redirect_for_advice(agent_config) &&
                    policy_result->advice_string != NULL) {
                char *redirect_url_with_advice = NULL;
                ret = am_web_build_advice_redirect_url(policy_result,
                        redirect_url, &redirect_url_with_advice);
                if (ret == AM_SUCCESS) {
                    redirect_url = redirect_url_with_advice;
                    am_web_log_debug("do_redirect(): policy status=%s, "
                            "redirect url with advice [%s]",
                            am_status_to_string(status),
                            redirect_url);
                } else {
                    am_web_log_error("do_redirect(): Error while building "
                            "the redirect url with advice:%s",
                            am_status_to_string(ret));
                }
            }

            /* redirection is enabled by the PathCheck directive */
            /* Set the return code to 302 Redirect */
            protocol_status(sn, rq, PROTOCOL_REDIRECT, NULL);

            /* set the new URL to redirect */
            //pblock_nvinsert("url", redirect_url, rq->vars);
            pblock_nvinsert("escape", "no", rq->vars);

            param_free(pblock_remove("Location", rq->srvhdrs));
            pblock_nvinsert("Location", redirect_url, rq->srvhdrs);
            protocol_start_response(sn, rq);

            am_web_free_memory(redirect_url);
        }
    } else if (ret == AM_NO_MEMORY) {
        /* Set the return code 500 Internal Server Error. */
        protocol_status(sn, rq, PROTOCOL_SERVER_ERROR, NULL);
        am_web_log_error("do_redirect() Status code= %s.",
                am_status_to_string(status));
    } else {
        /* Set the return code 403 Forbidden */
        protocol_status(sn, rq, PROTOCOL_FORBIDDEN, NULL);
        am_web_log_info("do_redirect() Status code= %s.",
                am_status_to_string(status));
    }

    return retVal;
}