File: clientutil.c

package info (click to toggle)
wmii 3.9.2%2Bdebian-4
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 2,464 kB
  • sloc: ansic: 24,885; python: 2,123; sh: 1,203; makefile: 403; ruby: 326
file content (50 lines) | stat: -rw-r--r-- 863 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#define IXP_NO_P9_
#define IXP_P9_STRUCTS
#define CLIENTEXTERN
#include <string.h>
#include <ixp.h>
#include <clientutil.h>
#include <util.h>

static IxpCFid*	ctlfid;
static char 	ctl[1024];
static char*	ectl;

char*
readctl(char *key) {
	char *s, *p;
	int nkey, n;

	if(ctlfid == nil) {
		ctlfid = ixp_open(client, "ctl", OREAD);
		n = ixp_read(ctlfid, ctl, 1023);
		ectl = ctl + n;
		ixp_close(ctlfid);
	}

	nkey = strlen(key);
	p = ctl - 1;
	do {
		p++;
		if(!strncmp(p, key, nkey)) {
			p += nkey;
			s = strchr(p, '\n');
			n = (s ? s : ectl) - p;
			s = freelater(emalloc(n + 1));
			s[n] = '\0';
			return strncpy(s, p, n);
		}
	} while((p = strchr(p, '\n')));
	return "";
}

void
client_init(char* address) {
	if(address && *address)
		client = ixp_mount(address);
	else
		client = ixp_nsmount("wmii");
	if(client == nil)
		fatal("can't mount: %r\n");
}