1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-12-08 03:42:12 +03:00

messages: Reformat the surrounding code

Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Sahana Prasad <sahana@redhat.com>
Reviewed-by: Eshan Kelkar <eshankelkar@galorithm.com>
This commit is contained in:
Jakub Jelen
2024-07-17 12:56:52 +02:00
committed by Sahana Prasad
parent f6e2d18da1
commit 716950fc9e

View File

@@ -1391,8 +1391,13 @@ ssh_channel ssh_message_channel_request_open_reply_accept(ssh_message msg) {
*
* @returns SSH_OK on success, SSH_ERROR if an error occurred.
*/
int ssh_message_handle_channel_request(ssh_session session, ssh_channel channel, ssh_buffer packet,
const char *request, uint8_t want_reply) {
int
ssh_message_handle_channel_request(ssh_session session,
ssh_channel channel,
ssh_buffer packet,
const char *request,
uint8_t want_reply)
{
ssh_message msg = NULL;
int rc;
@@ -1415,14 +1420,14 @@ int ssh_message_handle_channel_request(ssh_session session, ssh_channel channel,
msg->channel_request.want_reply = want_reply;
if (strcmp(request, "pty-req") == 0) {
rc = ssh_buffer_unpack(packet, "sddddS",
rc = ssh_buffer_unpack(packet,
"sddddS",
&msg->channel_request.TERM,
&msg->channel_request.width,
&msg->channel_request.height,
&msg->channel_request.pxwidth,
&msg->channel_request.pxheight,
&msg->channel_request.modes
);
&msg->channel_request.modes);
msg->channel_request.type = SSH_CHANNEL_REQUEST_PTY;
@@ -1434,22 +1439,22 @@ int ssh_message_handle_channel_request(ssh_session session, ssh_channel channel,
if (strcmp(request, "window-change") == 0) {
msg->channel_request.type = SSH_CHANNEL_REQUEST_WINDOW_CHANGE;
rc = ssh_buffer_unpack(packet, "dddd",
rc = ssh_buffer_unpack(packet,
"dddd",
&msg->channel_request.width,
&msg->channel_request.height,
&msg->channel_request.pxwidth,
&msg->channel_request.pxheight);
if (rc != SSH_OK){
if (rc != SSH_OK) {
goto error;
}
goto end;
}
if (strcmp(request, "subsystem") == 0) {
rc = ssh_buffer_unpack(packet, "s",
&msg->channel_request.subsystem);
rc = ssh_buffer_unpack(packet, "s", &msg->channel_request.subsystem);
msg->channel_request.type = SSH_CHANNEL_REQUEST_SUBSYSTEM;
if (rc != SSH_OK){
if (rc != SSH_OK) {
goto error;
}
goto end;
@@ -1461,8 +1466,7 @@ int ssh_message_handle_channel_request(ssh_session session, ssh_channel channel,
}
if (strcmp(request, "exec") == 0) {
rc = ssh_buffer_unpack(packet, "s",
&msg->channel_request.command);
rc = ssh_buffer_unpack(packet, "s", &msg->channel_request.command);
msg->channel_request.type = SSH_CHANNEL_REQUEST_EXEC;
if (rc != SSH_OK) {
goto error;
@@ -1471,7 +1475,8 @@ int ssh_message_handle_channel_request(ssh_session session, ssh_channel channel,
}
if (strcmp(request, "env") == 0) {
rc = ssh_buffer_unpack(packet, "ss",
rc = ssh_buffer_unpack(packet,
"ss",
&msg->channel_request.var_name,
&msg->channel_request.var_value);
msg->channel_request.type = SSH_CHANNEL_REQUEST_ENV;
@@ -1482,7 +1487,8 @@ int ssh_message_handle_channel_request(ssh_session session, ssh_channel channel,
}
if (strcmp(request, "x11-req") == 0) {
rc = ssh_buffer_unpack(packet, "bssd",
rc = ssh_buffer_unpack(packet,
"bssd",
&msg->channel_request.x11_single_connection,
&msg->channel_request.x11_auth_protocol,
&msg->channel_request.x11_auth_cookie,
@@ -1498,7 +1504,7 @@ int ssh_message_handle_channel_request(ssh_session session, ssh_channel channel,
msg->channel_request.type = SSH_CHANNEL_REQUEST_UNKNOWN;
end:
ssh_message_queue(session,msg);
ssh_message_queue(session, msg);
return SSH_OK;
error:
@@ -1515,7 +1521,8 @@ error:
*
* @returns SSH_OK on success, SSH_ERROR if an error occurred.
*/
int ssh_message_channel_request_reply_success(ssh_message msg) {
int ssh_message_channel_request_reply_success(ssh_message msg)
{
uint32_t channel;
int rc;
@@ -1527,13 +1534,14 @@ int ssh_message_channel_request_reply_success(ssh_message msg) {
channel = msg->channel_request.channel->remote_channel;
SSH_LOG(SSH_LOG_PACKET,
"Sending a channel_request success to channel %" PRIu32, channel);
"Sending a channel_request success to channel %" PRIu32,
channel);
rc = ssh_buffer_pack(msg->session->out_buffer,
"bd",
SSH2_MSG_CHANNEL_SUCCESS,
channel);
if (rc != SSH_OK){
if (rc != SSH_OK) {
ssh_set_error_oom(msg->session);
return SSH_ERROR;
}
@@ -1548,20 +1556,20 @@ int ssh_message_channel_request_reply_success(ssh_message msg) {
}
#ifdef WITH_SERVER
SSH_PACKET_CALLBACK(ssh_packet_global_request){
SSH_PACKET_CALLBACK(ssh_packet_global_request)
{
ssh_message msg = NULL;
char *request=NULL;
char *request = NULL;
uint8_t want_reply;
int rc = SSH_PACKET_USED;
int r;
(void)user;
(void)type;
(void)packet;
SSH_LOG(SSH_LOG_DEBUG,"Received SSH_MSG_GLOBAL_REQUEST packet");
r = ssh_buffer_unpack(packet, "sb",
&request,
&want_reply);
r = ssh_buffer_unpack(packet, "sb", &request, &want_reply);
if (r != SSH_OK){
goto error;
}
@@ -1580,10 +1588,10 @@ SSH_PACKET_CALLBACK(ssh_packet_global_request){
goto reply_with_failure;
}
r = ssh_buffer_unpack(packet, "sd",
r = ssh_buffer_unpack(packet,
"sd",
&msg->global_request.bind_address,
&msg->global_request.bind_port
);
&msg->global_request.bind_port);
if (r != SSH_OK){
goto reply_with_failure;
}
@@ -1597,14 +1605,18 @@ SSH_PACKET_CALLBACK(ssh_packet_global_request){
msg->global_request.bind_address,
msg->global_request.bind_port);
if(ssh_callbacks_exists(session->common.callbacks, global_request_function)) {
if (ssh_callbacks_exists(session->common.callbacks,
global_request_function)) {
SSH_LOG(SSH_LOG_DEBUG,
"Calling callback for SSH_MSG_GLOBAL_REQUEST %s %hhu %s:%d",
request,
want_reply,
msg->global_request.bind_address,
msg->global_request.bind_port);
session->common.callbacks->global_request_function(session, msg, session->common.callbacks->userdata);
session->common.callbacks->global_request_function(
session,
msg,
session->common.callbacks->userdata);
} else {
SAFE_FREE(request);
ssh_message_queue(session, msg);
@@ -1617,7 +1629,8 @@ SSH_PACKET_CALLBACK(ssh_packet_global_request){
goto reply_with_failure;
}
r = ssh_buffer_unpack(packet, "sd",
r = ssh_buffer_unpack(packet,
"sd",
&msg->global_request.bind_address,
&msg->global_request.bind_port);
if (r != SSH_OK){
@@ -1633,8 +1646,12 @@ SSH_PACKET_CALLBACK(ssh_packet_global_request){
msg->global_request.bind_address,
msg->global_request.bind_port);
if(ssh_callbacks_exists(session->common.callbacks, global_request_function)) {
session->common.callbacks->global_request_function(session, msg, session->common.callbacks->userdata);
if (ssh_callbacks_exists(session->common.callbacks,
global_request_function)) {
session->common.callbacks->global_request_function(
session,
msg,
session->common.callbacks->userdata);
} else {
SAFE_FREE(request);
ssh_message_queue(session, msg);
@@ -1646,8 +1663,12 @@ SSH_PACKET_CALLBACK(ssh_packet_global_request){
SSH_LOG(SSH_LOG_DEBUG,
"Received keepalive@openssh.com %hhu",
want_reply);
if(ssh_callbacks_exists(session->common.callbacks, global_request_function)) {
session->common.callbacks->global_request_function(session, msg, session->common.callbacks->userdata);
if (ssh_callbacks_exists(session->common.callbacks,
global_request_function)) {
session->common.callbacks->global_request_function(
session,
msg,
session->common.callbacks->userdata);
} else {
ssh_message_global_request_reply_success(msg, 0);
}
@@ -1666,7 +1687,7 @@ SSH_PACKET_CALLBACK(ssh_packet_global_request){
session->flags |= SSH_SESSION_FLAG_NO_MORE_SESSIONS;
} else {
SSH_LOG(SSH_LOG_DEBUG,
"UNKNOWN SSH_MSG_GLOBAL_REQUEST %s,xwant_reply = %hhu",
"UNKNOWN SSH_MSG_GLOBAL_REQUEST %s, want_reply = %hhu",
request,
want_reply);
goto reply_with_failure;
@@ -1679,8 +1700,7 @@ SSH_PACKET_CALLBACK(ssh_packet_global_request){
reply_with_failure:
/* Only report the failure if requested */
if (want_reply) {
r = ssh_buffer_add_u8(session->out_buffer,
SSH2_MSG_REQUEST_FAILURE);
r = ssh_buffer_add_u8(session->out_buffer, SSH2_MSG_REQUEST_FAILURE);
if (r < 0) {
ssh_set_error_oom(session);
goto error;