⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mod_imagemap.c

📁 Apache官方在今天放出产品系列2.2的最新版本2.2.11的源码包 最流行的HTTP服务器软件之一
💻 C
📖 第 1 页 / 共 2 页
字号:
                                   rid of it otherwise */        }    }                           /* by this point, value does not start                                   with '..' */    if (value && *value) {        return apr_pstrcat(r->pool, my_base, value, NULL);    }    return my_base;}static int imap_reply(request_rec *r, char *redirect){    if (!strcasecmp(redirect, "error")) {        /* they actually requested an error! */        return HTTP_INTERNAL_SERVER_ERROR;    }    if (!strcasecmp(redirect, "nocontent")) {        /* tell the client to keep the page it has */        return HTTP_NO_CONTENT;    }    if (redirect && *redirect) {        /* must be a URL, so redirect to it */        apr_table_setn(r->headers_out, "Location", redirect);        return HTTP_MOVED_TEMPORARILY;    }    return HTTP_INTERNAL_SERVER_ERROR;}static void menu_header(request_rec *r, char *menu){    ap_set_content_type(r, "text/html; charset=ISO-8859-1");    ap_rvputs(r, DOCTYPE_HTML_3_2, "<html><head>\n<title>Menu for ",               ap_escape_html(r->pool, r->uri),              "</title>\n</head><body>\n", NULL);    if (!strcasecmp(menu, "formatted")) {        ap_rvputs(r, "<h1>Menu for ",                   ap_escape_html(r->pool, r->uri),                  "</h1>\n<hr />\n\n", NULL);    }    return;}static void menu_blank(request_rec *r, char *menu){    if (!strcasecmp(menu, "formatted")) {        ap_rputs("\n", r);    }    if (!strcasecmp(menu, "semiformatted")) {        ap_rputs("<br />\n", r);    }    if (!strcasecmp(menu, "unformatted")) {        ap_rputs("\n", r);    }    return;}static void menu_comment(request_rec *r, char *menu, char *comment){    if (!strcasecmp(menu, "formatted")) {        ap_rputs("\n", r);         /* print just a newline if 'formatted' */    }    if (!strcasecmp(menu, "semiformatted") && *comment) {        ap_rvputs(r, comment, "\n", NULL);    }    if (!strcasecmp(menu, "unformatted") && *comment) {        ap_rvputs(r, comment, "\n", NULL);    }    return;                     /* comments are ignored in the                                   'formatted' form */}static void menu_default(request_rec *r, char *menu, char *href, char *text){    if (!strcasecmp(href, "error") || !strcasecmp(href, "nocontent")) {        return;                 /* don't print such lines, these aren't                                   really href's */    }    if (!strcasecmp(menu, "formatted")) {        ap_rvputs(r, "<pre>(Default) <a href=\"", href, "\">", text,               "</a></pre>\n", NULL);    }    if (!strcasecmp(menu, "semiformatted")) {        ap_rvputs(r, "<pre>(Default) <a href=\"", href, "\">", text,               "</a></pre>\n", NULL);    }    if (!strcasecmp(menu, "unformatted")) {        ap_rvputs(r, "<a href=\"", href, "\">", text, "</a>", NULL);    }    return;}static void menu_directive(request_rec *r, char *menu, char *href, char *text){    if (!strcasecmp(href, "error") || !strcasecmp(href, "nocontent")) {        return;                 /* don't print such lines, as this isn't                                   really an href */    }    if (!strcasecmp(menu, "formatted")) {        ap_rvputs(r, "<pre>          <a href=\"", href, "\">", text,               "</a></pre>\n", NULL);    }    if (!strcasecmp(menu, "semiformatted")) {        ap_rvputs(r, "<pre>          <a href=\"", href, "\">", text,               "</a></pre>\n", NULL);    }    if (!strcasecmp(menu, "unformatted")) {        ap_rvputs(r, "<a href=\"", href, "\">", text, "</a>", NULL);    }    return;}static void menu_footer(request_rec *r){    ap_rputs("\n\n</body>\n</html>\n", r);         /* finish the menu */}static int imap_handler_internal(request_rec *r){    char input[MAX_STRING_LEN];    char *directive;    char *value;    char *href_text;    char *base;    char *redirect;    char *mapdflt;    char *closest = NULL;    double closest_yet = -1;    apr_status_t status;    double testpoint[2];    double pointarray[MAXVERTS + 1][2];    int vertex;    char *string_pos;    int showmenu = 0;    imap_conf_rec *icr;    char *imap_menu;    char *imap_default;    char *imap_base;    ap_configfile_t *imap;    icr = ap_get_module_config(r->per_dir_config, &imagemap_module);    imap_menu = icr->imap_menu ? icr->imap_menu : IMAP_MENU_DEFAULT;    imap_default = icr->imap_default      ?  icr->imap_default : IMAP_DEFAULT_DEFAULT;    imap_base = icr->imap_base ? icr->imap_base : IMAP_BASE_DEFAULT;    status = ap_pcfg_openfile(&imap, r->pool, r->filename);    if (status != APR_SUCCESS) {        return HTTP_NOT_FOUND;    }    base = imap_url(r, NULL, imap_base);         /* set base according                                                    to default */    if (!base) {        return HTTP_INTERNAL_SERVER_ERROR;    }    mapdflt = imap_url(r, NULL, imap_default);   /* and default to                                                    global default */    if (!mapdflt) {        return HTTP_INTERNAL_SERVER_ERROR;    }    testpoint[X] = get_x_coord(r->args);    testpoint[Y] = get_y_coord(r->args);    if ((testpoint[X] == -1 || testpoint[Y] == -1) ||        (testpoint[X] == 0 && testpoint[Y] == 0)) {        /* if either is -1 or if both are zero (new Lynx) */        /* we don't have valid coordinates */        testpoint[X] = -1;        testpoint[Y] = -1;        if (strncasecmp(imap_menu, "none", 2)) {            showmenu = 1;       /* show the menu _unless_ ImapMenu is                                   'none' or 'no' */        }    }    if (showmenu) {             /* send start of imagemap menu if                                   we're going to */        menu_header(r, imap_menu);    }    while (!ap_cfg_getline(input, sizeof(input), imap)) {        if (!input[0]) {            if (showmenu) {                menu_blank(r, imap_menu);            }            continue;        }        if (input[0] == '#') {            if (showmenu) {                menu_comment(r, imap_menu, input + 1);            }            continue;        }                       /* blank lines and comments are ignored                                   if we aren't printing a menu */        /* find the first two space delimited fields, recall that         * ap_cfg_getline has removed leading/trailing whitespace.         *         * note that we're tokenizing as we go... if we were to use the         * ap_getword() class of functions we would end up allocating extra         * memory for every line of the map file         */        string_pos = input;        if (!*string_pos) {   /* need at least two fields */            goto need_2_fields;        }        directive = string_pos;        while (*string_pos && !apr_isspace(*string_pos)) {   /* past directive */            ++string_pos;        }        if (!*string_pos) {   /* need at least two fields */            goto need_2_fields;        }        *string_pos++ = '\0';        if (!*string_pos) {   /* need at least two fields */            goto need_2_fields;        }        while(*string_pos && apr_isspace(*string_pos)) { /* past whitespace */            ++string_pos;        }        value = string_pos;        while (*string_pos && !apr_isspace(*string_pos)) {   /* past value */            ++string_pos;        }        if (apr_isspace(*string_pos)) {            *string_pos++ = '\0';        }        else {            /* end of input, don't advance past it */            *string_pos = '\0';        }        if (!strncasecmp(directive, "base", 4)) {       /* base, base_uri */            base = imap_url(r, NULL, value);            if (!base) {                goto menu_bail;            }            continue;           /* base is never printed to a menu */        }        read_quoted(&string_pos, &href_text);        if (!strcasecmp(directive, "default")) {        /* default */            mapdflt = imap_url(r, NULL, value);            if (!mapdflt) {                goto menu_bail;            }            if (showmenu) {     /* print the default if there's a menu */                redirect = imap_url(r, base, mapdflt);                if (!redirect) {                    goto menu_bail;                }                menu_default(r, imap_menu, redirect,                             href_text ? href_text : mapdflt);            }            continue;        }        vertex = 0;        while (vertex < MAXVERTS &&               sscanf(string_pos, "%lf%*[, ]%lf",                      &pointarray[vertex][X], &pointarray[vertex][Y]) == 2) {            /* Now skip what we just read... we can't use ANSIism %n */            while (apr_isspace(*string_pos)) {      /* past whitespace */                string_pos++;            }            while (apr_isdigit(*string_pos)) {      /* and the 1st number */                string_pos++;            }            string_pos++;       /* skip the ',' */            while (apr_isspace(*string_pos)) {      /* past any more whitespace */                string_pos++;            }            while (apr_isdigit(*string_pos)) {      /* 2nd number */                string_pos++;            }            vertex++;        }                       /* so long as there are more vertices to                                   read, and we have room, read them in.                                   We start where we left off of the last                                   sscanf, not at the beginning. */        pointarray[vertex][X] = -1;     /* signals the end of vertices */        if (showmenu) {            if (!href_text) {                read_quoted(&string_pos, &href_text);     /* href text could                                                             be here instead */            }            redirect = imap_url(r, base, value);            if (!redirect) {                goto menu_bail;            }            menu_directive(r, imap_menu, redirect,                           href_text ? href_text : value);            continue;        }        /* note that we don't make it past here if we are making a menu */        if (testpoint[X] == -1 || pointarray[0][X] == -1) {            continue;           /* don't try the following tests if testpoints                                   are invalid, or if there are no                                   coordinates */        }        if (!strcasecmp(directive, "poly")) {   /* poly */            if (pointinpoly(testpoint, pointarray)) {                ap_cfg_closefile(imap);                redirect = imap_url(r, base, value);                if (!redirect) {                    return HTTP_INTERNAL_SERVER_ERROR;                }                return (imap_reply(r, redirect));            }            continue;        }        if (!strcasecmp(directive, "circle")) {         /* circle */            if (pointincircle(testpoint, pointarray)) {                ap_cfg_closefile(imap);                redirect = imap_url(r, base, value);                if (!redirect) {                    return HTTP_INTERNAL_SERVER_ERROR;                }                return (imap_reply(r, redirect));            }            continue;        }        if (!strcasecmp(directive, "rect")) {   /* rect */            if (pointinrect(testpoint, pointarray)) {                ap_cfg_closefile(imap);                redirect = imap_url(r, base, value);                if (!redirect) {                    return HTTP_INTERNAL_SERVER_ERROR;                }                return (imap_reply(r, redirect));            }            continue;        }        if (!strcasecmp(directive, "point")) {  /* point */            if (is_closer(testpoint, pointarray, &closest_yet)) {                closest = apr_pstrdup(r->pool, value);            }            continue;        }                       /* move on to next line whether it's                                   closest or not */    }                           /* nothing matched, so we get another line! */    ap_cfg_closefile(imap);        /* we are done with the map file; close it */    if (showmenu) {        menu_footer(r);         /* finish the menu and we are done */        return OK;    }    if (closest) {             /* if a 'point' directive has been seen */        redirect = imap_url(r, base, closest);        if (!redirect) {            return HTTP_INTERNAL_SERVER_ERROR;        }        return (imap_reply(r, redirect));    }    if (mapdflt) {             /* a default should be defined, even if                                  only 'nocontent' */        redirect = imap_url(r, base, mapdflt);        if (!redirect) {            return HTTP_INTERNAL_SERVER_ERROR;        }        return (imap_reply(r, redirect));    }    return HTTP_INTERNAL_SERVER_ERROR;        /* If we make it this far,                                                 we failed. They lose! */need_2_fields:    ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,                "map file %s, line %d syntax error: requires at "                "least two fields", r->uri, imap->line_number);    /* fall through */menu_bail:    ap_cfg_closefile(imap);    if (showmenu) {        /* There's not much else we can do ... we've already sent the headers         * to the client.         */        ap_rputs("\n\n[an internal server error occured]\n", r);        menu_footer(r);        return OK;    }    return HTTP_INTERNAL_SERVER_ERROR;}static int imap_handler(request_rec *r){    /* Optimization: skip the allocation of large local variables on the     * stack (in imap_handler_internal()) on requests that aren't using     * imagemaps     */    if (r->method_number != M_GET || (strcmp(r->handler,IMAP_MAGIC_TYPE)                                      && strcmp(r->handler, "imap-file"))) {        return DECLINED;    }    else {        return imap_handler_internal(r);    }}static void register_hooks(apr_pool_t *p){    ap_hook_handler(imap_handler,NULL,NULL,APR_HOOK_MIDDLE);}module AP_MODULE_DECLARE_DATA imagemap_module ={    STANDARD20_MODULE_STUFF,    create_imap_dir_config,     /* dir config creater */    merge_imap_dir_configs,     /* dir merger --- default is to override */    NULL,                       /* server config */    NULL,                       /* merge server config */    imap_cmds,                  /* command apr_table_t */    register_hooks              /* register hooks */};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -