예제 #1
0
/* Update the client property BLOB handling policy */
void crackBLOBHandling(const char *dev, const char *name, const char *enableBLOB, ClInfo *cp)
{
    int i=0;

    /* If we have EnableBLOB with property name, we add it to Client device list */
    if (name[0])
        addClDevice (cp, dev, name, 1);
    else
    /* Otherwise, we set the whole client blob handling to what's passed (enableBLOB) */
        crackBLOB(enableBLOB, &cp->blob);

    /* If whole client blob handling policy was updated, we need to pass that also to all children
       and if the request was for a specific property, then we apply the policy to it */
    for (i = 0; i < cp->nprops; i++)
    {
        Property *pp = &cp->props[i];
        if (!name[0])
            crackBLOB(enableBLOB, &pp->blob);
        else if (!strcmp (pp->dev, dev) && (!strcmp(pp->name, name)))
        {
            crackBLOB(enableBLOB, &pp->blob);
            return;
        }
    }
}
예제 #2
0
/* read more from the given client, send to each appropriate driver when see
 * xml closure. also send all newXXX() to all other interested clients.
 * shut down client if any trouble.
 */
static void
clientMsg (ClInfo *cp)
{
	char buf[BUFSZ];
	int i, nr;

	/* read client */
	nr = read (cp->s, buf, sizeof(buf));
	if (nr < 0) {
	    fprintf (stderr, "Client %d: %s\n", cp->s, strerror(errno));
	    shutdownClient (cp);
	    return;
	}
	if (nr == 0) {
	    if (verbose)
		fprintf (stderr, "Client %d: read EOF\n", cp->s);
	    shutdownClient (cp);
	    return;
	} 
	if (verbose > 2)
	    fprintf (stderr, "Client %d: read %d:\n%.*s", cp->s, nr, nr, buf);

	/* process XML, sending when find closure */
	for (i = 0; i < nr; i++) {
	    char err[1024];
	    XMLEle *root = readXMLEle (cp->lp, buf[i], err);
	    if (root) {
		char *roottag = tagXMLEle(root);

		if (verbose > 1)
		    fprintf (stderr, "Client %d: read %s\n", cp->s,
		    						xmlLog(root));

		/* record BLOB message locally, others go to matching drivers */
		if (!strcmp (roottag, "enableBLOB")) {
		    cp->blob = crackBLOB (pcdataXMLEle(root));
		    delXMLEle (root);
		} else {
		    char *dev = findXMLAttValu (root, "device");

		    /* snag interested devices */
		    if (!strcmp (roottag, "getProperties"))
			addClDevice (cp, dev);

		    /* send message to driver(s) responsible for dev */
		    send2Drivers (root, dev);

		    /* echo new* commands back to other clients, else done */
		    if (!strncmp (roottag, "new", 3))
			send2Clients (cp, root, dev); /* does delXMLEle */
		    else
			delXMLEle (root);
		}
	    } else if (err[0])
		fprintf (stderr, "Client %d: %s\n", cp->s, err);
	}
}
예제 #3
0
/* read more from the given client, send to each appropriate driver when see
 * xml closure. also send all newXXX() to all other interested clients.
 * return -1 if had to shut down anything, else 0.
 */
int
readFromClient (ClInfo *cp)
{
	char buf[MAXRBUF];
	int shutany = 0;
	ssize_t i, nr;

	/* read client */
	nr = read (cp->s, buf, sizeof(buf));
	if (nr <= 0) {
	    if (nr < 0)
		fprintf (stderr, "%s: Client %d: read: %s\n", indi_tstamp(NULL),
							cp->s, strerror(errno));
	    else if (verbose > 0)
		fprintf (stderr, "%s: Client %d: read EOF\n", indi_tstamp(NULL),
									cp->s);
	    shutdownClient (cp);
	    return (-1);
	}

	/* process XML, sending when find closure */
	for (i = 0; i < nr; i++) {
	    char err[1024];
	    XMLEle *root = readXMLEle (cp->lp, buf[i], err);
	    if (root) {
		char *roottag = tagXMLEle(root);
		const char *dev = findXMLAttValu (root, "device");
		const char *name = findXMLAttValu (root, "name");
		int isblob = !strcmp (tagXMLEle(root), "setBLOBVector");
		Msg *mp;

		if (verbose > 2) {
		    fprintf (stderr, "%s: Client %d: read ",indi_tstamp(NULL),cp->s);
		    traceMsg (root);
		} else if (verbose > 1) {
		    fprintf (stderr, "%s: Client %d: read <%s device='%s' name='%s'>\n",
				    indi_tstamp(NULL), cp->s, tagXMLEle(root),
				    findXMLAttValu (root, "device"),
				    findXMLAttValu (root, "name"));
		}

		/* snag interested properties.
		 * N.B. don't open to alldevs if seen specific dev already, else
		 *   remote client connections start returning too much.
		 */
		if (dev[0])
                    addClDevice (cp, dev, name, isblob);
		else if (!strcmp (roottag, "getProperties") && !cp->nprops)
		    cp->allprops = 1;

		/* snag enableBLOB -- send to remote drivers too */
		if (!strcmp (roottag, "enableBLOB"))
                   // crackBLOB (pcdataXMLEle(root), &cp->blob);
                     crackBLOBHandling (dev, name, pcdataXMLEle(root), cp);

		/* build a new message -- set content iff anyone cares */
		mp = newMsg();

		/* send message to driver(s) responsible for dev */
		q2RDrivers (dev, mp, root);

		/* echo new* commands back to other clients */
		if (!strncmp (roottag, "new", 3)) {
                    if (q2Clients (cp, isblob, dev, name, mp, root) < 0)
			shutany++;
		}

		/* set message content if anyone cares else forget it */
		if (mp->count > 0)
		    setMsgXMLEle (mp, root);
		else
		    freeMsg (mp);
		delXMLEle (root);

	    } else if (err[0]) {
		char *ts = indi_tstamp(NULL);
		fprintf (stderr, "%s: Client %d: XML error: %s\n", ts,
								cp->s, err);
		fprintf (stderr, "%s: Client %d: XML read: %.*s\n", ts,
							    cp->s, (int)nr, buf);
		shutdownClient (cp);
		return (-1);
	    }
	}

	return (shutany ? -1 : 0);
}