Exemplo n.º 1
0
static gboolean fastcgi_parse_response(fastcgi_connection *fcon) {
	liVRequest *vr = fcon->vr;
	liPlugin *p = fcon->ctx->plugin;
	gint len;
	while (fastcgi_get_packet(fcon)) {
		if (fcon->fcgi_in_record.version != FCGI_VERSION_1) {
			VR_ERROR(vr, "(%s) Unknown fastcgi protocol version %i", fcon->ctx->socket_str->str, (gint) fcon->fcgi_in_record.version);
			close(fcon->fd);
			fcon->fd = -1;
			li_vrequest_error(vr);
			return FALSE;
		}
		switch (fcon->fcgi_in_record.type) {
		case FCGI_END_REQUEST:
			li_chunkqueue_skip(fcon->fcgi_in, fastcgi_available(fcon));
			fcon->stdout->is_closed = TRUE;
			break;
		case FCGI_STDOUT:
			if (0 == fcon->fcgi_in_record.contentLength) {
				fcon->stdout->is_closed = TRUE;
			} else {
				li_chunkqueue_steal_len(fcon->stdout, fcon->fcgi_in, fastcgi_available(fcon));
			}
			break;
		case FCGI_STDERR:
			len = fastcgi_available(fcon);
			li_chunkqueue_extract_to(vr, fcon->fcgi_in, len, vr->wrk->tmp_str);
			if (OPTION(FASTCGI_OPTION_LOG_PLAIN_ERRORS).boolean) {
				li_log_split_lines(vr->wrk->srv, vr, LI_LOG_LEVEL_BACKEND, 0, vr->wrk->tmp_str->str, "");
			} else {
				VR_BACKEND_LINES(vr, vr->wrk->tmp_str->str, "(fcgi-stderr %s) ", fcon->ctx->socket_str->str);
			}
			li_chunkqueue_skip(fcon->fcgi_in, len);
			break;
		default:
			if (fcon->fcgi_in_record.first) VR_WARNING(vr, "(%s) Unhandled fastcgi record type %i", fcon->ctx->socket_str->str, (gint) fcon->fcgi_in_record.type);
			li_chunkqueue_skip(fcon->fcgi_in, fastcgi_available(fcon));
			break;
		}
		fcon->fcgi_in_record.first = FALSE;
	}
	return TRUE;
}
Exemplo n.º 2
0
int fcgi_demux_response(fastcgiResponse *fr) {
    int fin = 0;
    while (fin == 0) {
            fastcgi_response_packet packet;

            /* check if we have at least one packet */
            if (0 != fastcgi_get_packet(fr, &packet)) {
                    /* no full packet */
                    break;
            }

            switch(packet.type) {
                case FCGI_STDOUT:
                        if (packet.len == 0) break;
                        char *c;
                        size_t blen;
                        if (NULL != (c = buffer_search_string_len(packet.b, CONST_STR_LEN("\r\n\r\n")))) {
                                blen = packet.b->used - (c - packet.b->ptr) - 4;
                                //packet.b->used = (c - packet.b->ptr) + 3;
                                c += 4; /* point the the start of the response */
                        }
                        buffer_append_string_len(fr->format_buf, c, blen);
                        
                        //analyze format buffer get pubsub command
                        
                        break;
                case FCGI_STDERR:
                        if (packet.len == 0) break;

                        break;
                case FCGI_END_REQUEST:

                        fin = 1;
                        break;
                default:
                        break;
            }
            buffer_free(packet.b);
    }

    return fin;
}