mirror of
https://github.com/libssh2/libssh2.git
synced 2026-10-24 03:48:58 +03:00
From `_libssh2_*` to `ssh2_*`, `LIBSSH2_*` -> `SSH2_*`. To make the code easier to read, write, to fit more into the maximum line width without folding, and to avoid using reserved namespace (`_*`). Namespacing after this patch: - `libssh2_`, `LIBSSH2_` (rarely preceded with `_`): public API. - `ssh2_`, `SSH2_`: private API. - `ssh2_<crypto-backend>_`: non-static crypto functions. where `<crypto-backend>` is: lgcr, mbed, ossl, wcng, os400qc3 - local macros and static functions try to be short, descriptive of their scope, without strict namespacing. They also avoid namespaces used above for clarity. Also: - reflow using clang-format (and manually where necessary.) - merge split error strings where possible (manually). - shorten `_libssh2_debug()` to `ssh2_deb()`. - shorten `_libssh2_error()` to `ssh2_err()`. - move `libssh2_*` internal symbols to the `ssh2_*` namespace. - shorten local macro/enum prefixes from `LIBSSH2_` to `SSH2_`. - mbedtls, wincng: move static functions to the local namespace, where missing. - drop stray no-op `ssh2_init_aes_ctr()` symbols (libgcrypt, mbedtls). - move crypto primitives to crypto-local namespace `ssh2_(lgcr|mbed|ossl|wcng)_`, where missing. - normalize crypo-local and crypto-static function namespace to: `mbed_*`, `ssh2_mbed_,*` `wcng_*`, `ssh2_wcng_*`. - `LIBSSH2_CIPHER_T()` -> `SSH2_CIPHER_T()` Follow-up to689b202320#1923 - rename `ssh2_store_bignum2_bytes()` -> `ssh2_store_bignum_bytes()`. - drop redundant `void *` cast from `SSH2_UNCONST()` values. - os400qc3: drop unused static `ssh2_bn_from_bn()`. - os400qc3: move static `ssh2_bn_resize()` off the ssh2 namespace. - libssh2.rpgle.in: drop private macros `LIBSSH2_DH_GEX*`. - rename `ARRAY_SIZE()` to `SSH2_ARRAYSIZE()` for uniqueness. - agent: drop unused/commented `SSH_AGENTC_*` protocol 1 macros. - fix stray symbol references found in comments. - minor whitespace fixes along the way. Note: - `ssh2` as a namespace has the minor downside of potential confusion with SSH protocol 2 (vs 1). In practice I think this is fine. - `SSH2_` prefix has been used in two places before this patch: 4 `SSH2_AGENT*` macros in `agent.c` and 2 `SSH2_MSG_KEX_ECDH_*` macros in `libssh2_priv.h`. The latter is coming from https://datatracker.ietf.org/doc/html/rfc9941. If this ever creates confusion they can be moved under an `IETF_` namespace for example. - libssh2_userauth_publickey_sk: the public man page says the callbacks needs to be using `LIBSSH2_ALLOC()` for allocation and responsible for freeing. It's an internal macro and should not be mentioned or necessary in public docs. Ref:ed439a29bb#698 Follow-up to8c9b7771ee#1931 Follow-up to689b202320#1923 Ref: #1949 Closes #1961
94 lines
4.4 KiB
C
94 lines
4.4 KiB
C
#ifndef LIBSSH2_SESSION_H
|
|
#define LIBSSH2_SESSION_H
|
|
/* Copyright (C) Sara Golemon <sarag@libssh2.org>
|
|
* Copyright (C) Daniel Stenberg
|
|
* Copyright (C) Simon Josefsson <simon@josefsson.org>
|
|
* All rights reserved.
|
|
*
|
|
* Redistribution and use in source and binary forms,
|
|
* with or without modification, are permitted provided
|
|
* that the following conditions are met:
|
|
*
|
|
* Redistributions of source code must retain the above
|
|
* copyright notice, this list of conditions and the
|
|
* following disclaimer.
|
|
*
|
|
* Redistributions in binary form must reproduce the above
|
|
* copyright notice, this list of conditions and the following
|
|
* disclaimer in the documentation and/or other materials
|
|
* provided with the distribution.
|
|
*
|
|
* Neither the name of the copyright holder nor the names
|
|
* of any other contributors may be used to endorse or
|
|
* promote products derived from this software without
|
|
* specific prior written permission.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
|
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
|
|
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
|
* OF SUCH DAMAGE.
|
|
*
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
*/
|
|
|
|
/* Convenience-macros to allow code like this;
|
|
|
|
int rc = BLOCK_ADJUST(rc, session, session_startup(session, sock));
|
|
|
|
int rc = BLOCK_ADJUST_ERRNO(ptr, session, session_startup(session, sock));
|
|
|
|
The point being to make sure that while in non-blocking mode these always
|
|
return no matter what the return code is, but in blocking mode it blocks
|
|
if EAGAIN is the reason for the return from the underlying function.
|
|
|
|
*/
|
|
#define BLOCK_ADJUST(rc, sess, x) \
|
|
do { \
|
|
time_t entry_time = time(NULL); \
|
|
do { \
|
|
(rc) = (x); \
|
|
/* the order of the check below is important to properly \
|
|
deal with the case when the 'sess' is freed */ \
|
|
if(((rc) != LIBSSH2_ERROR_EAGAIN) || !(sess) || \
|
|
!(sess)->api_block_mode) \
|
|
break; \
|
|
(rc) = ssh2_wait_socket(sess, entry_time); \
|
|
} while(!(rc)); \
|
|
} while(0)
|
|
|
|
/*
|
|
* For functions that returns a pointer, we need to check if the API is
|
|
* non-blocking and return immediately. If the pointer is non-NULL we return
|
|
* immediately. If the API is blocking and we get a NULL we check the errno
|
|
* and *only* if that is EAGAIN we loop and wait for socket action.
|
|
*/
|
|
#define BLOCK_ADJUST_ERRNO(ptr, sess, x) \
|
|
do { \
|
|
time_t entry_time = time(NULL); \
|
|
int rc; \
|
|
do { \
|
|
(ptr) = (x); \
|
|
if(!(sess) || !(sess)->api_block_mode || (ptr) != NULL || \
|
|
libssh2_session_last_errno(sess) != LIBSSH2_ERROR_EAGAIN) \
|
|
break; \
|
|
(rc) = ssh2_wait_socket(sess, entry_time); \
|
|
} while(!(rc)); \
|
|
} while(0)
|
|
|
|
int ssh2_wait_socket(LIBSSH2_SESSION *session, time_t start_time);
|
|
|
|
/* this is the lib-internal set blocking function */
|
|
int ssh2_session_set_blocking(LIBSSH2_SESSION *session, int blocking);
|
|
|
|
#endif /* LIBSSH2_SESSION_H */
|