Ejemplo n.º 1
0
static int my_find_index(_FW_URL_FUNC_ARGV)
{
	split_t sp;
	sort_idx_t idx;
	int total, n;
	char key[1024] = {0};
	const char *url = http->hp_url();

	char *buf_data = m_buf_data[pthread_idx];
	char *tmp_data = m_tmp_data[pthread_idx];
	char *convert = m_convert_data[pthread_idx];

	split(',', url, sp);

	for (int i = 0; i < split_total(sp); i++) {
		if (m_wiki_index->wi_find(NULL, WK_INDEX_FIND, atoi(sp[i]), &idx, &total) == 0) {
			if ((n = m_wiki_data->wd_sys_read((int)idx.data_file_idx, idx.data_pos,
							(int)idx.data_len, buf_data, MAX_PAGE_LEN)) > 0) {
				m_wiki_index->wi_get_key(&idx, key);
				char *w = convert_nohtml(buf_data, n, tmp_data, &n);
				if (http->hp_param("key")[0]) {
					n = convert_page_simple(convert, w, n, http->hp_param("key"));
					return output_one_page(sock, ws, convert, n, key);
				}
				output_one_page(sock, ws, w, n, key);
				return 0;
			}
		}
	}

	return output_one_page(sock, ws, "Not Found", 9, "");
}
Ejemplo n.º 2
0
int WikiManage::wiki_parse_url_full_search(const char *url, char *flag, char *title, char **data)
{
	full_search_t *fs = &m_search_buf;
	
	int size, i = atoi(url);
	struct one_lang *p = wiki_full_search_find_lang(i);

	strcpy(flag, "1");
	strcpy(title, fs->key);

	if (p == NULL)
		return wiki_not_found(data, &size, "Not Found.");

	int len;
	sort_idx_t idx;

	if (p->index->wi_find(NULL, WK_INDEX_FIND, fs->page_idx[i], &idx, &len) == 0) {
		if ((len = p->data->wd_sys_read(idx.data_file_idx,
							idx.data_pos, idx.data_len, m_curr_content, _MAX_ONE_PAGE_SIZE)) > 0) {
			m_curr_content[len] = 0;

			if (m_wiki_config->wc_get_audio_flag()) {
				len = wiki_parse_audio_flag(m_curr_content, len, m_curr_page);
				memcpy(m_curr_content, m_curr_page, len);
				m_curr_content[len] = 0;
			}

			if (m_wiki_config->wc_get_need_translate()) {
				len = wiki_translate_format(m_curr_content, len, m_curr_page);
				memcpy(m_curr_content, m_curr_page, len);
				m_curr_content[len] = 0;
			}

			int size = convert_page_simple(m_curr_page, m_curr_content, len, fs->key);
			m_curr_page[size] = 0;

			char tmp[256];

			p->index->wi_get_key(&idx, tmp);
			m_curr_lang = p;
			wiki_push_back(STATUS_CONTENT, tmp, len, &idx);

			return wiki_not_found(data, &size, m_curr_page, size);
		}
	}

	return wiki_not_found(data, &size, "Not Found.");
}
Ejemplo n.º 3
0
static int my_find_full_text(_FW_URL_FUNC_ARGV, const char *key)
{
	int n, total, all_total;
	char *buf_data = m_buf_data[pthread_idx];
	char *tmp_data = m_tmp_data[pthread_idx];
	char title[128], message[_TMP_DATA_START];
	int page_idx[16], message_pos = 0;
	int page = atoi(http->hp_param("page"));
	struct timeval diff1, diff2;

	gettimeofday(&diff1, NULL);

	total = m_httpd_index->hi_fetch(key, &page, page_idx, &all_total);

	if (total <= 0) {
		n = sprintf(buf_data, "Not found: %s\n", key);
		return output_one_page(sock, ws, buf_data, n, key);
	}

	int pos = _TMP_DATA_START, len;
	sort_idx_t idx;

	pos += sprintf(tmp_data + pos, "<table border=0>\n");

	for (int i = 0; i < total; i++) {
		if (m_wiki_index->wi_find(NULL, WK_INDEX_FIND, page_idx[i], &idx, &len) == -1)
			continue;

		m_wiki_index->wi_get_key(&idx, title);
		if ((len = m_wiki_data->wd_sys_read(idx.data_file_idx, idx.data_pos, idx.data_len, buf_data, MAX_PAGE_LEN)) <=  0)
			continue;

		buf_data[len] = 0;

		char *p = buf_data;

		if (http->hp_cookie("showall")[0] != '1') {
			p = m_convert_data[pthread_idx];
			len = convert_page(p, buf_data, len, key);
		} else {
			p = m_convert_data[pthread_idx];
			len = convert_page_simple(p, buf_data, len, key);
		}

		pos += sprintf(tmp_data + pos, "<tr><td width=600px>"
					"<a href='%d?title=%s&key=%s'><font size=4>%s</font></a><br/>\n",
					page_idx[i], title, key, title);

		memcpy(tmp_data + pos, p, len);
		pos += len;

		pos += sprintf(tmp_data + pos, "%s", "<br/><br/>\n</td</tr>\n");
	}

	pos += sprintf(tmp_data + pos, "</table>\n");

	gettimeofday(&diff2, NULL);
	if (diff2.tv_usec < diff1.tv_usec) {
		diff2.tv_usec += 1000000;
		diff2.tv_sec--;
	}

	message_pos += sprintf(message + message_pos,
			"<table border=0><tr><td width=600px>Total: %d, Time: %d.%05ds <br/><br/></td></tr></table>\n",
			all_total, (int)(diff2.tv_sec - diff1.tv_sec), (int)(diff2.tv_usec - diff1.tv_usec) / 10);

	int page_total = _page_total(all_total);
	int before_page = page - 1;
	int next_page = page + 1;

	if (before_page <= 0)
		before_page = 1;

	if (next_page >= page_total)
		next_page = page_total;

	pos += sprintf(tmp_data + pos, "<table border=0 width=100%%><tr><td align=left width=40%%>"
			"<a href=\"/search?key=%s&ft=on&page=%d\">"
			"<font size=4><b>&lt;&lt;&lt;&lt;&lt;</b></font></a></td>\n", key, before_page);

	pos += sprintf(tmp_data + pos, "<td align=center width=20%%>%d/%d</td>", page, page_total);

	pos += sprintf(tmp_data + pos, "<td align=right width=40%%>"
			"<a href=\"/search?key=%s&ft=on&page=%d\">"
			"<font size=4><b>&gt;&gt;&gt;&gt;&gt;</b></font></a></td></tr></table>\n<br/>", key, next_page);

	char *tmp = tmp_data + _TMP_DATA_START - message_pos;
	memcpy(tmp, message, message_pos);

	output_one_page(sock, ws, tmp, pos + message_pos - _TMP_DATA_START, http->hp_param("key"));

	return 0;
}
Ejemplo n.º 4
0
int WikiManage::wiki_full_search_one_page(char **buf, int *size, int page)
{
	full_search_t *fs  = &m_search_buf;

	int last_page = fs->page_total / PAGE_TOTAL;

	if (fs->page_total % PAGE_TOTAL)
		last_page++;

	if (page < 1)
		page = 1;

	if (page > last_page)
		page = last_page;

	fs->curr_page = page;

	int len, pos = 0;
	struct one_lang *p;
	sort_idx_t idx;

	pos = sprintf(m_curr_page + pos, "<table border=0>\n");

	for (int i = PAGE_TOTAL * (page - 1); i < PAGE_TOTAL * page && i < fs->page_total; i++) {
		if ((p = wiki_full_search_find_lang(i)) == NULL)
			continue;

		if (p->index->wi_find(NULL, WK_INDEX_FIND, fs->page_idx[i], &idx, &len) == -1)
			continue;

		char title[128];

		p->index->wi_get_key(&idx, title);
		pos += sprintf(m_curr_page + pos, "<tr><td width=100%%>"
				"<a href='idx:%d'><font size=4>%s</font></a><br/>\n", i, title);

		int show_flag = m_wiki_config->wc_get_full_text_show();

		if (show_flag == FULL_TEXT_SHOW_SOME || show_flag == FULL_TEXT_SHOW_ALL) {
			if ((len = p->data->wd_sys_read(idx.data_file_idx, idx.data_pos, idx.data_len,
							m_curr_content, _MAX_ONE_PAGE_SIZE)) > 0) {
				m_curr_content[len] = 0;

				if (show_flag == FULL_TEXT_SHOW_SOME)
					len = convert_page_complex(m_buf, m_curr_content, len, fs->key);
				else {
					if (m_wiki_config->wc_get_audio_flag()) {
						len = wiki_parse_audio_flag(m_curr_content, len, m_buf);
						memcpy(m_curr_content, m_buf, len);
						m_curr_content[len] = 0;
					}

					if (m_wiki_config->wc_get_need_translate()) {
						len = wiki_translate_format(m_curr_content, len, m_buf);
						memcpy(m_curr_content, m_buf, len);
						m_curr_content[len] = 0;
					}
					len = convert_page_simple(m_buf, m_curr_content, len, fs->key);
				}
				memcpy(m_curr_page + pos, m_buf, len);
				pos += len;
			}
		}

		pos += sprintf(m_curr_page + pos, "%s", "<hr>\n</td</tr>\n");
	}

	pos += sprintf(m_curr_page + pos, "</table>\n");

	char next[1024] = "&nbsp;", before[1024] = "&nbsp;";

	if (page < last_page)
		sprintf(next, "<a href=\"page:%d\"><font size=4><b>&gt;&gt;&gt;&gt;&gt;</b></font></a>", page + 1);

	if (page > 1)
		sprintf(before, "<a href=\"page:%d\"><font size=4><b>&lt;&lt;&lt;&lt;&lt;</b></font></a>", page - 1);

	pos += sprintf(m_curr_page + pos, "<table border=0 width=100%%><tr>"
			"<td align=left width=40%%>%s</td>"
			"<td align=center width=20%%>%d/%d</td>"
			"<td align=right width=40%%>%s</td></tr></table>\n", before, page, last_page, next);

	m_curr_page[pos] = 0;

	return wiki_not_found(buf, size, m_curr_page, pos);
}