Ejemplo n.º 1
0
static void send(void *v_s)
{
	struct sender *s = v_s;

	if (!s->output) {
		s->output = async_transport_send(s->transport,
						 s->address, &s->err);
		assert(s->output);
	}

	for (;;) {
		switch (stream_write_bytes(s->output, &s->buf, &s->tasklet,
					   &s->err)) {
		case STREAM_ERROR:
			die("%s", error_message(&s->err));
			/* fall through */

		case STREAM_END:
			stream_destroy(s->output);
			s->output = NULL;
			tasklet_stop(&s->tasklet);

			/* fall through */
		case STREAM_WAITING:
			return;
		}
	}
}
Ejemplo n.º 2
0
static ssize_t finish_prebody(struct http_writer *w,
			      struct tasklet *t, struct error *e)
{
	switch (w->state) {
	case HTTP_WRITER_HEADERS:
		growbuf_append_string(&w->prebody, "\r\n");
		w->prebody_out = growbuf_to_bytes(&w->prebody);
		w->state = HTTP_WRITER_PREBODY;
		/* fall through */

	case HTTP_WRITER_PREBODY: {
		for (;;) {
			ssize_t res = stream_write_bytes(w->stream,
							 &w->prebody_out, t, e);
			if (res < 0) {
				if (res == STREAM_END)
					break;
				else
					return res;
			}
		}

		w->state = HTTP_WRITER_BODY;
		/* fall through */
	}

	case HTTP_WRITER_BODY:
		return 0;

	default:
		die("bad http_writer state %d", w->state);
	}
}
Ejemplo n.º 3
0
CODECode _url_encoding(void *p, const byte *data, size_t dataLen, CDCStream *st) {
    size_t i = 0;
    byte c = 0;
	byte *safechr = ((urlencoding *)p)->safechr;
    byte escape[3] = {0};
    escape[0] = '%';
    for (i = 0; i < dataLen; ++i) {
        c = data[i];
        if (c == 0xff) {
            stream_write_bytes(st, (const byte *)"%FF", 3);
        }
        else if(safechr[c] == 0xff) {
            escape[1] = _url_digit((c >> 4) & 0x0f);
            escape[2] = _url_digit(c & 0x0f);
            stream_write_bytes(st, escape, 3);
        }
        else {