Пример #1
0
ClientGUI::ClientGUI(QWidget *parent) :
QMainWindow(parent)
{
	qDebug("Client UI setup");
	setupUi(this);
	move(100,22);
	
	m_tcpSocket = new QTcpSocket(this);
		
	// network widgets
	connect(pushButtonConnect, SIGNAL(clicked()), this, SLOT(hostAction()));
	connect(pushButtonSend, SIGNAL(clicked()), this, SLOT(sendToHost()));
	connect(lineEditCommand, SIGNAL(returnPressed()), this, SLOT(sendToHost()));
	
	connect(m_tcpSocket, SIGNAL(readyRead()), this, SLOT(readFromHost()));
	connect(m_tcpSocket, SIGNAL(disconnected()), this, SLOT(hostDisconnect()));
	connect(m_tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)),
             this, SLOT(hostError(QAbstractSocket::SocketError)));

	pushButtonSend->setEnabled(false);
	pushButtonConnect->setText("Connect");
	
	ipAddress = "NULL";
	lineEditAddress->setText(QHostAddress(QHostAddress::LocalHost).toString());
	lineEditPort->setText(QString::number(50657));
	lineEditPort->setFocus();
}
Пример #2
0
/*
 * Finally, bring it all together to handle parsing full connection URLs:
 *
 * pcp://oss.sgi.com:45892?user=otto&pass=blotto&compress=true
 * pcps://[email protected]:45893?user=jimbo&pass=jones&compress=true
 * local://path/to/socket:?user=jimbo&pass=jones
 * unix://path/to/socket
 */
int
__pmParseHostAttrsSpec(
    const char *spec,           /* the original, complete string to parse */
    pmHostSpec **host,          /* hosts result allocated and returned here */
    int *count,
    __pmHashCtl *attributes,
    char **errmsg)              /* error message */
{
    char *value = NULL, *s = (char *)spec;
    int sts, attr;

    *count = 0;			/* ensure this initialised for fail: code */

    /* parse optional protocol section */
    if ((sts = parseProtocolSpec(spec, &s, &attr, &value, errmsg)) < 0)
	return sts;

    if (attr == PCP_ATTR_LOCAL || attr == PCP_ATTR_UNIXSOCK) {
	/* We are looking for a socket path. */
	if ((sts = parseSocketPath(spec, &s, host)) < 0)
	    goto fail;
	*count = 1;
	host[0]->nports = (attr == PCP_ATTR_LOCAL) ?
	    PM_HOST_SPEC_NPORTS_LOCAL : PM_HOST_SPEC_NPORTS_UNIX;
    }
    else {
	/* We are looking for a host spec. */
	if ((sts = parseHostSpec(spec, &s, host, count, errmsg)) < 0)
	    goto fail;
    }

    /* skip over an attributes delimiter */
    if (*s == '?') {
	s++;	/* optionally skip over the question mark */
    } else if (*s != '\0' && *s != '/') {
	hostError(spec, s, "unexpected terminal character", errmsg);
	sts = PM_ERR_GENERIC;
	goto fail;
    }

    /* parse optional attributes section */
    if ((sts = parseAttributeSpec(spec, &s, attr, value, attributes, errmsg)) < 0)
	goto fail;

    return 0;

fail:
    if (value)
	free(value);
    if (*count)
	__pmFreeHostSpec(*host, *count);
    *count = 0;
    *host = NULL;
    return sts;
}
Пример #3
0
int
__pmParseHostSpec(
    const char *spec,           /* parse this string */
    pmHostSpec **rslt,          /* result allocated and returned here */
    int *count,			/* number of host specs returned here */
    char **errmsg)              /* error message */
{
    char *s = (char *)spec;
    int sts;

    if ((sts = parseHostSpec(spec, &s, rslt, count, errmsg)) < 0)
	return sts;

    if (*s == '\0')
	return 0;

    hostError(spec, s, "unexpected terminal character", errmsg);
    __pmFreeHostSpec(*rslt, *count);
    *rslt = NULL;
    *count = 0;
    return PM_ERR_GENERIC;
}
Пример #4
0
/*
 * Parse a host specification, with optional ports and proxy host(s).
 * Examples:
 *	pcp -h app1.aconex.com:44321,[email protected]:44322
 *	pcp -h app1.aconex.com:[email protected]:44322
 *	pcp -h app1.aconex.com:[email protected]
 *	pcp -h [email protected]
 *	pcp -h app1.aconex.com:44321
 *      pcp -h 192.168.122.1:44321
 *      pcp -h [fe80::5eff:35ff:fe07:55ca]:44321,4321@[fe80::5eff:35ff:fe07:55cc]:44322
 *      pcp -h [fe80::5eff:35ff:fe07:55ca]:44321
 *
 * Basic algorithm:
 *	look for first colon, @ or null; preceding text is hostname
 *	 if colon, look for comma, @ or null, preceding text is port
 *	  while comma, look for comma, @ or null, preceding text is next port
 *	if @, start following host specification at the following character,
 *	 by returning to the start and repeating the above for the next chunk.
 * Note:
 *      IPv6 addresses contain colons and, so, must be separated from the
 *      rest of the spec somehow. A common notation among ipv6-enabled
 *      applications is to enclose the address within brackets, as in
 *      [fe80::5eff:35ff:fe07:55ca]:44321. We keep it simple, however,
 *      and allow any host spec to be enclosed in brackets.
 * Note:
 *	Currently only two hosts are useful, but ability to handle more than
 *	one optional proxy host is there (i.e. proxy ->proxy ->... ->pmcd),
 *	in case someone implements the pmproxy->pmproxy protocol extension.
 */
