Exemplo n.º 1
0
/*
 *  search ? key=xxx
 *  match  ? key=xxx
 *  i.jpg  ? file=xxx
 *  m.jpg  ? file=xxx
 *  pos    ? idx=xxx, pos=, len
 */
static int my_do_url(void *_class, void *type, void *_http, int sock, int pthread_idx)
{
	const char *url;
	WikiSocket *ws = (WikiSocket *)type;
	HttpParse *http = (HttpParse *)_http;

	start_html_len = sprintf(start_html, HTTP_START_HTML, _is_http_full_text(http) ? "checked" : "",
				http->hp_cookie("showall")[0] == '1' ? "checked" : "");
	end_html_len = sprintf(end_html, "%s", HTTP_END_HTML);

	url = http->hp_url();

#ifdef DEBUG
	LOG("url=%s.\n", url);
#endif

	if (url[0] == 0)
		return output_one_page(sock, ws, " ", 1, "");

	if (strncmp(url, "I.", 2) == 0)
		return my_find_image(ws, http, sock, pthread_idx, url + 2);

	if (url[0] == 'M')
		return my_find_math(ws, http, sock, pthread_idx, url);

	if (url[0] >= '0' && url[0] <= '9')
		return my_find_index(ws, http, sock, pthread_idx);

	for (int i = 0; m_url_func[i].url; i++) {
		struct url_func *p = &m_url_func[i];
		if (strcmp(p->url, url) == 0) {
			return (*p->func)(ws, http, sock, pthread_idx);
		}
	}

	ws->ws_http_output_head(sock, 404, "text/html", 10);
	ws->ws_http_output_body(sock, "Not Found\n", 10);

	return 0;
}
Exemplo n.º 2
0
/*
 * dyld adds libraries by first adding the directly dependant libraries in link order, and
 * then adding the dependencies for those libraries, so we should do the same... but we don't
 * bother adding the extra dependencies, if the symbols are neither in the loaded image nor
 * any of it's direct dependencies, then it probably isn't there.
 */
NSSymbol *search_linked_libs(const struct mach_header * mh, const char *symbol)
{
	unsigned int n;
	struct load_command *lc = 0;
	struct mach_header *wh;
	NSSymbol *nssym = 0;
	if (dyld_NSAddImage && dyld_NSIsSymbolNameDefinedInImage && dyld_NSLookupSymbolInImage)
	{
		lc = (struct load_command *)((char *)mh + sizeof(struct mach_header));
		for (n = 0; n < mh->ncmds; n++, lc = (struct load_command *)((char *)lc + lc->cmdsize))
		{
			if ((LC_LOAD_DYLIB == lc->cmd) || (LC_LOAD_WEAK_DYLIB == lc->cmd))
			{
				if ((wh = (struct mach_header *)
					 my_find_image((char *)(((struct dylib_command *)lc)->dylib.name.offset +
											(char *)lc))))
				{
					if (dyld_NSIsSymbolNameDefinedInImage(wh, symbol))
					{
						nssym = dyld_NSLookupSymbolInImage(wh,
														   symbol,
														   NSLOOKUPSYMBOLINIMAGE_OPTION_BIND |
														   NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
						break;
					}
				}
			}
		}
		if ((!nssym) && NSIsSymbolNameDefined(symbol))
		{
			/* I've never seen this debug message...*/
			debug("Symbol \"%s\" is defined but was not found", symbol);
		}
	}
	return nssym;
}