Skip to content
This repository
Browse code

First half of rx events.

  • Loading branch information...
commit 5c03835b772e35367cefe8fec820f1788e550f60 1 parent 895c394
Sound and Fury authored
14  buffer.c
@@ -15,6 +15,7 @@
15 15
 #include "ttyesc.h"
16 16
 #include "bits.h"
17 17
 #include "names.h"
  18
+#include "process.h"
18 19
 #include "text.h"
19 20
 #include "version.h"
20 21
 
@@ -335,12 +336,19 @@ int add_to_buffer(int buf, mtype lm, prio lq, char lp, bool ls, const char *lt,
335 336
 			))
336 337
 		bufs[buf].alert=true;
337 338
 	}
  339
+	int e=0;
338 340
 	if(bufs[buf].logf)
  341
+		e|=log_add(bufs[buf].logf, bufs[buf].logt, lm, lq, lp, ls, lt, ltag, ts);
  342
+	for(symbiont_list *sl=symbionts;sl!=NULL;sl=sl->cdr)
339 343
 	{
340  
-		int e=log_add(bufs[buf].logf, bufs[buf].logt, lm, lq, lp, ls, lt, ltag, ts);
341  
-		if(e) return(e);
  344
+		symbiont *sym=sl->car;
  345
+		for(listen_t *listen=sym->listen;listen!=NULL;listen=listen->next)
  346
+		{
  347
+			if(match_bufspec(buf, listen->where))
  348
+				e|=rx_event(sym, listen->rx, lm, lq, lp, ls, lt, ltag, ts);
  349
+		}
342 350
 	}
343  
-	return(0);
  351
+	return(e);
344 352
 }
345 353
 
346 354
 int redraw_buffer(void)
59  process.c
@@ -17,6 +17,7 @@
17 17
 bufspec parse_bufspec(const char *spec, bufspec home)
18 18
 {
19 19
 	bufspec rv;
  20
+	rv.warned=false;
20 21
 	size_t l_first=strcspn(spec, " \t");
21 22
 	char *first=strndup(spec, l_first);
22 23
 	if(strcmp(first, "status")==0) // we assume the rest-of-line is fine; should perhaps check it?
@@ -104,9 +105,13 @@ char *print_bufspec(bufspec spec)
104 105
 		default:
105 106
 			free(msg);
106 107
 			// shouldn't get here!
107  
-			char emsg[80];
108  
-			snprintf(emsg, 80, "print_bufspec didn't recognise type %d", spec.type);
109  
-			add_to_buffer(0, MT_ERR, PRIO_QUIET, 0, false, emsg, "Internal error: ");
  108
+			if(!spec.warned)
  109
+			{
  110
+				char emsg[80];
  111
+				snprintf(emsg, 80, "print_bufspec didn't recognise type %d", spec.type);
  112
+				add_to_buffer(0, MT_ERR, PRIO_QUIET, 0, false, emsg, "Internal error: ");
  113
+				spec.warned=true;
  114
+			}
110 115
 			return(NULL);
111 116
 	}
112 117
 	return(msg);
@@ -147,12 +152,52 @@ int resolve_bufspec(bufspec spec)
147 152
 			return(-1); // not found
148 153
 	}
149 154
 	// shouldn't get here!
150  
-	char msg[80];
151  
-	snprintf(msg, 80, "resolve_bufspec didn't recognise type %d", spec.type);
152  
-	add_to_buffer(0, MT_ERR, PRIO_QUIET, 0, false, msg, "Internal error: ");
  155
+	if(!spec.warned)
  156
+	{
  157
+		char msg[80];
  158
+		snprintf(msg, 80, "resolve_bufspec didn't recognise type %d", spec.type);
  159
+		add_to_buffer(0, MT_ERR, PRIO_QUIET, 0, false, msg, "Internal error: ");
  160
+		spec.warned=true;
  161
+	}
153 162
 	return(-1);
154 163
 }
155 164
 
  165
+bool match_bufspec(int buf, bufspec spec)
  166
+{
  167
+	switch(spec.type)
  168
+	{
  169
+		case BS_STATUS:
  170
+			return(buf==0);
  171
+		case BS_ANY:
  172
+			return(true);
  173
+		case BS_SERVER:
  174
+			if(bufs[buf].type!=BT_SERVER) return(false);
  175
+			if(!spec.server) return(true); // shouldn't happen
  176
+			return(strcmp(bufs[buf].realsname, spec.server)==0);
  177
+		case BS_CHANNEL:
  178
+			if(bufs[buf].type!=BT_CHANNEL) return(false);
  179
+			if(spec.server)
  180
+				if(strcmp(SERVER(buf).realsname, spec.server)!=0) return(false);
  181
+			if(!spec.channel) return(true);
  182
+			return(strcmp(bufs[buf].bname, spec.channel)==0);
  183
+		case BS_NICK:
  184
+			if(bufs[buf].type!=BT_PRIVATE) return(false);
  185
+			if(spec.server)
  186
+				if(strcmp(SERVER(buf).realsname, spec.server)!=0) return(false);
  187
+			if(!spec.channel) return(true);
  188
+			return(strcmp(bufs[buf].bname, spec.channel)==0);
  189
+	}
  190
+	// shouldn't get here!
  191
+	if(!spec.warned)
  192
+	{
  193
+		char msg[80];
  194
+		snprintf(msg, 80, "match_bufspec didn't recognise type %d", spec.type);
  195
+		add_to_buffer(0, MT_ERR, PRIO_QUIET, 0, false, msg, "Internal error: ");
  196
+		spec.warned=true;
  197
+	}
  198
+	return(false);
  199
+}
  200