static int      /* 0 -> ok, PM_ERR_GENERIC -> error message is set */
parseHostSpec(
    const char *spec,
    char **position,            /* parse this string, return end char */
    pmHostSpec **rslt,          /* result allocated and returned here */
    int *count,
    char **errmsg)              /* error message */
{
    pmHostSpec *hsp = NULL;
    const char *s, *start, *next;
    int nhosts = 0, sts = 0;

    for (s = start = *position; s != NULL; s++) {
	/* Allow the host spec to be enclosed in brackets. */
	if (s == start && *s == '[') {
	    for (s++; *s != ']' && *s != '\0'; s++)
		;
	    if (*s != ']') {
		hostError(spec, s, "missing closing ']' for host spec", errmsg);
		sts = PM_ERR_GENERIC;
		goto fail;
	    }
	    next = s + 1; /* past the trailing ']' */
	    if (*next != ':' && *next != '@' && *next != '\0' && *next != '/' && *next != '?') {
		hostError(spec, next, "extra characters after host spec", errmsg);
		sts = PM_ERR_GENERIC;
		goto fail;
	    }
	    start++; /* past the initial '[' */
	}
	else
	    next = s;
	if (*next == ':' || *next == '@' || *next == '\0' || *next == '/' || *next == '?') {
	    if (s == *position)
		break;
	    else if (s == start)
		continue;
	    hsp = hostAdd(hsp, &nhosts, start, s - start);
	    if (hsp == NULL) {
		sts = -ENOMEM;
		goto fail;
	    }
	    s = next;
	    if (*s == ':') {
		for (++s, start = s; s != NULL; s++) {
		    if (*s == ',' || *s == '@' || *s == '\0' || *s == '/' || *s == '?') {
			if (s - start < 1) {
			    hostError(spec, s, "missing port", errmsg);
			    sts = PM_ERR_GENERIC;
			    goto fail;
			}
			int port = atoi(start);
			sts = __pmAddHostPorts(&hsp[nhosts-1], &port, 1);
			if (sts < 0)
			    goto fail;
			start = s + 1;
			if (*s == '@' || *s == '\0' || *s == '/' || *s == '?')
			    break;
			continue;
		    }
		    if (isdigit((int)*s))
			continue;
		    hostError(spec, s, "non-numeric port", errmsg);
		    sts = PM_ERR_GENERIC;
		    goto fail;
		}
	    }
	    if (*s == '@') {
		start = s+1;
		continue;
	    }
	    break;
	}
    }
    *position = (char *)s;
    *count = nhosts;
    *rslt = hsp;
    return 0;

fail:
    __pmFreeHostSpec(hsp, nhosts);
    *rslt = NULL;
    *count = 0;
    return sts;
}