initial commit
[xdos] / src / server.c
1 #include <string.h>
2 #include "server.h"
3 #include "proto.h"
4 #include "util.h"
5 #include "client.h"
6
7 #define NUM_SCR         1
8 #define NUM_PIXFMT      1
9 static const char *vendor = "John Tsiombikas";
10
11 static int calc_add_size(void);
12 static int calc_info_size(void);
13
14 int server_info(void *buf, int sz)
15 {
16         struct xconn_accept_header *info;
17         char *vendptr;
18         struct xformat *pixfmt;
19         int addsz = calc_add_size();
20         int infosz = addsz + sizeof *info;
21         int vendsz = strlen(vendor);
22
23         if(!buf) return infosz;
24         if(sz < infosz) return -1;
25
26         info = buf;
27         vendptr = (char*)buf + sizeof *info;
28         pixfmt = (struct xformat*)(vendptr + padded_size(vendsz));
29
30         info->success = 1;
31         info->proto_major = PROTO_MAJOR;
32         info->proto_minor = PROTO_MINOR;
33         info->add_length = addsz / 4;   /* in words */
34         info->release = 1;
35         info->resid_base = 0;
36         info->resid_mask = 0xffff;
37         info->motionbuf_size = 0;
38         info->vendor_length = vendsz;
39         info->max_req_length = CLIENT_BUF_SIZE;
40         info->num_screens = NUM_SCR;
41         info->num_pixfmt = NUM_PIXFMT;
42         info->img_byteorder = 0;        /* LSB first */
43         info->bm_fmt_bitorder = 0;      /* least significant */
44         info->bm_fmt_scanline_unit = 1; /* TODO */
45         info->bm_fmt_scanline_pad = 0;
46         info->min_keycode = 0;
47         info->max_keycode = 0xff;
48
49         memcpy(vendptr, vendor, vendsz);
50
51         pixfmt->depth = 24;
52         pixfmt->bpp = 24;
53         pixfmt->scanline_pad = 0;
54
55         return infosz;
56 }
57
58 static int calc_add_size(void)
59 {
60         int ven_len = strlen(vendor);
61         int ven_pad = padding(ven_len);
62         int max_scr = padded_size(NUM_SCR);     /* must be multiple of 4 */
63
64         /* additional data size */
65         return 32 + 8 * NUM_PIXFMT + ven_len + ven_pad + max_scr;
66 }
67
68 static int calc_info_size(void)
69 {
70         return sizeof(struct xconn_accept_header) + calc_add_size();
71 }