+
156 201
 void free_bufspec(bufspec spec)
157 202
 {
158 203
 	free(spec.server);
@@ -221,7 +266,7 @@ int fork_symbiont(symbiont *buf, char *const *argvl)
221 266
 		buf->in=pipes[0][1]; // but we do write stdin
222 267
 		buf->out=pipes[1][0]; // read stdout
223 268
 		buf->err=pipes[2][0]; // and stderr
224  
-		buf->rx=RXM_nil;
  269
+		buf->listen=NULL;
225 270
 		buf->grab=NULL;
226 271
 		return(0);
227 272
 	}
24  process.h
@@ -6,6 +6,7 @@
6 6
 	process: subprocess & symbiont control
7 7
 */
8 8
 
  9
+#include <stdbool.h>
9 10
 #include <sys/types.h>
10 11
 #include "types.h"
11 12
 
@@ -14,6 +15,7 @@ typedef struct
14 15
 	enum {BS_STATUS, BS_ANY, BS_SERVER, BS_CHANNEL, BS_NICK} type; // note that we never store "home 0", we convert it to a definite spec in parse_bufspec
15 16
 	char *server; // this refers to realsname, not bname, which _might_ not be what you want; no guarantee this won't change.  Scripts should generally only use it as a token anyway
16 17
 	char *channel; // for BS_NICK this is <nick> not <channel>
  18
+	bool warned; // have we previously reported this bufspec bad?
17 19
 }
18 20
 bufspec;
19 21
 
@@ -21,23 +23,43 @@ bufspec parse_bufspec(const char *spec, bufspec home); // must free_
21 23
 bufspec clone_bufspec(bufspec spec); // must free_
22 24
 char *print_bufspec(bufspec spec);
23 25
 int resolve_bufspec(bufspec spec);
  26
+bool match_bufspec(int buf, bufspec spec);
24 27
 void free_bufspec(bufspec spec);
25 28
 
26 29
 typedef struct grab_t
27 30
 {
  31
+	bufspec where;
28 32
 	char *cmd;
29 33
 	struct grab_t *next;
30 34
 }
31 35
 grab_t;
32 36
 
  37
+typedef struct listen_t
  38
+{
  39
+	bufspec where;
  40
+	rxmode rx;
  41
+	struct listen_t *next;
  42
+}
  43
+listen_t;
  44
+
33 45
 typedef struct
34 46
 {
35 47
 	pid_t pid;
36 48
 	int in, out, err; // pipe fds, for child's stdin/stdout/stderr
37 49
 	bufspec home; // PRELOAD
38  
-	rxmode rx;
  50
+	listen_t *listen;
39 51
 	grab_t *grab;
40 52
 }
41 53
 symbiont;
42 54
 
  55
+typedef struct symbiont_list
  56
+{
  57
+	symbiont *car;
  58
+	struct symbiont_list *cdr;
  59
+}
  60
+symbiont_list;
  61
+
  62
+symbiont_list *symbionts;
  63
+
43 64
 int fork_symbiont(symbiont *buf, char *const *argvl); // buf should be preloaded with PRELOAD fields
  65
+int rx_event(symbiont *sym, rxmode rx, mtype lm, prio lq, char lp, bool ls, const char *lt, const char *ltag, time_t ts);
2  qsp
@@ -24,7 +24,7 @@ qsp: quIRC symbiont protocol
24 24
 An ':' which should begin an <arg> is encoded as "\072" to distinguish the resulting <arg> from an <argsp>.  In general \ooo octal escapes should be recognised in <arg> and <argsp> words.
25 25
 <server>, <channel> and <nick> are as defined in RFC1459.  However, clients should treat them as anything "matching [^[:space:]]+".
26 26
 The <specbuf>s "any" and "home" may only appear in <request>s, never in <event>s.
27  
-If a <bufspec> could match more than one buffer, the resulting behaviour is implementation-defined.
  27
+If a non-"any" <bufspec> could match more than one buffer, the resulting behaviour is implementation-defined.
28 28
 
29 29
 2 Requests
30 30
 2.1 rxmode
3  quirc.c
@@ -36,6 +36,7 @@
36 36
 #include "config.h"
37 37
 #include "input.h"
38 38
 #include "version.h"
  39
+#include "process.h"
39 40
 
40 41
 int main(int argc, char *argv[])
41 42
 {
@@ -201,6 +202,8 @@ int main(int argc, char *argv[])
201 202
 		return(1);
202 203
 	}
203 204
 	
  205
+	symbionts=NULL;
  206
+	
204 207
 	push_ring(&s_buf, PRIO_QUIET);
205 208
 	
206 209
 	fd_set master, readfds;

0 notes on commit 5c03835

Please sign in to comment.
Something went wrong with that request. Please try again.