aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLee Hambley <lee.hambley@gmail.com>2011-10-28 22:52:03 +0200
committerAndreas Schneider <asn@cryptomilk.org>2011-11-03 18:24:02 +0100
commit17f396ffab3a5ad9d9984344cde6793685cf81be (patch)
tree41a12de8543ebc0b7b957c666e2c53aad0289f29 /src
parent2c04994443384224161d895d00255b5788e8376d (diff)
downloadlibssh-17f396ffab3a5ad9d9984344cde6793685cf81be.tar.gz
libssh-17f396ffab3a5ad9d9984344cde6793685cf81be.tar.xz
libssh-17f396ffab3a5ad9d9984344cde6793685cf81be.zip
Improve ssh_options_get(ssh_session, enum ssh_options_e, char**).
* Use SSH_ERROR and SSH_OK instead of `-1` and `0`. * Re-factor for code duplication * No longer call `ssh_set_error_invalid(ssh_session)` when the ssh_session is NULL.
Diffstat (limited to 'src')
-rw-r--r--src/options.c47
1 files changed, 16 insertions, 31 deletions
diff --git a/src/options.c b/src/options.c
index 4dbcb679..4b928dd8 100644
--- a/src/options.c
+++ b/src/options.c
@@ -838,57 +838,42 @@ int ssh_options_get_port(ssh_session session, unsigned int* port_target) {
* your responsibility to free the memory using
* ssh_free().
*
- * @return 0 on success, < 0 on error.
+ * @return SSH_OK on success, SSH_ERROR on error.
*/
int ssh_options_get(ssh_session session, enum ssh_options_e type, char** value)
{
+ char* src = NULL;
if (session == NULL) {
- return -1;
+ return SSH_ERROR;
}
switch(type)
{
case SSH_OPTIONS_HOST: {
- if (session->host == NULL) {
- ssh_set_error_invalid(session);
- return -1;
- }
- *value = strdup(session->host);
- if (*value == NULL) {
- ssh_set_error_oom(session);
- return -1;
- }
+ src = session->host;
break;
}
case SSH_OPTIONS_USER: {
- if (session->username == NULL) {
- ssh_set_error_invalid(session);
- return -1;
- }
- *value = strdup(session->username);
- if (*value == NULL) {
- ssh_set_error_oom(session);
- return -1;
- }
+ src = session->username;
break;
}
case SSH_OPTIONS_IDENTITY: {
- if (session->identity == NULL) {
- ssh_set_error_invalid(session);
- return -1;
- }
- *value = strdup(session->identity->root->data);
- if(*value == NULL){
- ssh_set_error_oom(session);
- return -1;
- }
+ src = ssh_iterator_value(char *, ssh_list_get_iterator(session->identity));
break;
}
default:
ssh_set_error(session, SSH_REQUEST_DENIED, "Unknown ssh option %d", type);
- return -1;
+ return SSH_ERROR;
break;
}
- return 0;
+ if (src == NULL) {
+ return SSH_ERROR;
+ }
+ *value = strdup(src);
+ if (*value == NULL) {
+ ssh_set_error_oom(session);
+ return SSH_ERROR;
+ }
+ return SSH_OK;
}
/**