summaryrefslogtreecommitdiffstats
path: root/sesman/libscp_v1c.c
diff options
context:
space:
mode:
Diffstat (limited to 'sesman/libscp_v1c.c')
-rw-r--r--sesman/libscp_v1c.c234
1 files changed, 219 insertions, 15 deletions
diff --git a/sesman/libscp_v1c.c b/sesman/libscp_v1c.c
index 736a451a..17bfb0e0 100644
--- a/sesman/libscp_v1c.c
+++ b/sesman/libscp_v1c.c
@@ -18,19 +18,22 @@
*/
/**
- *
+ *
* @file libscp_v1c.c
* @brief libscp version 1 client api code
* @author Simone Fedele
- *
+ *
*/
#include "libscp_v1c.h"
+#include <stdlib.h>
+#include <stdio.h>
+
static enum SCP_CLIENT_STATES_E _scp_v1c_check_response(struct SCP_CONNECTION* c, struct SCP_SESSION* s);
/* client API */
-/* 001 */
+/* 001 */
enum SCP_CLIENT_STATES_E scp_v1c_connect(struct SCP_CONNECTION* c, struct SCP_SESSION* s)
{
unsigned char sz;
@@ -93,11 +96,11 @@ enum SCP_CLIENT_STATES_E scp_v1c_connect(struct SCP_CONNECTION* c, struct SCP_SE
return SCP_CLIENT_STATE_NETWORK_ERR;
}
- /* wait for response */
+ /* wait for response */
return _scp_v1c_check_response(c, s);
}
-/* 004 */
+/* 004 */
enum SCP_CLIENT_STATES_E scp_v1c_resend_credentials(struct SCP_CONNECTION* c, struct SCP_SESSION* s)
{
unsigned char sz;
@@ -138,11 +141,208 @@ enum SCP_CLIENT_STATES_E scp_v1c_resend_credentials(struct SCP_CONNECTION* c, st
/* 021 */ enum SCP_CLIENT_STATES_E scp_v1c_pwd_change(struct SCP_CONNECTION* c, char* newpass);
/* 022 */ enum SCP_CLIENT_STATES_E scp_v1c_pwd_change_cancel(struct SCP_CONNECTION* c);
-/* ... */ enum SCP_CLIENT_STATES_E scp_v1c_get_session_list(struct SCP_CONNECTION* c, int* scount, struct SCP_DISCONNECTED_SESSION** s);
-/* 041 */ enum SCP_CLIENT_STATES_E scp_v1c_select_session(struct SCP_CONNECTION* c, SCP_SID sid);
-/* 042 */ enum SCP_CLIENT_STATES_E scp_v1c_select_session_cancel(struct SCP_CONNECTION* c);
+/* 041 */
+enum SCP_CLIENT_STATES_E
+scp_v1c_get_session_list(struct SCP_CONNECTION* c, int* scount, struct SCP_DISCONNECTED_SESSION** s)
+{
+ uint32_t version=1;
+ uint32_t size=12;
+ uint16_t cmd=41;
+ uint32_t sescnt=0; /* total session number */
+ uint32_t sestmp=0; /* additional total session number */
+ uint8_t pktcnt=0; /* packet session count */
+ uint32_t totalcnt=0; /* session counter */
+ uint8_t continued=0; /* continue flag */
+ int firstpkt=1; /* "first packet" flag */
+ int idx;
+ struct SCP_DISCONNECTED_SESSION* ds=0;
+
+ init_stream(c->out_s, c->out_s->size);
+
+ /* we request session list */
+ out_uint32_be(c->out_s, version); /* version */
+ out_uint32_be(c->out_s, size); /* size */
+ out_uint16_be(c->out_s, SCP_COMMAND_SET_DEFAULT); /* cmdset */
+ out_uint16_be(c->out_s, cmd); /* cmd */
+
+ if (0!=tcp_force_send(c->in_sck, c->out_s->data, size))
+ {
+ return SCP_CLIENT_STATE_NETWORK_ERR;
+ }
+
+ do
+ {
+ /* then we wait for server response */
+ init_stream(c->in_s, c->in_s->size);
+ if (0!=tcp_force_recv(c->in_sck, c->in_s->data, 8))
+ {
+ return SCP_CLIENT_STATE_NETWORK_ERR;
+ }
+
+ in_uint32_be(c->in_s, version);
+ if (version!=1)
+ {
+ return SCP_CLIENT_STATE_VERSION_ERR;
+ }
+
+ in_uint32_be(c->in_s, size);
+ if (size<12)
+ {
+ return SCP_CLIENT_STATE_SIZE_ERR;
+ }
+
+ init_stream(c->in_s, c->in_s->size);
+ if (0!=tcp_force_recv(c->in_sck, c->in_s->data, size-8))
+ {
+ return SCP_CLIENT_STATE_NETWORK_ERR;
+ }
+
+ in_uint16_be(c->in_s, cmd);
+ if (cmd!=SCP_COMMAND_SET_DEFAULT)
+ {
+ return SCP_CLIENT_STATE_SEQUENCE_ERR;
+ }
+
+ in_uint16_be(c->in_s, cmd);
+ if (cmd!=42)
+ {
+ return SCP_CLIENT_STATE_SEQUENCE_ERR;
+ }
+
+ if (firstpkt)
+ {
+ firstpkt = 0;
+ in_uint32_be(c->in_s, sescnt);
+ sestmp = sescnt;
+
+ ds = g_malloc(sizeof(struct SCP_DISCONNECTED_SESSION)*sescnt, 0);
+ if (ds == 0)
+ {
+ return SCP_CLIENT_STATE_INTERNAL_ERR;
+ }
+ }
+ else
+ {
+ in_uint32_be(c->in_s, sestmp);
+ }
+ in_uint8(c->in_s, continued);
+ in_uint8(c->in_s, pktcnt);
+
+ for (idx=0; idx<pktcnt; idx++)
+ {
+ in_uint32_be(c->in_s, (ds[totalcnt]).SID); /* session id */
+ in_uint8(c->in_s, (ds[totalcnt]).type);
+ in_uint16_be(c->in_s, (ds[totalcnt]).height);
+ in_uint16_be(c->in_s, (ds[totalcnt]).width);
+ in_uint8(c->in_s, (ds[totalcnt]).bpp);
+ in_uint8(c->in_s, (ds[totalcnt]).idle_days);
+ in_uint8(c->in_s, (ds[totalcnt]).idle_hours);
+ in_uint8(c->in_s, (ds[totalcnt]).idle_minutes);
+ totalcnt++;
+ }
+ }
+ while (continued);
+
+ printf("fine\n");
+ /* return data... */
+ (*scount) = sescnt;
+ (*s) = ds;
+
+ return SCP_CLIENT_STATE_LIST_OK;
+}
+
+/* 043 */
+enum SCP_CLIENT_STATES_E
+scp_v1c_select_session(struct SCP_CONNECTION* c, struct SCP_SESSION* s, SCP_SID sid)
+{
+ uint32_t version = 1;
+ uint32_t size = 16;
+ uint16_t cmd = 43;
+
+ init_stream(c->out_s, c->out_s->size);
+
+ /* sending our selection */
+ out_uint32_be(c->out_s, version); /* version */
+ out_uint32_be(c->out_s, size); /* size */
+ out_uint16_be(c->out_s, SCP_COMMAND_SET_DEFAULT); /* cmdset */
+ out_uint16_be(c->out_s, cmd); /* cmd */
+
+ out_uint32_be(c->out_s, sid);
+
+ if (0!=tcp_force_send(c->in_sck, c->out_s->data, size))
+ {
+ return SCP_CLIENT_STATE_NETWORK_ERR;
+ }
+
+ /* waiting for response.... */
+ init_stream(c->in_s, c->in_s->size);
+ if (0!=tcp_force_recv(c->in_sck, c->in_s->data, 8))
+ {
+ return SCP_CLIENT_STATE_NETWORK_ERR;
+ }
+
+ in_uint32_be(c->in_s, version);
+ if (version!=1)
+ {
+ return SCP_CLIENT_STATE_VERSION_ERR;
+ }
+
+ in_uint32_be(c->in_s, size);
+ if (size<12)
+ {
+ return SCP_CLIENT_STATE_SIZE_ERR;
+ }
-/* 03x */ enum SCP_CLIENT_STATES_E scp_v1c_retrieve_session(struct SCP_CONNECTION* c, struct SCP_SESSION* s, struct SCP_DISCONNECTED_SESSION* ds);
+ init_stream(c->in_s, c->in_s->size);
+ /* read the rest of the packet */
+ if (0!=tcp_force_recv(c->in_sck, c->in_s->data, size-8))
+ {
+ return SCP_CLIENT_STATE_NETWORK_ERR;
+ }
+
+ in_uint16_be(c->in_s, cmd);
+ if (cmd != SCP_COMMAND_SET_DEFAULT)
+ {
+ return SCP_CLIENT_STATE_SEQUENCE_ERR;
+ }
+
+ in_uint16_be(c->in_s, cmd);
+ if (cmd != 46)
+ {
+ return SCP_CLIENT_STATE_SEQUENCE_ERR;
+ }
+
+ /* session display */
+ in_uint16_be(c->in_s, (s->display));
+ /*we don't need to return any data other than the display */
+ /*because we already sent that */
+
+ return SCP_CLIENT_STATE_OK;
+}
+
+/* 044 */
+enum SCP_CLIENT_STATES_E
+scp_v1c_select_session_cancel(struct SCP_CONNECTION* c)
+{
+ uint32_t version = 1;
+ uint32_t size = 12;
+ uint16_t cmd = 44;
+
+ init_stream(c->out_s, c->out_s->size);
+
+ /* sending our selection */
+ out_uint32_be(c->out_s, version); /* version */
+ out_uint32_be(c->out_s, size); /* size */
+ out_uint16_be(c->out_s, SCP_COMMAND_SET_DEFAULT); /* cmdset */
+ out_uint16_be(c->out_s, cmd); /* cmd */
+
+ if (0!=tcp_force_send(c->in_sck, c->out_s->data, size))
+ {
+ return SCP_CLIENT_STATE_NETWORK_ERR;
+ }
+
+ return SCP_CLIENT_STATE_END;
+}
static enum SCP_CLIENT_STATES_E _scp_v1c_check_response(struct SCP_CONNECTION* c, struct SCP_SESSION* s)
{
@@ -156,7 +356,7 @@ static enum SCP_CLIENT_STATES_E _scp_v1c_check_response(struct SCP_CONNECTION* c
{
return SCP_CLIENT_STATE_NETWORK_ERR;
}
-
+
in_uint32_be(c->in_s, version);
if (version!=1)
{
@@ -166,7 +366,7 @@ static enum SCP_CLIENT_STATES_E _scp_v1c_check_response(struct SCP_CONNECTION* c
in_uint32_be(c->in_s, size);
init_stream(c->in_s, c->in_s->size);
- /* read the rest of the packet */
+ /* read the rest of the packet */
if (0!=tcp_force_recv(c->in_sck, c->in_s->data, size-8))
{
return SCP_CLIENT_STATE_NETWORK_ERR;
@@ -236,10 +436,14 @@ static enum SCP_CLIENT_STATES_E _scp_v1c_check_response(struct SCP_CONNECTION* c
return SCP_CLIENT_STATE_OK;
}
- else if (cmd==32) /* display of a disconnected session */
- {
- return SCP_CLIENT_STATE_RECONNECT;
- }
+ //else if (cmd==31) /* there's a disconnected session */
+ //{
+ // return SCP_CLIENT_STATE_RECONNECT_SINGLE;
+ //}
+ //else if (cmd==33) /* display of a disconnected session */
+ //{
+ // return SCP_CLIENT_STATE_RECONNECT;
+ //}
else if (cmd==40) /* session list */
{
return SCP_CLIENT_STATE_SESSION_LIST;