summaryrefslogtreecommitdiffstats
path: root/sesman/libscp/libscp_session.c
diff options
context:
space:
mode:
Diffstat (limited to 'sesman/libscp/libscp_session.c')
-rw-r--r--sesman/libscp/libscp_session.c106
1 files changed, 91 insertions, 15 deletions
diff --git a/sesman/libscp/libscp_session.c b/sesman/libscp/libscp_session.c
index 916424d9..a7b3397c 100644
--- a/sesman/libscp/libscp_session.c
+++ b/sesman/libscp/libscp_session.c
@@ -27,6 +27,12 @@
#include "libscp_session.h"
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+
+extern struct log_config* s_log;
+
struct SCP_SESSION*
scp_session_create()
{
@@ -36,14 +42,15 @@ scp_session_create()
if (0 == s)
{
+ log_message(s_log, LOG_LEVEL_WARNING, "[session:%d] session create: malloc error", __LINE__);
return 0;
}
- s->username=0;
- s->password=0;
- s->hostname=0;
- s->errstr=0;
-#warning FIXME use scp_session_set* to init session
+ s->username = 0;
+ s->password = 0;
+ s->hostname = 0;
+ s->errstr = 0;
+ s->locale[0]='\0';
return s;
}
@@ -60,7 +67,11 @@ scp_session_set_type(struct SCP_SESSION* s, tui8 type)
case SCP_SESSION_TYPE_XRDP:
s->type = SCP_SESSION_TYPE_XRDP;
break;
+ case SCP_SESSION_TYPE_MANAGE:
+ s->type = SCP_SESSION_TYPE_MANAGE;
+ break;
default:
+ log_message(s_log, LOG_LEVEL_WARNING, "[session:%d] set_type: unknown type", __LINE__);
return 1;
}
return 0;
@@ -79,6 +90,7 @@ scp_session_set_version(struct SCP_SESSION* s, tui32 version)
s->version = 1;
break;
default:
+ log_message(s_log, LOG_LEVEL_WARNING, "[session:%d] set_version: unknown version", __LINE__);
return 1;
}
return 0;
@@ -137,6 +149,8 @@ scp_session_set_locale(struct SCP_SESSION* s, char* str)
{
if (0 == str)
{
+ log_message(s_log, LOG_LEVEL_WARNING, "[session:%d] set_locale: null locale", __LINE__);
+ s->locale[0]='\0';
return 1;
}
g_strncpy(s->locale, str, 17);
@@ -150,13 +164,19 @@ scp_session_set_username(struct SCP_SESSION* s, char* str)
{
if (0 == str)
{
+ log_message(s_log, LOG_LEVEL_WARNING, "[session:%d] set_username: null username", __LINE__);
return 1;
}
- if (0 != s->username)
+ if (0 != s->username)
{
g_free(s->username);
}
s->username = g_strdup(str);
+ if (0 == s->username)
+ {
+ log_message(s_log, LOG_LEVEL_WARNING, "[session:%d] set_username: strdup error", __LINE__);
+ return 1;
+ }
return 0;
}
@@ -166,13 +186,19 @@ scp_session_set_password(struct SCP_SESSION* s, char* str)
{
if (0 == str)
{
+ log_message(s_log, LOG_LEVEL_WARNING, "[session:%d] set_password: null password", __LINE__);
return 1;
}
- if (0 != s->password)
+ if (0 != s->password)
{
g_free(s->password);
}
s->password = g_strdup(str);
+ if (0 == s->password)
+ {
+ log_message(s_log, LOG_LEVEL_WARNING, "[session:%d] set_password: strdup error", __LINE__);
+ return 1;
+ }
return 0;
}
@@ -180,15 +206,21 @@ scp_session_set_password(struct SCP_SESSION* s, char* str)
int
scp_session_set_hostname(struct SCP_SESSION* s, char* str)
{
- if (0 == str)
+ if (0 == str)
{
+ log_message(s_log, LOG_LEVEL_WARNING, "[session:%d] set_hostname: null hostname", __LINE__);
return 1;
}
- if (0 != s->hostname)
+ if (0 != s->hostname)
{
g_free(s->hostname);
}
s->hostname = g_strdup(str);
+ if (0 == s->hostname)
+ {
+ log_message(s_log, LOG_LEVEL_WARNING, "[session:%d] set_hostname: strdup error", __LINE__);
+ return 1;
+ }
return 0;
}
@@ -196,15 +228,21 @@ scp_session_set_hostname(struct SCP_SESSION* s, char* str)
int
scp_session_set_errstr(struct SCP_SESSION* s, char* str)
{
- if (0 == str)
+ if (0 == str)
{
+ log_message(s_log, LOG_LEVEL_WARNING, "[session:%d] set_errstr: null string", __LINE__);
return 1;
}
- if (0 != s->errstr)
+ if (0 != s->errstr)
{
g_free(s->errstr);
}
s->errstr = g_strdup(str);
+ if (0 == s->errstr)
+ {
+ log_message(s_log, LOG_LEVEL_WARNING, "[session:%d] set_errstr: strdup error", __LINE__);
+ return 1;
+ }
return 0;
}
@@ -212,16 +250,54 @@ scp_session_set_errstr(struct SCP_SESSION* s, char* str)
int
scp_session_set_display(struct SCP_SESSION* s, SCP_DISPLAY display)
{
- s->display=display;
+ s->display = display;
return 0;
}
/*******************************************************************/
int
-scp_session_set_addr(struct SCP_SESSION* s, int type, char* addr)
+scp_session_set_addr(struct SCP_SESSION* s, int type, void* addr)
{
-#warning FIXME managing addresses
- return 1;
+ struct in_addr ip4;
+ struct in6_addr ip6;
+ int ret;
+
+ switch (type)
+ {
+ case SCP_ADDRESS_TYPE_IPV4:
+ /* convert from char to 32bit*/
+ ret = inet_pton(AF_INET, addr, &ip4);
+ if (0 == ret)
+ {
+ log_message(s_log, LOG_LEVEL_WARNING, "[session:%d] set_addr: invalid address", __LINE__);
+ inet_pton(AF_INET, "127.0.0.1", &ip4);
+ g_memcpy(&(s->ipv4addr), &(ip4.s_addr), 4);
+ return 1;
+ }
+ g_memcpy(&(s->ipv4addr), &(ip4.s_addr), 4);
+ break;
+ case SCP_ADDRESS_TYPE_IPV6:
+ /* convert from char to 128bit*/
+ ret = inet_pton(AF_INET6, addr, &ip6);
+ if (0 == ret)
+ {
+ log_message(s_log, LOG_LEVEL_WARNING, "[session:%d] set_addr: invalid address", __LINE__);
+ inet_pton(AF_INET, "::1", &ip6);
+ g_memcpy(s->ipv6addr, &(ip6.s6_addr), 16);
+ return 1;
+ }
+ g_memcpy(s->ipv6addr, &(ip6.s6_addr), 16);
+ break;
+ case SCP_ADDRESS_TYPE_IPV4_BIN:
+ g_memcpy(&(s->ipv4addr), addr, 4);
+ break;
+ case SCP_ADDRESS_TYPE_IPV6_BIN:
+ g_memcpy(s->ipv6addr, addr, 16);
+ break;
+ default:
+ return 1;
+ }
+ return 0;
}
/*******************************************************************/