diff --git a/docs/libssh2_session_flag.3 b/docs/libssh2_session_flag.3 index a4a26b49..3816029b 100644 --- a/docs/libssh2_session_flag.3 +++ b/docs/libssh2_session_flag.3 @@ -5,11 +5,21 @@ libssh2_session_flag - TODO .SH SYNOPSIS int -libssh2_session_flag(LIBSSH2_SESSION * session, int flag, int value); +libssh2_session_flag(LIBSSH2_SESSION *session, int flag, int value); .SH DESCRIPTION -This function has no purpose and no documented flags can be set nor read. +Set options for the created session. \fIflag\fP is the option to set, while +\fIvalue\fP is typically set to 1 or 0 to enable or disable the option. +.SH FLAGS +.IP LIBSSH2_FLAG_SIGPIPE +If set, libssh2 will not attempt to block SIGPIPEs but will let them trigger +from the underlying socket layer. +.IP LIBSSH2_FLAG_COMPRESS +If set - before the connection negotiation is performed - libssh2 will try to +negotiate compression enabling for this connection. By default libssh2 will +not attempt to use compression. .SH RETURN VALUE -0 -.SH ERRORS -Its mere existence is an error +Returns regular libssh2 error code. +.SH AVAILABILITY +This function has existed since the age of dawn. LIBSSH2_FLAG_COMPRESS was +added in version 1.2.8. .SH SEE ALSO diff --git a/include/libssh2.h b/include/libssh2.h index eedfecff..e011d496 100644 --- a/include/libssh2.h +++ b/include/libssh2.h @@ -1,5 +1,5 @@ /* Copyright (c) 2004-2009, Sara Golemon - * Copyright (c) 2009 by Daniel Stenberg + * Copyright (c) 2009-2010 Daniel Stenberg * Copyright (c) 2010 Simon Josefsson * All rights reserved. * @@ -253,8 +253,9 @@ typedef struct _LIBSSH2_USERAUTH_KBDINT_RESPONSE #define LIBSSH2_METHOD_LANG_CS 8 #define LIBSSH2_METHOD_LANG_SC 9 -/* session.flags bits */ -#define LIBSSH2_FLAG_SIGPIPE 0x00000001 +/* flags */ +#define LIBSSH2_FLAG_SIGPIPE 1 +#define LIBSSH2_FLAG_COMPRESS 2 typedef struct _LIBSSH2_SESSION LIBSSH2_SESSION; typedef struct _LIBSSH2_CHANNEL LIBSSH2_CHANNEL; diff --git a/src/libssh2_priv.h b/src/libssh2_priv.h index 00da23a6..7942d2be 100644 --- a/src/libssh2_priv.h +++ b/src/libssh2_priv.h @@ -661,6 +661,11 @@ struct _LIBSSH2_SFTP #define LIBSSH2_SCP_RESPONSE_BUFLEN 256 +struct flags { + int sigpipe; /* LIBSSH2_FLAG_SIGPIPE */ + int compress; /* LIBSSH2_FLAG_COMPRESS */ +}; + struct _LIBSSH2_SESSION { /* Memory management callbacks */ @@ -681,7 +686,9 @@ struct _LIBSSH2_SESSION char *hostkey_prefs; int state; - int flags; + + /* Flag options */ + struct flags flag; /* Agreed Key Exchange Method */ const LIBSSH2_KEX_METHOD *kex; @@ -930,8 +937,8 @@ struct _LIBSSH2_SESSION /* session.flag helpers */ #ifdef MSG_NOSIGNAL -#define LIBSSH2_SOCKET_SEND_FLAGS(session) (((session)->flags & LIBSSH2_FLAG_SIGPIPE) ? 0 : MSG_NOSIGNAL) -#define LIBSSH2_SOCKET_RECV_FLAGS(session) (((session)->flags & LIBSSH2_FLAG_SIGPIPE) ? 0 : MSG_NOSIGNAL) +#define LIBSSH2_SOCKET_SEND_FLAGS(session) (((session)->flag.sigpipe) ? 0 : MSG_NOSIGNAL) +#define LIBSSH2_SOCKET_RECV_FLAGS(session) (((session)->flag.sigpipe) ? 0 : MSG_NOSIGNAL) #else /* If MSG_NOSIGNAL isn't defined we're SOL on blocking SIGPIPE */ #define LIBSSH2_SOCKET_SEND_FLAGS(session) 0 diff --git a/src/session.c b/src/session.c index e79888a6..855923a1 100644 --- a/src/session.c +++ b/src/session.c @@ -1227,19 +1227,24 @@ libssh2_session_last_errno(LIBSSH2_SESSION * session) * * Set/Get session flags * - * Passing flag==0 will avoid changing session->flags while still returning - * its current value + * Return error code. */ LIBSSH2_API int libssh2_session_flag(LIBSSH2_SESSION * session, int flag, int value) { - if (value) { - session->flags |= flag; - } else { - session->flags &= ~flag; + switch(flag) { + case LIBSSH2_FLAG_SIGPIPE: + session->flag.sigpipe = value; + break; + case LIBSSH2_FLAG_COMPRESS: + session->flag.compress = value; + break; + default: + /* unknown flag */ + return LIBSSH2_ERROR_INVAL; } - return session->flags; + return LIBSSH2_ERROR_NONE; } /* _libssh2_session_set_blocking