Lines Matching refs:ioc

161 qio_channel_websock_handshake_send_res(QIOChannelWebsock *ioc,  in qio_channel_websock_handshake_send_res()  argument
172 buffer_reserve(&ioc->encoutput, responselen); in qio_channel_websock_handshake_send_res()
173 buffer_append(&ioc->encoutput, response, responselen); in qio_channel_websock_handshake_send_res()
185 static void qio_channel_websock_handshake_send_res_err(QIOChannelWebsock *ioc, in qio_channel_websock_handshake_send_res_err() argument
189 qio_channel_websock_handshake_send_res(ioc, resdata, date); in qio_channel_websock_handshake_send_res_err()
203 qio_channel_websock_extract_headers(QIOChannelWebsock *ioc, in qio_channel_websock_extract_headers() argument
228 trace_qio_channel_websock_http_greeting(ioc, buffer); in qio_channel_websock_extract_headers()
252 ioc, QIO_CHANNEL_WEBSOCK_HANDSHAKE_RES_NOT_FOUND); in qio_channel_websock_extract_headers()
317 ioc, QIO_CHANNEL_WEBSOCK_HANDSHAKE_RES_BAD_REQUEST); in qio_channel_websock_extract_headers()
338 static void qio_channel_websock_handshake_send_res_ok(QIOChannelWebsock *ioc, in qio_channel_websock_handshake_send_res_ok() argument
361 ioc, QIO_CHANNEL_WEBSOCK_HANDSHAKE_RES_SERVER_ERR); in qio_channel_websock_handshake_send_res_ok()
368 ioc, QIO_CHANNEL_WEBSOCK_HANDSHAKE_WITH_PROTO_RES_OK, in qio_channel_websock_handshake_send_res_ok()
372 ioc, QIO_CHANNEL_WEBSOCK_HANDSHAKE_RES_OK, date, accept); in qio_channel_websock_handshake_send_res_ok()
379 static void qio_channel_websock_handshake_process(QIOChannelWebsock *ioc, in qio_channel_websock_handshake_process() argument
391 nhdrs = qio_channel_websock_extract_headers(ioc, buffer, hdrs, nhdrs, errp); in qio_channel_websock_handshake_process()
434 trace_qio_channel_websock_http_request(ioc, protocols, version, in qio_channel_websock_handshake_process()
476 qio_channel_websock_handshake_send_res_ok(ioc, key, !!protocols, errp); in qio_channel_websock_handshake_process()
481 ioc, QIO_CHANNEL_WEBSOCK_HANDSHAKE_RES_BAD_REQUEST); in qio_channel_websock_handshake_process()
484 static int qio_channel_websock_handshake_read(QIOChannelWebsock *ioc, in qio_channel_websock_handshake_read() argument
491 size_t want = 4096 - ioc->encinput.offset; in qio_channel_websock_handshake_read()
492 buffer_reserve(&ioc->encinput, want); in qio_channel_websock_handshake_read()
493 ret = qio_channel_read(ioc->master, in qio_channel_websock_handshake_read()
494 (char *)buffer_end(&ioc->encinput), want, errp); in qio_channel_websock_handshake_read()
498 ioc->encinput.offset += ret; in qio_channel_websock_handshake_read()
500 handshake_end = g_strstr_len((char *)ioc->encinput.buffer, in qio_channel_websock_handshake_read()
501 ioc->encinput.offset, in qio_channel_websock_handshake_read()
504 if (ioc->encinput.offset >= 4096) { in qio_channel_websock_handshake_read()
506 ioc, QIO_CHANNEL_WEBSOCK_HANDSHAKE_RES_TOO_LARGE); in qio_channel_websock_handshake_read()
519 qio_channel_websock_handshake_process(ioc, in qio_channel_websock_handshake_read()
520 (char *)ioc->encinput.buffer, in qio_channel_websock_handshake_read()
523 buffer_advance(&ioc->encinput, in qio_channel_websock_handshake_read()
524 handshake_end - (char *)ioc->encinput.buffer + in qio_channel_websock_handshake_read()
529 static gboolean qio_channel_websock_handshake_send(QIOChannel *ioc, in qio_channel_websock_handshake_send() argument
545 trace_qio_channel_websock_handshake_fail(ioc, error_get_pretty(err)); in qio_channel_websock_handshake_send()
555 ioc, error_get_pretty(wioc->io_err)); in qio_channel_websock_handshake_send()
560 trace_qio_channel_websock_handshake_complete(ioc); in qio_channel_websock_handshake_send()
565 trace_qio_channel_websock_handshake_pending(ioc, G_IO_OUT); in qio_channel_websock_handshake_send()
569 static gboolean qio_channel_websock_handshake_io(QIOChannel *ioc, in qio_channel_websock_handshake_io() argument
586 trace_qio_channel_websock_handshake_fail(ioc, error_get_pretty(err)); in qio_channel_websock_handshake_io()
592 trace_qio_channel_websock_handshake_pending(ioc, G_IO_IN); in qio_channel_websock_handshake_io()
599 trace_qio_channel_websock_handshake_reply(ioc); in qio_channel_websock_handshake_io()
610 static void qio_channel_websock_encode(QIOChannelWebsock *ioc, in qio_channel_websock_encode() argument
641 trace_qio_channel_websock_encode(ioc, opcode, header_size, size); in qio_channel_websock_encode()
642 buffer_reserve(&ioc->encoutput, header_size + size); in qio_channel_websock_encode()
643 buffer_append(&ioc->encoutput, header.buf, header_size); in qio_channel_websock_encode()
649 buffer_append(&ioc->encoutput, iov[i].iov_base, want); in qio_channel_websock_encode()
658 static void qio_channel_websock_write_close(QIOChannelWebsock *ioc, in qio_channel_websock_write_close() argument
675 qio_channel_websock_encode(ioc, QIO_CHANNEL_WEBSOCK_OPCODE_CLOSE, in qio_channel_websock_write_close()
677 qio_channel_websock_write_wire(ioc, NULL); in qio_channel_websock_write_close()
678 qio_channel_shutdown(ioc->master, QIO_CHANNEL_SHUTDOWN_BOTH, NULL); in qio_channel_websock_write_close()
682 static int qio_channel_websock_decode_header(QIOChannelWebsock *ioc, in qio_channel_websock_decode_header() argument
689 (QIOChannelWebsockHeader *)ioc->encinput.buffer; in qio_channel_websock_decode_header()
691 if (ioc->payload_remain) { in qio_channel_websock_decode_header()
694 ioc->payload_remain); in qio_channel_websock_decode_header()
696 ioc, QIO_CHANNEL_WEBSOCK_STATUS_SERVER_ERR, in qio_channel_websock_decode_header()
700 if (ioc->encinput.offset < QIO_CHANNEL_WEBSOCK_HEADER_LEN_7_BIT) { in qio_channel_websock_decode_header()
712 ioc->opcode = opcode; in qio_channel_websock_decode_header()
714 opcode = ioc->opcode; in qio_channel_websock_decode_header()
717 trace_qio_channel_websock_header_partial_decode(ioc, payload_len, in qio_channel_websock_decode_header()
734 ioc, QIO_CHANNEL_WEBSOCK_STATUS_POLICY , in qio_channel_websock_decode_header()
746 ioc, QIO_CHANNEL_WEBSOCK_STATUS_INVALID_DATA , in qio_channel_websock_decode_header()
754 ioc, QIO_CHANNEL_WEBSOCK_STATUS_PROTOCOL_ERR, in qio_channel_websock_decode_header()
760 ioc->payload_remain = payload_len; in qio_channel_websock_decode_header()
762 ioc->mask = header->u.m; in qio_channel_websock_decode_header()
766 ioc, QIO_CHANNEL_WEBSOCK_STATUS_PROTOCOL_ERR, in qio_channel_websock_decode_header()
770 ioc->encinput.offset >= QIO_CHANNEL_WEBSOCK_HEADER_LEN_16_BIT) { in qio_channel_websock_decode_header()
771 ioc->payload_remain = be16_to_cpu(header->u.s16.l16); in qio_channel_websock_decode_header()
773 ioc->mask = header->u.s16.m16; in qio_channel_websock_decode_header()
775 ioc->encinput.offset >= QIO_CHANNEL_WEBSOCK_HEADER_LEN_64_BIT) { in qio_channel_websock_decode_header()
776 ioc->payload_remain = be64_to_cpu(header->u.s64.l64); in qio_channel_websock_decode_header()
778 ioc->mask = header->u.s64.m64; in qio_channel_websock_decode_header()
785 ioc, header_size, ioc->payload_remain, ioc->mask.u); in qio_channel_websock_decode_header()
786 buffer_advance(&ioc->encinput, header_size); in qio_channel_websock_decode_header()
791 static int qio_channel_websock_decode_payload(QIOChannelWebsock *ioc, in qio_channel_websock_decode_payload() argument
798 if (ioc->payload_remain) { in qio_channel_websock_decode_payload()
803 if (ioc->encinput.offset < ioc->payload_remain) { in qio_channel_websock_decode_payload()
806 if (ioc->opcode & QIO_CHANNEL_WEBSOCK_CONTROL_OPCODE_MASK) { in qio_channel_websock_decode_payload()
809 payload_len = ioc->encinput.offset - (ioc->encinput.offset % 4); in qio_channel_websock_decode_payload()
811 payload_len = ioc->payload_remain; in qio_channel_websock_decode_payload()
817 ioc->payload_remain -= payload_len; in qio_channel_websock_decode_payload()
821 payload32 = (uint32_t *)ioc->encinput.buffer; in qio_channel_websock_decode_payload()
823 payload32[i] ^= ioc->mask.u; in qio_channel_websock_decode_payload()
827 ioc->encinput.buffer[i] ^= ioc->mask.c[i % 4]; in qio_channel_websock_decode_payload()
832 ioc, ioc->opcode, ioc->payload_remain); in qio_channel_websock_decode_payload()
834 if (ioc->opcode == QIO_CHANNEL_WEBSOCK_OPCODE_BINARY_FRAME) { in qio_channel_websock_decode_payload()
837 buffer_reserve(&ioc->rawinput, payload_len); in qio_channel_websock_decode_payload()
838 buffer_append(&ioc->rawinput, ioc->encinput.buffer, payload_len); in qio_channel_websock_decode_payload()
840 } else if (ioc->opcode == QIO_CHANNEL_WEBSOCK_OPCODE_CLOSE) { in qio_channel_websock_decode_payload()
845 struct iovec iov = { .iov_base = ioc->encinput.buffer, in qio_channel_websock_decode_payload()
846 .iov_len = ioc->encinput.offset }; in qio_channel_websock_decode_payload()
847 qio_channel_websock_encode(ioc, QIO_CHANNEL_WEBSOCK_OPCODE_CLOSE, in qio_channel_websock_decode_payload()
849 qio_channel_websock_write_wire(ioc, NULL); in qio_channel_websock_decode_payload()
850 qio_channel_shutdown(ioc->master, QIO_CHANNEL_SHUTDOWN_BOTH, NULL); in qio_channel_websock_decode_payload()
854 ioc, QIO_CHANNEL_WEBSOCK_STATUS_NORMAL, "peer requested close"); in qio_channel_websock_decode_payload()
857 } else if (ioc->opcode == QIO_CHANNEL_WEBSOCK_OPCODE_PING) { in qio_channel_websock_decode_payload()
860 if (ioc->pong_remain == 0) { in qio_channel_websock_decode_payload()
861 struct iovec iov = { .iov_base = ioc->encinput.buffer, in qio_channel_websock_decode_payload()
862 .iov_len = ioc->encinput.offset }; in qio_channel_websock_decode_payload()
863 qio_channel_websock_encode(ioc, QIO_CHANNEL_WEBSOCK_OPCODE_PONG, in qio_channel_websock_decode_payload()
865 ioc->pong_remain = ioc->encoutput.offset; in qio_channel_websock_decode_payload()
870 buffer_advance(&ioc->encinput, payload_len); in qio_channel_websock_decode_payload()
880 QIOChannel *ioc; in qio_channel_websock_new_server() local
883 ioc = QIO_CHANNEL(wioc); in qio_channel_websock_new_server()
886 ioc->follow_coroutine_ctx = master->follow_coroutine_ctx; in qio_channel_websock_new_server()
888 qio_channel_set_feature(ioc, QIO_CHANNEL_FEATURE_SHUTDOWN); in qio_channel_websock_new_server()
896 void qio_channel_websock_handshake(QIOChannelWebsock *ioc, in qio_channel_websock_handshake() argument
903 task = qio_task_new(OBJECT(ioc), in qio_channel_websock_handshake()
908 trace_qio_channel_websock_handshake_start(ioc); in qio_channel_websock_handshake()
909 trace_qio_channel_websock_handshake_pending(ioc, G_IO_IN); in qio_channel_websock_handshake()
910 qio_channel_add_watch(ioc->master, in qio_channel_websock_handshake()
920 QIOChannelWebsock *ioc = QIO_CHANNEL_WEBSOCK(obj); in qio_channel_websock_finalize() local
922 buffer_free(&ioc->encinput); in qio_channel_websock_finalize()
923 buffer_free(&ioc->encoutput); in qio_channel_websock_finalize()
924 buffer_free(&ioc->rawinput); in qio_channel_websock_finalize()
925 object_unref(OBJECT(ioc->master)); in qio_channel_websock_finalize()
926 if (ioc->io_tag) { in qio_channel_websock_finalize()
927 g_source_remove(ioc->io_tag); in qio_channel_websock_finalize()
929 if (ioc->io_err) { in qio_channel_websock_finalize()
930 error_free(ioc->io_err); in qio_channel_websock_finalize()
935 static ssize_t qio_channel_websock_read_wire(QIOChannelWebsock *ioc, in qio_channel_websock_read_wire() argument
940 if (ioc->encinput.offset < 4096) { in qio_channel_websock_read_wire()
941 size_t want = 4096 - ioc->encinput.offset; in qio_channel_websock_read_wire()
943 buffer_reserve(&ioc->encinput, want); in qio_channel_websock_read_wire()
944 ret = qio_channel_read(ioc->master, in qio_channel_websock_read_wire()
945 (char *)ioc->encinput.buffer + in qio_channel_websock_read_wire()
946 ioc->encinput.offset, in qio_channel_websock_read_wire()
952 if (ret == 0 && ioc->encinput.offset == 0) { in qio_channel_websock_read_wire()
953 ioc->io_eof = TRUE; in qio_channel_websock_read_wire()
956 ioc->encinput.offset += ret; in qio_channel_websock_read_wire()
959 while (ioc->encinput.offset != 0) { in qio_channel_websock_read_wire()
960 if (ioc->payload_remain == 0) { in qio_channel_websock_read_wire()
961 ret = qio_channel_websock_decode_header(ioc, errp); in qio_channel_websock_read_wire()
967 ret = qio_channel_websock_decode_payload(ioc, errp); in qio_channel_websock_read_wire()
976 static ssize_t qio_channel_websock_write_wire(QIOChannelWebsock *ioc, in qio_channel_websock_write_wire() argument
982 while (ioc->encoutput.offset > 0) { in qio_channel_websock_write_wire()
983 ret = qio_channel_write(ioc->master, in qio_channel_websock_write_wire()
984 (char *)ioc->encoutput.buffer, in qio_channel_websock_write_wire()
985 ioc->encoutput.offset, in qio_channel_websock_write_wire()
995 buffer_advance(&ioc->encoutput, ret); in qio_channel_websock_write_wire()
997 if (ioc->pong_remain < ret) { in qio_channel_websock_write_wire()
998 ioc->pong_remain = 0; in qio_channel_websock_write_wire()
1000 ioc->pong_remain -= ret; in qio_channel_websock_write_wire()
1013 static void qio_channel_websock_set_watch(QIOChannelWebsock *ioc);
1015 static gboolean qio_channel_websock_flush(QIOChannel *ioc, in qio_channel_websock_flush() argument
1042 static void qio_channel_websock_unset_watch(QIOChannelWebsock *ioc) in qio_channel_websock_unset_watch() argument
1044 if (ioc->io_tag) { in qio_channel_websock_unset_watch()
1045 g_source_remove(ioc->io_tag); in qio_channel_websock_unset_watch()
1046 ioc->io_tag = 0; in qio_channel_websock_unset_watch()
1050 static void qio_channel_websock_set_watch(QIOChannelWebsock *ioc) in qio_channel_websock_set_watch() argument
1054 qio_channel_websock_unset_watch(ioc); in qio_channel_websock_set_watch()
1056 if (ioc->io_err) { in qio_channel_websock_set_watch()
1060 if (ioc->encoutput.offset) { in qio_channel_websock_set_watch()
1063 if (ioc->encinput.offset < QIO_CHANNEL_WEBSOCK_MAX_BUFFER && in qio_channel_websock_set_watch()
1064 !ioc->io_eof) { in qio_channel_websock_set_watch()
1069 object_ref(OBJECT(ioc)); in qio_channel_websock_set_watch()
1070 ioc->io_tag = in qio_channel_websock_set_watch()
1071 qio_channel_add_watch(ioc->master, in qio_channel_websock_set_watch()
1074 ioc, in qio_channel_websock_set_watch()
1080 static ssize_t qio_channel_websock_readv(QIOChannel *ioc, in qio_channel_websock_readv() argument
1088 QIOChannelWebsock *wioc = QIO_CHANNEL_WEBSOCK(ioc); in qio_channel_websock_readv()
1099 ret = qio_channel_websock_read_wire(QIO_CHANNEL_WEBSOCK(ioc), errp); in qio_channel_websock_readv()
1127 static ssize_t qio_channel_websock_writev(QIOChannel *ioc, in qio_channel_websock_writev() argument
1135 QIOChannelWebsock *wioc = QIO_CHANNEL_WEBSOCK(ioc); in qio_channel_websock_writev()
1181 static int qio_channel_websock_set_blocking(QIOChannel *ioc, in qio_channel_websock_set_blocking() argument
1185 QIOChannelWebsock *wioc = QIO_CHANNEL_WEBSOCK(ioc); in qio_channel_websock_set_blocking()
1191 static void qio_channel_websock_set_delay(QIOChannel *ioc, in qio_channel_websock_set_delay() argument
1194 QIOChannelWebsock *tioc = QIO_CHANNEL_WEBSOCK(ioc); in qio_channel_websock_set_delay()
1199 static void qio_channel_websock_set_cork(QIOChannel *ioc, in qio_channel_websock_set_cork() argument
1202 QIOChannelWebsock *tioc = QIO_CHANNEL_WEBSOCK(ioc); in qio_channel_websock_set_cork()
1207 static int qio_channel_websock_shutdown(QIOChannel *ioc, in qio_channel_websock_shutdown() argument
1211 QIOChannelWebsock *tioc = QIO_CHANNEL_WEBSOCK(ioc); in qio_channel_websock_shutdown()
1216 static int qio_channel_websock_close(QIOChannel *ioc, in qio_channel_websock_close() argument
1219 QIOChannelWebsock *wioc = QIO_CHANNEL_WEBSOCK(ioc); in qio_channel_websock_close()
1221 trace_qio_channel_websock_close(ioc); in qio_channel_websock_close()
1290 static GSource *qio_channel_websock_create_watch(QIOChannel *ioc, in qio_channel_websock_create_watch() argument
1293 QIOChannelWebsock *wioc = QIO_CHANNEL_WEBSOCK(ioc); in qio_channel_websock_create_watch()