Permalink
Browse files

First half of rx events.

  • Loading branch information...
ec429 committed Jun 20, 2013
1 parent 895c394 commit 5c03835b772e35367cefe8fec820f1788e550f60
Showing with 90 additions and 12 deletions.
  1. +11 −3 buffer.c
  2. +52 −7 process.c
  3. +23 −1 process.h
  4. +1 −1 qsp
  5. +3 −0 quirc.c
View
@@ -15,6 +15,7 @@
#include "ttyesc.h"
#include "bits.h"
#include "names.h"
+#include "process.h"
#include "text.h"
#include "version.h"
@@ -335,12 +336,19 @@ int add_to_buffer(int buf, mtype lm, prio lq, char lp, bool ls, const char *lt,
))
bufs[buf].alert=true;
}
+ int e=0;
if(bufs[buf].logf)
+ e|=log_add(bufs[buf].logf, bufs[buf].logt, lm, lq, lp, ls, lt, ltag, ts);
+ for(symbiont_list *sl=symbionts;sl!=NULL;sl=sl->cdr)
{
- int e=log_add(bufs[buf].logf, bufs[buf].logt, lm, lq, lp, ls, lt, ltag, ts);
- if(e) return(e);
+ symbiont *sym=sl->car;
+ for(listen_t *listen=sym->listen;listen!=NULL;listen=listen->next)
+ {
+ if(match_bufspec(buf, listen->where))
+ e|=rx_event(sym, listen->rx, lm, lq, lp, ls, lt, ltag, ts);
+ }
}
- return(0);
+ return(e);
}
int redraw_buffer(void)
View
@@ -17,6 +17,7 @@
bufspec parse_bufspec(const char *spec, bufspec home)
{
bufspec rv;
+ rv.warned=false;
size_t l_first=strcspn(spec, " \t");
char *first=strndup(spec, l_first);
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)
default:
free(msg);
// shouldn't get here!
- char emsg[80];
- snprintf(emsg, 80, "print_bufspec didn't recognise type %d", spec.type);
- add_to_buffer(0, MT_ERR, PRIO_QUIET, 0, false, emsg, "Internal error: ");
+ if(!spec.warned)
+ {
+ char emsg[80];
+ snprintf(emsg, 80, "print_bufspec didn't recognise type %d", spec.type);
+ add_to_buffer(0, MT_ERR, PRIO_QUIET, 0, false, emsg, "Internal error: ");
+ spec.warned=true;
+ }
return(NULL);
}
return(msg);
@@ -147,12 +152,52 @@ int resolve_bufspec(bufspec spec)
return(-1); // not found
}
// shouldn't get here!
- char msg[80];
- snprintf(msg, 80, "resolve_bufspec didn't recognise type %d", spec.type);
- add_to_buffer(0, MT_ERR, PRIO_QUIET, 0, false, msg, "Internal error: ");
+ if(!spec.warned)
+ {
+ char msg[80];
+ snprintf(msg, 80, "resolve_bufspec didn't recognise type %d", spec.type);
+ add_to_buffer(0, MT_ERR, PRIO_QUIET, 0, false, msg, "Internal error: ");
+ spec.warned=true;
+ }
return(-1);
}
+bool match_bufspec(int buf, bufspec spec)
+{
+ switch(spec.type)
+ {
+ case BS_STATUS:
+ return(buf==0);
+ case BS_ANY:
+ return(true);
+ case BS_SERVER:
+ if(bufs[buf].type!=BT_SERVER) return(false);
+ if(!spec.server) return(true); // shouldn't happen
+ return(strcmp(bufs[buf].realsname, spec.server)==0);
+ case BS_CHANNEL:
+ if(bufs[buf].type!=BT_CHANNEL) return(false);
+ if(spec.server)
+ if(strcmp(SERVER(buf).realsname, spec.server)!=0) return(false);
+ if(!spec.channel) return(true);
+ return(strcmp(bufs[buf].bname, spec.channel)==0);
+ case BS_NICK:
+ if(bufs[buf].type!=BT_PRIVATE) return(false);
+ if(spec.server)
+ if(strcmp(SERVER(buf).realsname, spec.server)!=0) return(false);
+ if(!spec.channel) return(true);
+ return(strcmp(bufs[buf].bname, spec.channel)==0);
+ }
+ // shouldn't get here!
+ if(!spec.warned)
+ {
+ char msg[80];
+ snprintf(msg, 80, "match_bufspec didn't recognise type %d", spec.type);
+ add_to_buffer(0, MT_ERR, PRIO_QUIET, 0, false, msg, "Internal error: ");
+ spec.warned=true;
+ }
+ return(false);
+}
+
void free_bufspec(bufspec spec)
{
free(spec.server);
@@ -221,7 +266,7 @@ int fork_symbiont(symbiont *buf, char *const *argvl)
buf->in=pipes[0][1]; // but we do write stdin
buf->out=pipes[1][0]; // read stdout
buf->err=pipes[2][0]; // and stderr
- buf->rx=RXM_nil;
+ buf->listen=NULL;
buf->grab=NULL;
return(0);
}
View
@@ -6,6 +6,7 @@
process: subprocess & symbiont control
*/
+#include <stdbool.h>
#include <sys/types.h>
#include "types.h"
@@ -14,30 +15,51 @@ typedef struct
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
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
char *channel; // for BS_NICK this is <nick> not <channel>
+ bool warned; // have we previously reported this bufspec bad?
}
bufspec;
bufspec parse_bufspec(const char *spec, bufspec home); // must free_
bufspec clone_bufspec(bufspec spec); // must free_
char *print_bufspec(bufspec spec);
int resolve_bufspec(bufspec spec);
+bool match_bufspec(int buf, bufspec spec);
void free_bufspec(bufspec spec);
typedef struct grab_t
{
+ bufspec where;
char *cmd;
struct grab_t *next;
}
grab_t;
+typedef struct listen_t
+{
+ bufspec where;
+ rxmode rx;
+ struct listen_t *next;
+}
+listen_t;
+
typedef struct
{
pid_t pid;
int in, out, err; // pipe fds, for child's stdin/stdout/stderr
bufspec home; // PRELOAD
- rxmode rx;
+ listen_t *listen;
grab_t *grab;
}
symbiont;
+typedef struct symbiont_list
+{
+ symbiont *car;
+ struct symbiont_list *cdr;
+}
+symbiont_list;
+
+symbiont_list *symbionts;
+
int fork_symbiont(symbiont *buf, char *const *argvl); // buf should be preloaded with PRELOAD fields
+int rx_event(symbiont *sym, rxmode rx, mtype lm, prio lq, char lp, bool ls, const char *lt, const char *ltag, time_t ts);
View
2 qsp
@@ -24,7 +24,7 @@ qsp: quIRC symbiont protocol
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.
<server>, <channel> and <nick> are as defined in RFC1459. However, clients should treat them as anything "matching [^[:space:]]+".
The <specbuf>s "any" and "home" may only appear in <request>s, never in <event>s.
-If a <bufspec> could match more than one buffer, the resulting behaviour is implementation-defined.
+If a non-"any" <bufspec> could match more than one buffer, the resulting behaviour is implementation-defined.
2 Requests
2.1 rxmode
View
@@ -36,6 +36,7 @@
#include "config.h"
#include "input.h"
#include "version.h"
+#include "process.h"
int main(int argc, char *argv[])
{
@@ -201,6 +202,8 @@ int main(int argc, char *argv[])
return(1);
}
+ symbionts=NULL;
+
push_ring(&s_buf, PRIO_QUIET);
fd_set master, readfds;

0 comments on commit 5c03835

Please sign in to comment.