int otype_imgswitch(pblock *pb, Session *sn, Request *rq)
{
    char *ct, *ua, *pa, *npath, *t;
    struct stat fi;
    pb_param *pp;

    /* This routine might be cacheable.  Lets check the objtype so
     * far to see if we are talking about an image file.  If this path
     * is not an image, we can go ahead and cache.
     */
    rq->directive_is_cacheable = 1;

    if(!(ct = pblock_findval("content-type", rq->srvhdrs)))
        return REQ_NOACTION;
    if(strncasecmp(ct, "image/", 6))
        return REQ_NOACTION;

    /* This routine is still running, so it must be an image we are
     * dealing with.  This is not cacheable since we need the user-agent
     * info to determine which file we return.
     */
    rq->directive_is_cacheable=0;

    /* In the absence of a capabilities header, use user-agent */
    if(request_header("user-agent", &ua, sn, rq) == REQ_ABORTED)
        return REQ_ABORTED;
    /* We want to be nice to proxies */
    if(request_header("proxy-agent", &pa, sn, rq) == REQ_ABORTED)
        return REQ_ABORTED;

    if((!ua) || pa || strstr(ua, "roxy"))
        return REQ_NOACTION;

    /* Look for jpeg if we're talking to mozilla and image is .gif */
    if((!strncasecmp(ua, "mozilla", 7)) && (!strcasecmp(ct, "image/gif"))) {
        npath = STRDUP(pblock_findval("path", rq->vars));
        if(!(t = strstr(npath, ".gif")))
            return REQ_NOACTION;
        t[1] = 'j'; t[2] = 'p'; t[3] = 'g';
        if(stat(npath, &fi) == -1) {
            FREE(npath);
            return REQ_NOACTION;
        }
        pp = pblock_find("path", rq->vars);
        FREE(pp->value);
        pp->value = npath;

        /* don't check return; it should work. */
        request_stat_path(npath, rq);

        pp = pblock_find("content-type", rq->srvhdrs);
        FREE(pp->value);
        pp->value = STRDUP("image/jpeg");

        return REQ_PROCEED;
    }
    return REQ_NOACTION;
}
static inline void otype_ciadd(const char *c, pblock *srvhdrs, const char *name)
{
    if (c) {
        if (!pblock_find(name, srvhdrs))
            pblock_nvinsert(name, c, srvhdrs);
    }
}
static inline void otype_add(pblock *pb, const pb_key *config, pblock *srvhdrs, const char *header)
{
    char *value = pblock_findkeyval(config, pb);
    if (value) {
        if (!pblock_find(header, srvhdrs))
            pblock_nvinsert(header, value, srvhdrs);
    }
}
示例#4
0
NSAPI_PUBLIC int
add_agent_header(pblock *param, Session *sn, Request *rq)
{
    const char *thisfunc = "add_agent_header()";
    int  requestResult = REQ_ABORTED;
    char *host         = NULL ;
    char *host_name    = NULL;
    void *args[]       = { (void *)rq };
    am_status_t ret    = AM_FAILURE;
    char *header_str   = NULL;

    // NSAPI function pblock_pblock2str expects "full-headers" 
    // to be non-null value. Therefore, add a logic to check whether 
    // "full-headers" is null and if it is, return error to the client.
    // - Forward port of fix in CRT (657).
    pb_param *hdr_pp = pblock_find("full-headers", rq->reqpb);
    if (hdr_pp != NULL && hdr_pp->value == NULL) {
        am_web_log_error ("add_agent_header():Header not found.");
        return REQ_ABORTED;
    }

    header_str   = pblock_pblock2str(rq->reqpb, NULL);

    am_web_log_max_debug("%s: Headers: %s", thisfunc, header_str);
    system_free(header_str);
    requestResult = request_header ("host",&host,sn,rq );
    if (REQ_PROCEED == requestResult && host != NULL) {
        host_name = strdup (host);
        if (host_name == NULL){
            am_web_log_debug("%s: Unable to allocate memory for host_name",
                              thisfunc);
            am_web_free_memory(host);
            return REQ_ABORTED;
        }
        am_web_log_max_debug("%s: Host = %s ", thisfunc, host_name);
        ret = set_header("ampxy_host",host_name,args);
        if (ret == AM_SUCCESS) {
            header_str = pblock_pblock2str(rq->reqpb, NULL);
            am_web_log_max_debug("%s: headers = %s", thisfunc, header_str);
            system_free(header_str);
            requestResult = REQ_NOACTION;
            am_web_log_max_debug("%s: Host replace success %d ", thisfunc,
                                  requestResult);
        } else {
            am_web_log_max_debug("%s: Host replace failed", thisfunc);
        }
        if(host_name != NULL) {
            free(host_name);
        }
    } else {
        am_web_log_error ("%s: Header not found.", thisfunc);
    }

    return requestResult;
}
/* Sigh. Another stupid pet trick that will get dropped on the floor */
int otype_htmlswitch(pblock *pb, Session *sn, Request *rq)
{
    char *ct, *ua, *pa, *npath, *t;
    struct stat fi;
    pb_param *pp;

    /* This routine might be cacheable.  Lets check the objtype so
     * far to see if we are talking about a text file.  If this path
     * is not a text, we can go ahead and cache.
     */
    rq->directive_is_cacheable = 1;

    if(!(ct = pblock_findval("content-type", rq->srvhdrs)))
        return REQ_NOACTION;
    if(strncasecmp(ct, "text/", 5))
        return REQ_NOACTION;

    /* This is still running, so it must be a text file we are
     * dealing with.  This is not cacheable since we need the user-agent
     * info to determine which file we return.
     */
    rq->directive_is_cacheable = 0;

    /* In the absence of a capabilities header, use user-agent */
    if(request_header("user-agent", &ua, sn, rq) == REQ_ABORTED)
        return REQ_ABORTED;
    /* We want to be nice to proxies */
    if(request_header("proxy-agent", &pa, sn, rq) == REQ_ABORTED)
        return REQ_ABORTED;

    if((!ua) || pa || strstr(ua, "roxy"))
        return REQ_NOACTION;

    /* Look for html3 if we're talking to mozilla and find HTML */
    if(util_is_mozilla(ua, "1", "1") && (!strcasecmp(ct, "text/html"))) {
        t = pblock_findval("path", rq->vars);
        npath = (char *) MALLOC(strlen(t) + 1 + 1);
        util_sprintf(npath, "%s3", t);
        if(stat(npath, &fi) == -1) {
            FREE(npath);
            return REQ_NOACTION;
        }
        pp = pblock_find("path", rq->vars);
        FREE(pp->value);
        pp->value = npath;

        /* don't check return; it should work. */
        request_stat_path(npath, rq);
        return REQ_PROCEED;
    }
    return REQ_NOACTION;
}
NSAPI_PUBLIC PRBool conf_setGlobal(char *name, char *value)
{
    pblock *globals = conf_get_true_globals()->genericGlobals;

    char *d = _lowercase(name);

    if (pblock_find(d, globals)) {
        // Mark directive as multiply defined
        pblock_nvinsert(d, name, globalsMultiplyDefined);
        param_free(pblock_remove(d, globals));
    } else {
        // Mark directive as unaccessed
        pblock_nvinsert(d, name, globalsUnaccessed);
    }

    PRBool rv = (pblock_nvinsert(d, value, globals) != NULL);

    FREE(d);

    return rv;
}
示例#7
0
static am_status_t set_header(const char *key, const char *values,
                              void **args) {
    Request *rq = (Request *)args[0];
    pb_param *hdr_pp = pblock_find("full-headers", rq->reqpb);
    const char *the_key = key;

    if (hdr_pp != NULL) {
	if(values != NULL && *values != '\0') { //Added by bn152013 for 6739097
            int append = 0;
            int length = strlen(the_key) + strlen(values) + 5;
            if (hdr_pp->value != NULL) {
                size_t len = strlen(hdr_pp->value);
                length += len;
                append = 1;
                hdr_pp->value = (char *) system_realloc(hdr_pp->value, length);
                hdr_pp->value[len] = '\0';
            } else {
                hdr_pp->value = (char *) system_malloc(length);
                hdr_pp->value[0]='\0';
            }

            if ( hdr_pp->value == NULL) {
                return (AM_NO_MEMORY);
            }

            if (append)
                strcat(hdr_pp->value, the_key);
            else
                strcpy(hdr_pp->value, the_key);


            strcat(hdr_pp->value, ": ");
            strcat(hdr_pp->value, values);
            strcat(hdr_pp->value, "\r\n");
        } else {
            if(key[0] != '\0' && hdr_pp->value != NULL) {
                char *ptr = strstr(hdr_pp->value, the_key);
                if(ptr != NULL) {
                    char *end_ptr = ptr + strlen(the_key);
                    while(*end_ptr != '\r' && *end_ptr != '\n')
                        ++end_ptr;

                    end_ptr += 2;

                    while(*end_ptr != '\0') {
                        *ptr = *end_ptr;
                        ptr += 1;
                        end_ptr += 1;
                    }
                    *ptr = '\0';
                }
            }
        }
    }

    if(values != NULL && *values != '\0') { //Added by bn152013 for 6739097
        pblock_nvinsert(the_key, (char *)values, rq->headers);
    } else {
        param_free(pblock_remove(the_key, rq->headers));
    }
    return (AM_SUCCESS);
}