Пример #1
0
static void
call(char *func, FILE *stream)
{
	char *args, *end, *next;
	int argc;
	char * argv[16];
	struct ej_handler *handler;

	/* Parse out ( args ) */
	if (!(args = strchr(func, '(')))
		return;
	if (!(end = unqstrstr(func, ")")))
		return;
	*args++ = *end = '\0';

	/* Set up argv list */
	for (argc = 0; argc < 16 && args && *args; argc++, args = next) {
		if (!(argv[argc] = get_arg(args, &next)))
			break;
	}

	/* Call handler */
	for (handler = &ej_handlers[0]; handler->pattern; handler++) {
		if (strncmp(handler->pattern, func, strlen(handler->pattern)) == 0)
			handler->output(0, stream, argc, argv);
	}
}
Пример #2
0
// Call this function if and only if we can read whole <%....%> pattern.
static char *
process_asp (char *s, char *e, FILE *f)
{
	char *func = NULL, *end = NULL;

	if (s == NULL || e == NULL || f == NULL || s >= e)      {
		return NULL;
	}

	for (func = s; func < e; func = end) {
		/* Skip initial whitespace */
		for (; isspace((int)*func); func++);
		if (!(end = unqstrstr(func, ";")))
			break;
		*end++ = '\0';

		/* Call function */
		call(func, f);

		// skip asp_mark2
		end = e + strlen (asp_mark2);
		break;
	}
	return end;
}
Пример #3
0
static char *
get_arg(char *args, char **next)
{
	char *arg, *end;

	/* Parse out arg, ... */
	if (!(end = unqstrstr(args, ","))) {
		end = args + strlen(args);
		*next = NULL;
	} else
		*next = end + 1;

	/* Skip whitespace and quotation marks on either end of arg */
	for (arg = args; isspace((int)*arg) || *arg == '"'; arg++);
	for (*end-- = '\0'; isspace((int)*end) || *end == '"'; end--)
		*end = '\0';

	return arg;
}
Пример #4
0
Файл: ej.c Проект: jhbsz/LC4
void
call(char *func, INPUT *input)
{
    char *args, *end, *next;
    int argc;
    char *argv[16];
    struct ej_handler *handler;

    /* Parse out ( args ) */
    if (!(args = strchr(func, '(')))
        return;
    if (!(end = unqstrstr(func, ")")))
        return;
    *args++ = *end = '\0';

    /* Set up argv list */
    for (argc = 0; args && *args && argc < 16; argc++, args = next) {
        if (!(argv[argc] = get_arg(args, &next)))
            break;
    }

    /* Call handler */
    for (handler = &ej_handlers[0]; handler->pattern; handler++) {
        if (strcmp(handler->pattern, func) == 0) {
#ifdef DEBUG
            printf("Found handler: %s\n", func);
#endif

            handler->output(0, input, argc, argv);
            return;
        }
    }

    /* EZP: handler->pattern must be NULL after finishing the loop. */
#ifdef DEBUG
    printf("Not found handler: %s\n", func);
#endif
}
Пример #5
0
static void do_ej_s(int (*get) (void), webs_t stream)	// jimmy, https, 8/4/2003
{
	int c, ret;
	char *pattern, *asp = NULL, *func = NULL, *end = NULL;
	int len = 0;
	memdebug_enter();
	FILE *backup_fp = s_fp;
	int backup_filecount = s_filecount;
	unsigned char *backup_filebuffer = s_filebuffer;
	unsigned int backup_filelen = s_filelen;

	pattern = (char *)safe_malloc(PATTERN_BUFFER + 1);
	while ((c = get()) != EOF) {
		/* Add to pattern space */
		pattern[len++] = c;
		pattern[len] = '\0';
		if (len == (PATTERN_BUFFER - 1))
			goto release;

		if (!asp) {
			char pat = pattern[0];
			if (pat == '{') {
				ret = decompress(stream, pattern, len);
				if (ret) {
					if (len == 3)
						len = 0;
					continue;
				}
			}
			/* Look for <% ... */
			if (pat == 0x3c) {
				if (len == 1)
					continue;
				if (pattern[1] == 0x25) {
					asp = pattern + 2;
					continue;
				}
			}
			pat = pattern[len - 1];
			if (pat == '{' || pat == 0x3c) {
				pattern[len - 1] = '\0';
				wfputs(pattern, stream);	//jimmy, https, 8/4/2003
				pattern[0] = pat;
				len = 1;
			}
			continue;
		} else {
			if (unqstrstr(asp, "%>")) {
				for (func = asp; func < &pattern[len]; func = end) {
					/* Skip initial whitespace */
					for (; isspace((int)*func); func++) ;
					if (!(end = uqstrchr(func, ';')))
						break;
					*end++ = '\0';
					/* Call function */
					backup_filecount = s_filecount;
					global_handle = call(global_handle, func, stream);
					// restore pointers
					s_fp = backup_fp;
					s_filebuffer = backup_filebuffer;
					s_filecount = backup_filecount;
					s_filelen = backup_filelen;
				}
				asp = NULL;
				len = 0;
			}
			continue;
		}

	      release:
		/* Release pattern space */
		wfputs(pattern, stream);	//jimmy, https, 8/4/2003
		len = 0;
	}
	if (len)
		wfputs(pattern, stream);	//jimmy, https, 8/4/2003

#ifndef MEMLEAK_OVERRIDE
	if (global_handle)
		dlclose(global_handle);
	global_handle = NULL
#endif
	    free(pattern);
	memdebug_leave();
}
Пример #6
0
Файл: ej.c Проект: jhbsz/LC4
void
do_ej(char *file, INPUT *input, ...)
{
    lang_construct_translator(LANG_MAP_FILE, nvram_safe_get("lang"));
    inital_prod();

    FILE *fp;
    char http_folder[128]={0}, pattern[512]={0};
    char *asp = NULL, *func = NULL, *end = NULL;
    int c, len = 0;

#define DO_EJ_PARA_MAX  8

    char paras[DO_EJ_PARA_MAX][SHORT_BUF_LEN];
    int i=0;
    va_list ap;
    char *para;

    if(!input) input = CGI_INIT();
    strcpy(http_folder, "/tmp/mnt/");
    strcat(http_folder, file);

    va_start(ap, input);
    para = va_arg(ap, char *);
    while (para && *para) {
        strcpy(paras[i], para);
        i++;
        if (i >= DO_EJ_PARA_MAX) {
            break;
        }
        para = va_arg(ap, char *);
    }

    fp = fopen(http_folder, "r");
    if( fp!=NULL ) {
        while ((c = getc(fp)) != EOF) {
            if (c == '$') {
                c = getc(fp);
                if (c == EOF) {
                    break;
                }
                if ((c - '0') < i && c - '0' >= 0) {
                    /* $0 ~ $i */
                    strcpy(&pattern[len], paras[c - '0']);
                    len += strlen(paras[c - '0']);
                } 
                else {
                    /* Not what we want to replace. */
                    sprintf(&pattern[len], "$%c", c);
                    len += 2;
                }
                pattern[len] = '\0';
                continue;
            }
            /* Add to pattern space */
            pattern[len++] = c;
            pattern[len] = '\0';
            if (!asp && !strncmp(pattern, "<%", len)) {
                if (len == 2)
                    asp = pattern + 2;
                continue;
            }

            if (asp) {
                if (unqstrstr(asp, "%>")) {
                    /* The iterator could be ended before the string "%>". */
                    for (func = asp; func < &pattern[len - 3]; func = end) {
                        /* Skip initial whitespace */
                        for (; isspace((int) *func); func++);
                            if (!(end = unqstrstr(func, ";")))
                                break;
                            *end++ = '\0';
                            call(func, input);
                    }
                    asp = NULL;
                    len = 0;
                }
                continue;
            }
            len = 0;
            //if(!strcmp(pattern,"\n")) {
            if((c == '\n') || (c == '\r')) {
                if(!pattern_is_newline) {
                    printf("%s", pattern);
                }
                pattern_is_newline = 1;
            } 
            else {
                pattern_is_newline = 0;
                printf("%s", pattern);
            }

        }
        fclose(fp);
    }
}
Пример #7
0
Файл: ej.c Проект: jhbsz/LC4
void
do_ej(char *file, webs_t stream, ...)
{
    FILE *fp;
    int c;
    char pattern[512], *asp = NULL, *func = NULL, *end = NULL;
#define DO_EJ_PARA_MAX  8
    /* At most 'DO_EJ_PARA_MAX' parameters are allowed.
     * DO_EJ_PARA_MAX could not be more than 10 because $10 will be recognized
     * as $1.
     */
    char paras[DO_EJ_PARA_MAX][SHORT_BUF_LEN];
    int len = 0;
    int i = 0;
    va_list ap;
    char *para;

    if (!(fp = fopen(file, "r")))
        return;

    /* NOTE: va_arg() doesn't correctly return NULL if there is no parameter.
     * Therefore, we put an empty string as the last parameter for every
     * do_ej() function.
     * eg., do_ej("file.asp, "");
     */
    va_start(ap, stream);
    para = va_arg(ap, char *);
    while (para && *para) {
        strcpy(paras[i], para);
        i++;
        if (i >= DO_EJ_PARA_MAX) {
            break;
        }
        para = va_arg(ap, char *);
    } 
    
    /* i indicates the number of parameters for replacement. */
    while ((c = getc(fp)) != EOF) {
        if (c == '$') {
            c = getc(fp);
            if (c == EOF) {
                break;
            }
            if ((c - '0') < i && c - '0' >= 0) {
                /* $0 ~ $i */
                strcpy(&pattern[len], paras[c - '0']);
                len += strlen(paras[c - '0']);
            } else {
                /* Not what we want to replace. */
                sprintf(&pattern[len], "$%c", c);
                len += 2;
            }
            pattern[len] = '\0';
            continue;
        }
        /* Add to pattern space */
        pattern[len++] = c;
        pattern[len] = '\0';
        if (len == (sizeof(pattern) - 1))
            goto release;

        /* Look for <% ... */

        /* EZP: If "<%" appears, it will store in the "pattern buffer". */
       
        if (!asp && !strncmp(pattern, "<%", len)) {
            if (len == 2)
                asp = pattern + 2;
            continue;
        }

        /* Look for ... %> */
        if (asp) {
            if (unqstrstr(asp, "%>")) {
                /* The iterator could be ended before the string "%>". */
                for (func = asp; func < &pattern[len - 3]; func = end) {
                    /* Skip initial whitespace */
                    for (; isspace((int) *func); func++);
                    if (!(end = unqstrstr(func, ";")))
                        break;
                    *end++ = '\0';
                    /* 
                     * Either if allowed to print or if "do_print_end()", 
                     * let's execute the ej function. 
                     */
                    if (ej_print || !strncmp(func, "do_print_end", 
                                strlen("do_print_end"))) {
                        call(func, stream);
                    }
                }
                asp = NULL;
                len = 0;
            }
            continue;
        }
release:
        /* Release pattern space */
        if (ej_print) {
            if (wfputs(pattern, stream) == EOF) {
                printf("wfputs(pattern, stream) Error : code %d\n", ferror(stream));
                break;
            }
        }
        len = 0;
    }

    fclose(fp);
}