コード例 #1
0
ファイル: http.c プロジェクト: GrayHatter/tox-dns
void http_thread(void *args)
{
    if(!init()) {
        print("http_init() failed\n");
        return;
    }

    while(FCGI_Accept() >= 0)
    {
        FCGI_printf("Content-type: text/html\r\nStatus: 200 OK\r\n\r\n");

        char *name = getenv("SCRIPT_NAME");
        _Bool q = 0;

        if(name[0] == '/' && name[1] == 'q') {
            if(name[2] == 0) {
                q = 1;
            } else if(strcmp(name + 2, "key") == 0) {
                uint8_t k[64];
                key_to_string(k, key.public);
                FCGI_fwrite(k, sizeof(k), 1, FCGI_stdout);
                continue;
            } else if(strcmp(name + 2, "stat") == 0) {
                FCGI_printf("Number of registered names: %u<br/>Number of successful Tox DNS requests: %u\n", stat.registered, stat.requests);
                continue;
            }
        }
コード例 #2
0
ファイル: ewf_fastcgi.c プロジェクト: neufbox/misc
int ewf_fastcgi_write_cb( void *ptr, const char *data, int size )
{
	NBU_UNUSED(ptr);
	
	/* error here */
	return FCGI_fwrite( ( void * ) data, sizeof( char ), size, FCGI_stdout );
}
コード例 #3
0
ファイル: fcgiwrap.c プロジェクト: jeremyz/fcgiwrap
static const char * fcgi_pass_fd(struct fcgi_context *fc, int *fdp, FCGI_FILE *ffp, char *buf, size_t bufsize)
{
	ssize_t nread;
	char *p = buf;
	unsigned char cclass, next_state;

	nread = read(*fdp, buf, bufsize);
	if (nread > 0) {
		while (p < buf + nread) {
			if (*p == '\r') {
				cclass = CC_CR;
			} else if (*p == '\n') {
				cclass = CC_LF;
			} else {
				cclass = CC_NORMAL;
			}
			next_state = header_state_machine[fc->reply_state][cclass];
			fc->reply_state = next_state & ~ACTION_MASK;
			switch(next_state & ACTION_MASK) {
				case ACTION_ERROR:
					return "parsing CGI reply";

				case ACTION_END:
					goto out_of_loop;

				case ACTION_SKIP:
					goto next_char;

				case ACTION_EXTRA_CR:
					if (FCGI_fputc('\r', ffp) == EOF) return "writing CGI reply";
					break;

				case ACTION_EXTRA_LF:
					if (FCGI_fputc('\n', ffp) == EOF) return "writing CGI reply";
					break;
			}
			if (FCGI_fputc(*p, ffp) == EOF) {
				return "writing CGI reply";
			}
next_char:
			p++;
		}
out_of_loop:
		if (p < buf + nread) {
			if (FCGI_fwrite(p, 1, buf + nread - p, ffp) != (size_t)(buf + nread - p)) {
				return "writing CGI reply";
			}
		}
	} else {
		if (nread < 0) {
			return "reading CGI reply";
		}
		close(*fdp);
		*fdp = -1;
	}

	return NULL;
}
コード例 #4
0
ファイル: data_manipulate.c プロジェクト: Zhanyin/taomee
int prepare_data(store_result_t *result)
{
	struct in_addr inp;

	FCGI_fwrite(pic_empty_gif, 1, sizeof(pic_empty_gif), FCGI_stdout);

	//取得公共数据
	cgiFormString("Type", type, (MAX_POST_STRING_LEN - 1));
	cgiFormString("UserID", user_id, (MAX_POST_STRING_LEN - 1));
	cgiFormString("ProjNo", project_number, (MAX_POST_STRING_LEN - 1));
	cgiFormString("Client", client_ip, (MAX_POST_STRING_LEN - 1));
	if (0 == inet_aton(client_ip,&inp)) {
		snprintf(client_ip,sizeof(client_ip), "%s", cgiRemoteAddr);
		if (0 == inet_aton(client_ip,&inp))
			return -1;
	}
	result->client_ip = ntohl(inp.s_addr);
	result->user_id = strtoul(user_id, NULL, 10);
	result->project_number = strtoul(project_number, NULL, 10);
	result->test_time = time((time_t*)NULL);
	result->type = strtoul(type, NULL, 10);
	if (result->type == TYPE_CDN) {
		//cdn
		cgiFormString("CDNIP",cdn_ip,(MAX_POST_STRING_LEN - 1));
		if (0 == inet_aton(cdn_ip, &inp))
			return -1;
		result->record.m_cdn.cdn_ip = ntohl(inp.s_addr);

		cgiFormString("Rate",speed,(MAX_POST_STRING_LEN - 1));
		result->record.m_cdn.speed = strtoul(speed, NULL, 10);
		if (if_log_data) {
			write_log("User:%u,Proj:%u,Client:%u,CDN:%u,Speed:%u\n",
						result->user_id,
						result->project_number,
						result->client_ip,
						result->record.m_cdn.cdn_ip,
						result->record.m_cdn.speed);
		}
	} else if (result->type == TYPE_URL) {
		//url
		uint32_t count;
		cgiFormString("Count", str, (MAX_POST_STRING_LEN - 1));
		count = strtoul(str, NULL, 10);
		if (count == 0 || count > MAX_POINT)
			return -1;
		result->record.m_url.count = count;

		uint32_t page_id;
		cgiFormString("PageID", str, (MAX_POST_STRING_LEN - 1));
		page_id = strtoul(str, NULL, 10);
		if (page_id == 0)
			return -1;
		result->record.m_url.page_id = page_id;

		char spent[MAX_POST_STRING_LEN];
		int i;
		for (i = 1; i <= count; i++) {
			snprintf(spent, sizeof(spent), "T%d", i);
			cgiFormString(spent, spent_time, (MAX_POST_STRING_LEN - 1));
			result->record.m_url.vlist[ i-1 ] = strtoul(spent_time, NULL, 10);
		}
		if (if_log_data) {
			int k = 0, n = 0;
			char str[1024];
			for (k = 0; k < result->record.m_url.count; k++) {
				n += sprintf(str + n, " %u", result->record.m_url.vlist[k]);
			}
			write_log("User:%u,Client:%u,Proj:%u,Page:%u,Count:%u,List:%s\n",
						result->user_id,
						result->client_ip,
						result->project_number,
						result->record.m_url.page_id,
						result->record.m_url.count,
						str);
		}
	} else
		return -1;

	return 0;
}
コード例 #5
0
ファイル: mapio.c プロジェクト: codeforeurope/gim
static int msIO_fcgiWrite( void *cbData, void *data, int byteCount )

{
    return FCGI_fwrite( data, 1, byteCount, (FCGI_FILE *) cbData );
}
コード例 #6
0
static int fcgi_out_jansson(const char *buffer, size_t size, void *ctxt)
{
	return (1 != FCGI_fwrite(const_cast<char *>(buffer), size, 1, static_cast<FCGI_FILE *>(ctxt)));
}