+
+void *nterfacer_sendline(char *service, char *command, int argc, char **argv, rline_callback callback, void *tag) {
+ struct service_node *servicep;
+ struct rline *prequest;
+ struct handler *hl;
+ int re;
+
+ for(servicep=tree;servicep;servicep=servicep->next)
+ if(!strcmp(servicep->name->content, service))
+ break;
+
+ if(!servicep) {
+ Error("nterfacer", ERR_WARNING, "sendline: service not found: %s", service);
+ return NULL;
+ }
+
+ for(hl=servicep->handlers;hl;hl=hl->next)
+ if(!strcmp(hl->command->content, command))
+ break;
+
+ if(!hl) {
+ Error("nterfacer", ERR_WARNING, "sendline: command not found: %s", command);
+ return NULL;
+ }
+
+ if(argc < hl->args) {
+ Error("nterfacer", ERR_WARNING, "sendline: wrong number of arguments: %s", command);
+ return NULL;
+ }
+
+ prequest = (struct rline *)ntmalloc(sizeof(struct rline));
+ if(!prequest) {
+ MemError();
+ return NULL;
+ }
+
+ prequest->service = servicep;
+ prequest->handler = hl;
+ prequest->buf[0] = '\0';
+ prequest->curpos = prequest->buf;
+ prequest->tag = tag;
+ prequest->id = 0;
+ prequest->next = rlines;
+ prequest->socket = NULL;
+ prequest->callback = callback;
+
+ rlines = prequest;
+ re = (hl->function)(prequest, argc, argv);
+
+ if(re) {
+ Error("nterfacer", ERR_WARNING, "sendline: error occured calling %s %d: %s", command, re, request_error(re));
+ return NULL;
+ }
+
+ return (void *)prequest;
+}
+
+void nterfacer_freeline(void *tag) {
+ struct rline *prequest = tag;
+
+ prequest->callback = NULL;
+}
+
+#define MAX_LINES 8192
+
+/* this bites */
+static void nterfacer_sendcallback(struct rline *ri, int error, char *buf) {
+ char *lines[MAX_LINES+1];
+ char newbuf[MAX_BUFSIZE+5];
+ char *s, *d, *laststart;
+ int linec = 0;
+
+ for(s=buf,laststart=d=newbuf;*s;s++) {
+ if((*s == '\\') && *(s + 1)) {
+ if(*(s + 1) == ',') {
+ *d++ = ',';
+ } else if(*(s + 1) == '\\') {
+ *d++ = '\\';
+ }
+ s++;
+ } else if(*s == ',') {
+ *d++ = '\0';
+ if(linec >= MAX_LINES - 5) {
+ nterfacer_sendcallback(ri, BF_OVER, "Buffer overflow.");
+ return;
+ }
+
+ lines[linec++] = laststart;
+ laststart = d;
+ } else {
+ *d++ = *s;
+ }
+ }
+ *d = '\0';
+ lines[linec++] = laststart;
+
+ ri->callback(error, linec, lines, ri->tag);
+}