Beispiel #1
0
void *call_ej(char *name, void *handle, webs_t wp, int argc, char_t ** argv)
{

	if (nvram_match("console_debug", "1")) {
		fprintf(stderr, "call_ej %s\n", name);
		int i = 0;
		for (i = 0; i < argc; i++)
			fprintf(stderr, "argument %s\n", argv[i]);
	}
	char service[64];
	int nohandle = 0;

	{
		memdebug_enter();
		if (!handle) {
			cprintf("load visual_service\n");
			handle = load_visual_service(name);
			nohandle = 1;
		}
		memdebug_leave_info("loadviz");
	}
	if (handle == NULL) {
		cprintf("handle null\n");
		return NULL;
	}
	cprintf("pointer init\n");
	void (*fptr) (webs_t wp, int argc, char_t ** argv);

	sprintf(service, "ej_%s", name);
	{
		memdebug_enter();
		if (nohandle) {
			cprintf("init web\n");
			if (initWeb(handle) != 0) {
				return handle;
			}
		}
		memdebug_leave_info("initweb");
	}
	cprintf("resolving %s\n", service);
	fptr = (void (*)(webs_t wp, int argc, char_t ** argv))dlsym(handle,
								    service);
	cprintf("found. pointer is %p\n", fptr);
	{
		memdebug_enter();
		if (fptr)
			(*fptr) (wp, argc, argv);
		else if (nvram_match("console_debug", "1"))
			fprintf(stderr, "function %s not found \n", service);
		memdebug_leave_info(service);
	}
	cprintf("start_sevice_nofree done()\n");
	return handle;

}
Beispiel #2
0
void do_ej(struct mime_handler *handler, char *path, webs_t stream, char *query)	// jimmy, https, 8/4/2003
{
	FILE *fp = NULL;
	unsigned int len;
	int i;
	memdebug_enter();

	i = 0;
	len = 0;
	unsigned int curoffset = 0;
	while (websRomPageIndex[i].path != NULL) {
		if (!strcmp(websRomPageIndex[i].path, path)) {
			fp = fopen("/etc/www", "rb");
			if (fp == NULL)
				return;
			fseek(fp, curoffset, SEEK_SET);
			len = websRomPageIndex[i].size - WEBSOFFSET;
			break;
		}
		curoffset += websRomPageIndex[i].size - WEBSOFFSET;
		i++;
	}
	if (fp == NULL) {
		fp = fopen(path, "rb");
		if (fp == NULL)
			return;
		fseek(fp, 0, SEEK_END);
		len = ftell(fp);
		fseek(fp, 0, SEEK_SET);
		do_ej_file(fp, len, stream);
	} else {
		do_ej_file(fp, len, stream);
	}
	fclose(fp);
	memdebug_leave_info(path);

}
Beispiel #3
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();
}