some fixes for libscp

ulab-original
ilsimo 18 years ago
parent c127c2b2a4
commit dd76b40a35

@ -34,6 +34,7 @@
#include "os_calls.h"
#include "parse.h"
#include "arch.h"
#include "log.h"
//#warning sesman requires its own tcp streaming functions for threading safety
#include "tcp.h"
@ -57,6 +58,8 @@
#define SCP_COMMAND_SET_MANAGE 0x0001
#define SCP_COMMAND_SET_RSR 0x0002
#define free_session(s) {g_free((s)->username); g_free((s)->password); g_free((s)->hostname); g_free(s);}
struct SCP_CONNECTION
{
int in_sck;
@ -98,7 +101,15 @@ struct SCP_DISCONNECTED_SESSION
enum SCP_CLIENT_STATES_E
{
SCP_CLIENT_STATE_OK,
SCP_CLIENT_STATE_NETWORK_ERR
SCP_CLIENT_STATE_NETWORK_ERR,
SCP_CLIENT_STATE_VERSION_ERR,
SCP_CLIENT_STATE_SEQUENCE_ERR,
SCP_CLIENT_STATE_INTERNAL_ERR,
SCP_CLIENT_STATE_SESSION_LIST,
SCP_CLIENT_STATE_RESEND_CREDENTIALS,
SCP_CLIENT_STATE_CONNECTION_DENIED,
SCP_CLIENT_STATE_PWD_CHANGE_REQ,
SCP_CLIENT_STATE_RECONNECT
};
enum SCP_SERVER_STATES_E
@ -115,3 +126,4 @@ enum SCP_SERVER_STATES_E
};
#endif

@ -26,6 +26,7 @@
*/
#include "sesman.h"
#include "libscp_types.h"
extern unsigned char g_fixedkey[8];
extern struct config_sesman g_cfg; /* config.h */
@ -468,3 +469,73 @@ session_get_bypid(int pid)
return 0;
}
/******************************************************************************/
struct SCP_DISCONNECTED_SESSION*
session_get_byuser(char* user, int* cnt)
{
struct session_chain* tmp;
struct SCP_DISCONNECTED_SESSION* sess;
int count;
int index;
count=0;
/*THREAD-FIX require chain lock */
lock_chain_acquire();
tmp = g_sessions;
while (tmp != 0)
{
#warning FIXME: we should get only disconnected sessions!
if (!g_strncasecmp(user, tmp->item->name, 256))
{
count++;
}
/* go on */
tmp=tmp->next;
}
if (count==0)
{
(*cnt)=0;
/*THREAD-FIX release chain lock */
lock_chain_release();
return 0;
}
/* malloc() an array of disconnected sessions */
sess=g_malloc(count * sizeof(struct SCP_DISCONNECTED_SESSION),1);
if (sess==0)
{
(*cnt)=0;
/*THREAD-FIX release chain lock */
lock_chain_release();
return 0;
}
tmp = g_sessions;
index = 0;
while (tmp != 0)
{
(sess[index]).SID=tmp->item->pid;
(sess[index]).type=tmp->item->type;
(sess[index]).height=tmp->item->height;
(sess[index]).width=tmp->item->width;
(sess[index]).bpp=tmp->item->bpp;
#warning FIXME: setting idle times and such
(sess[index]).idle_days=0;
(sess[index]).idle_hours=0;
(sess[index]).idle_minutes=0;
/* go on */
tmp=tmp->next;
index++;
}
/*THREAD-FIX release chain lock */
lock_chain_release();
(*cnt)=count;
return sess;
}

@ -29,6 +29,8 @@
#ifndef SESSION_H
#define SESSION_H
#include "libscp_types.h"
#define SESMAN_SESSION_TYPE_XRDP 1
#define SESMAN_SESSION_TYPE_XVNC 2
@ -111,5 +113,15 @@ session_kill(int pid);
struct session_item* DEFAULT_CC
session_get_bypid(int pid);
/**
*
* @brief retrieves a session's descriptor
* @param pid the session pid
* @return a pointer to the session descriptor on success, NULL otherwise
*
*/
struct SCP_DISCONNECTED_SESSION*
session_get_byuser(char* user, int* cnt);
#endif

@ -32,9 +32,11 @@ int DEFAULT_CC
tcp_force_recv(int sck, char* data, int len)
{
int rcvd;
int block;
#ifndef LIBSCP_CLIENT
int block;
block = lock_fork_critical_section_start();
#endif
while (len > 0)
{
@ -61,7 +63,9 @@ tcp_force_recv(int sck, char* data, int len)
}
}
#ifndef LIBSCP_CLIENT
lock_fork_critical_section_end(block);
#endif
return 0;
}
@ -71,9 +75,11 @@ int DEFAULT_CC
tcp_force_send(int sck, char* data, int len)
{
int sent;
int block;
#ifndef LIBSCP_CLIENT
int block;
block = lock_fork_critical_section_start();
#endif
while (len > 0)
{
@ -100,7 +106,9 @@ tcp_force_send(int sck, char* data, int len)
}
}
#ifndef LIBSCP_CLIENT
lock_fork_critical_section_end(block);
#endif
return 0;
}

Loading…
Cancel
Save