diff options
author | Christophe Fergeau <cfergeau@redhat.com> | 2013-10-07 13:50:20 +0200 |
---|---|---|
committer | Christophe Fergeau <cfergeau@redhat.com> | 2014-01-20 12:15:41 +0100 |
commit | 8b347a641c885fdc31a41a1b1a55da982b580265 (patch) | |
tree | 659abc85944ebd4c41fb12eaf34223d807991abc /server/reds_stream.h | |
parent | 73c56e5a2d952bf566c3fbff5e9aefff70ddd59a (diff) | |
download | spice-8b347a641c885fdc31a41a1b1a55da982b580265.tar.gz spice-8b347a641c885fdc31a41a1b1a55da982b580265.tar.xz spice-8b347a641c885fdc31a41a1b1a55da982b580265.zip |
Add reds_stream.[ch]
Gather common RedsStream code there rather than having it
in reds.c
Diffstat (limited to 'server/reds_stream.h')
-rw-r--r-- | server/reds_stream.h | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/server/reds_stream.h b/server/reds_stream.h new file mode 100644 index 00000000..ca18f75b --- /dev/null +++ b/server/reds_stream.h @@ -0,0 +1,100 @@ +/* + Copyright (C) 2009, 2013 Red Hat, Inc. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef _H_REDS_STREAM +#define _H_REDS_STREAM + +#include "spice.h" +#include "common/mem.h" + +#include <openssl/ssl.h> + +#if HAVE_SASL +#include <sasl/sasl.h> + +typedef struct RedsSASL { + sasl_conn_t *conn; + + /* If we want to negotiate an SSF layer with client */ + int wantSSF :1; + /* If we are now running the SSF layer */ + int runSSF :1; + + /* + * Buffering encoded data to allow more clear data + * to be stuffed onto the output buffer + */ + const uint8_t *encoded; + unsigned int encodedLength; + unsigned int encodedOffset; + + SpiceBuffer inbuffer; + + char *username; + char *mechlist; + char *mechname; + + /* temporary data during authentication */ + unsigned int len; + char *data; +} RedsSASL; +#endif + +typedef struct RedsStream RedsStream; + +struct RedsStream { + int socket; + SpiceWatch *watch; + + /* set it to TRUE if you shutdown the socket. shutdown read doesn't work as accepted - + receive may return data afterward. check the flag before calling receive*/ + int shutdown; + SSL *ssl; + +#if HAVE_SASL + RedsSASL sasl; +#endif + + /* life time of info: + * allocated when creating RedsStream. + * deallocated when main_dispatcher handles the SPICE_CHANNEL_EVENT_DISCONNECTED + * event, either from same thread or by call back from main thread. */ + SpiceChannelEventInfo* info; + + /* private */ + ssize_t (*read)(RedsStream *s, void *buf, size_t nbyte); + ssize_t (*write)(RedsStream *s, const void *buf, size_t nbyte); + ssize_t (*writev)(RedsStream *s, const struct iovec *iov, int iovcnt); +}; + +typedef enum { + REDS_STREAM_SSL_STATUS_OK, + REDS_STREAM_SSL_STATUS_ERROR, + REDS_STREAM_SSL_STATUS_WAIT_FOR_READ, + REDS_STREAM_SSL_STATUS_WAIT_FOR_WRITE +} RedsStreamSslStatus; + +/* any thread */ +ssize_t reds_stream_read(RedsStream *s, void *buf, size_t nbyte); +ssize_t reds_stream_write(RedsStream *s, const void *buf, size_t nbyte); +ssize_t reds_stream_writev(RedsStream *s, const struct iovec *iov, int iovcnt); +void reds_stream_free(RedsStream *s); + +void reds_stream_push_channel_event(RedsStream *s, int event); +void reds_stream_remove_watch(RedsStream* s); + +#endif |