client.c 1.7 KB
Newer Older
Niels Möller's avatar
Niels Möller committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/* client.c
 *
 */

#include "client.h"
#include "version.h"

static int client_initiate(struct client_callback *closure,
		    int fd)
{
  struct abstract_write *write = io_write(closure->backend, fd, closure->block_size,
					  ...close);

  struct session = session_alloc(...);
  session->sent_version = ssh_format("SSH-" PROTOCOL_VERSION
				     "-" SOFTWARE_VERSION " %lS\r\n",
				     closure->id_comment);
  /* FIXME: Retain the version string (by copying or increfing) */
#error foo
  A_WRITE(write, session->sent_version);
  io_read(closure->backend, fd, make_client_read_line());
}

Niels Möller's avatar
Niels Möller committed
24
struct client_line_handler
Niels Möller's avatar
Niels Möller committed
25
{
Niels Möller's avatar
Niels Möller committed
26
27
28
  struct line_handler super;
  struct session *session;
};
Niels Möller's avatar
Niels Möller committed
29

Niels Möller's avatar
Niels Möller committed
30
31
32
33
34
static struct read_handler *do_line(struct client_line_handler *closure,
				    UINT32 length,
				    UINT8 *line)
{
  if ( (length >= 4) && !memcmp(line, "SSH-", 4))
Niels Möller's avatar
Niels Möller committed
35
36
    {
      /* Parse and remember format string */
Niels Möller's avatar
Niels Möller committed
37
38
      if ( ((length >= 8) && !memcmp(line + 4, "2.0-", 4))
	   || ((length >= 9) && !memcmp(line + 4, "1.99-", 5)))
Niels Möller's avatar
Niels Möller committed
39
	{
Niels Möller's avatar
Niels Möller committed
40
41
	  closure->session->recieved_version
	    = ssh_format("%s", length, line);
Niels Möller's avatar
Niels Möller committed
42
43

	  /* return a new read-handler */
Niels Möller's avatar
Niels Möller committed
44
	  return ...
Niels Möller's avatar
Niels Möller committed
45
46
47
48
	}
      else
	{
	  werror("Unsupported protocol version: ");
Niels Möller's avatar
Niels Möller committed
49
	  werror_safe(length, line);
Niels Möller's avatar
Niels Möller committed
50
51
52
53
54
55
56
	  werror("\n");
	  return 0;
	}
    }
  else
    {
      /* Display line */
Niels Möller's avatar
Niels Möller committed
57
      werror_safe(length, line);
Niels Möller's avatar
Niels Möller committed
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74

      /* Read next line */
      return closure;
    }
}

struct fd_callback *make_client_callback(struct io_backend *b,
					 UINT32 block_size)
{
  struct client_callback connected = xalloc(sizeof(struct client_callback));

  connected->c.f = (fd_callback_f) client_initiate;
  connected->backend = b;
  connected->block_size = block_size;
  
  return (struct fd_callback *) connected;
}