Beispiel #1
0
static int response_mem_do_data(struct http_state *http)
{
	struct response_mem_priv_s *priv = http->response_priv;
	
	int av = httpd_available_sendbuffer(http);
	
	if (!av)
	{
		printf("no httpd sendbuffer space\n");
		return 1;
	}
	
	if (av > (priv->len - priv->ptr))
		av = priv->len - priv->ptr;
	
	while (av)
	{
		int maxread = 1024;
		if (maxread > av)
			maxread = av;
		httpd_put_sendbuffer(http, (void*)(priv->base + priv->ptr), maxread);
		priv->ptr += maxread;
		av -= maxread;
	}

	return 1;
}
Beispiel #2
0
static int response_file_do_data(struct http_state *http) {
    struct response_file_priv_s *priv = http->response_priv;

    int av = httpd_available_sendbuffer(http);

    if (!av)
        return 1;

    unsigned char buff[av];
    av = fread(buff, 1, av, priv->f);
    if (av <= 0)
        return 0;

    httpd_put_sendbuffer(http, buff, av);

    return 1;
}
Beispiel #3
0
static int response_la_do_data(struct http_state *http)
{
	struct response_la_priv_s *priv = http->response_priv;
	
	if (priv->command != 2)
	{
		httpd_put_sendbuffer_string(http, "OK\n");
		return 0;
	}
	
	int av = httpd_available_sendbuffer(http);
	
	if (!av)
		return 1;
	
	if (av > (priv->size - priv->ptr))
		av = priv->size - priv->ptr;

	if (av > priv->len)
		av = priv->len;

	while (av)
	{
		int maxread = 1024;
		if (maxread > av)
			maxread = av;
		microblaze_init_dcache_range((int)(priv->ptr + priv->base), maxread);
		hdprintf("sending %08x..%08x, len %08x, size %08x\n", priv->ptr, priv->ptr+maxread, priv->len, priv->size);
		httpd_put_sendbuffer(http, (void*)(priv->ptr + priv->base), maxread);
		priv->ptr += maxread;
		priv->len -= maxread;
		av -= maxread;
	}

	if (priv->ptr == priv->size)
	{
			/* wrap */
		priv->ptr = 0;
	}
	if (!priv->len)
		return 0;

	return 1;
}
Beispiel #4
0
static int response_static_do_data(struct http_state *http) {
    struct response_static_priv_s *priv = http->response_priv;
    if (!priv)
        return 0;

    int av = httpd_available_sendbuffer(http);

    hdprintf("err_do_data, %d %d\n", av, priv->len);

    if (!av)
        return 1;

    if (av > priv->len)
        av = priv->len;

    httpd_put_sendbuffer(http, priv->data + priv->ptr, av);
    priv->ptr += av;
    priv->len -= av;
    if (!priv->len)
        return 0;
    else
        return 1;
}
Beispiel #5
0
static int response_vfs_do_data(struct http_state *http)
{
	struct response_vfs_priv_s *priv = http->response_priv;
	
	int av = httpd_available_sendbuffer(http);
	
	if (!av)
		return 1;

			/* static content is easy... */
	if (!(priv->f->flags & 1))
	{
		if (av > (priv->f->len - priv->ptr))
			av = priv->f->len - priv->ptr;
	
		if (!av)
			return 0;

		httpd_put_sendbuffer(http, priv->f->data + priv->ptr, av);
		priv->ptr += av;
	} else
	{
		const char *b = priv->f->data + priv->ptr, *e = b;
		while ((e - b) < av)
		{
			hdprintf("%d bytes parsed, %d av\n", e- b, av);
			if (e == priv->f->data + priv->f->len)
				break;
			if (*e == '%')
			{
				if (e != b)
				{
					httpd_put_sendbuffer(http, b, e - b);
					priv->ptr = e - priv->f->data;
					av -= e - b;
				}
				
				b = ++e;
				
						/* length check missing here: wer mit dhtml dingern rummesst hat selbst schuld! */
				while (*e != '%')
					++e;
				
				int l = e - b;
				int r = response_vfs_do_dynamic(http, b, l);
				if (r == 1) // "out of sendbuf space"
				{
					hdprintf("out of sendbuf space\n");
					return 1;
				}
				
				av = httpd_available_sendbuffer(http);
				b = ++e;
				priv->ptr = e - priv->f->data;
			} else
				++e;
		}
		if (e != b)
		{
			httpd_put_sendbuffer(http, b, e - b);
			priv->ptr = e - priv->f->data;
		}
		
		if (e == priv->f->data + priv->f->len)
			return 0;
	}

	return 1;
}
Beispiel #6
0
void httpd_put_sendbuffer_string(struct http_state *http, const char *data)
{
	httpd_put_sendbuffer(http, data, strlen(data));
}