Exemple #1
0
void EvalEqN(const void *data, qCtx *ctx, qStr *out, qArgAry *args) {
	if (args->Count() > 2) {
		if (fabs(ParseDbl((*args)[0])-ParseDbl((*args)[1])) < ParseDbl((*args)[2]))
			out->PutC('T');	
	} else if (args->Count() > 1 && 
			ParseDbl((*args)[0])==ParseDbl((*args)[1]) )
		out->PutC('T');
}
Exemple #2
0
void qObjProto::EvalXTCP(qCtx *ctx, qStr *out, qArgAry *args)
{
    if (args->Count() < 1) {
        ctx->Throw(out, 655, "USAGE: %connect-tcp(host,body[,timeout]])");
        return;
    }

    CStrAry hosts;

    CStr serv = (*args)[0];

    CStr bodyStr = args->GetAt(1);

    double timeout = ParseDbl((*args)[2]);

    if (serv.IsEmpty())
        return;

    int port = 0;

    char * p = strchr((const char *)serv, ':');

    if (p) {
        port = atoi(p+1);
        *p = '\0';
        ++p;
    }

    if (!port)
        port = IPPORT_TELNET;


    int sock_rval;
    Sock sock;

    CStr body, dom, ref;

    qCtxTmp tmpCtx(ctx);

    if (!bodyStr.IsEmpty()) {
        tmpCtx.MapObj(&sock, EvalXTCPSend,"send");
        tmpCtx.MapObj(&sock, EvalXTCPRecv,"recv");
    }

    PROTO_OPEN_SOCK();

    if (timeout > 1)
        sock.SetTimeout((float) timeout);

    tmpCtx.Parse(bodyStr, out);

    sock.Close();

    return;
}
Exemple #3
0
void qObjProto::EvalTCPConn(qCtx *ctx, qStr *out, qArgAry *args) 
{
	if (args->Count() < 1) {
		ctx->Throw(out, 655, "USAGE: %tcp(name,host[,timeout]])");
		return;
	}


	CStr name = (*args)[0];

	CStr serv = (*args)[1];

	double timeout = ParseDbl((*args)[2]);

	if (serv.IsEmpty()) {
		ctx->Throw(out, 656, "%tcp : host unspecified");
		return;
	}
	if (name.IsEmpty()) {
		ctx->Throw(out, 656, "%tcp : connection name unspecified");
		return;
	}

	int port = 0;

	char * p = strchr(serv, ':');

	if (p) {
		port = atoi(p+1);
		*p = '\0';
		++p;

	}

#ifndef IPPORT_TELNET
#define IPPORT_TELNET 23
#endif
	if (!port)
		port = IPPORT_TELNET;

	qObjTcp *conn = new qObjTcp();

	int sock_rval;

	PROTO_OPEN_SOCK2(conn->sock);

	if (timeout > 1)
		conn->sock.SetTimeout((float) timeout);

	ctx->MapObjLet(conn, name);

	return;
}
Exemple #4
0
	int EvalCommRead(qCtx *ctx, qStr *out, qArgAry *args) {
		int maxbuf = args->GetAt(0).IsEmpty() ? 1 :  ParseInt((*args)[0]);
		int timeout = (int) (1000.0 * ParseDbl((*args)[1]));
		CStr eol = (*args)[2];
		CStr buf(maxbuf);
		char *p = buf.Data();
		const char *b = p;
		DWORD dwb;
		COMMTIMEOUTS to, to2;
		if (timeout > 0) {
			GetCommTimeouts(myCom, &to);
			to2 = to;
			to2.ReadTotalTimeoutMultiplier = 0;
			to2.ReadTotalTimeoutConstant = timeout;
			BOOL rVal = SetCommTimeouts(myCom, &to2);
		}
		while (maxbuf > 0) {
			if (!ReadFile(myCom, p, maxbuf, &dwb, 0)) {
				ctx->ThrowF(out, 604, "Read failure : %y", GetLastError());
				return false;
			}

			if (eol.IsEmpty() || dwb == 0)
				break;

			if (p-b >= eol.Length())
				if (strstr(b, eol))
					break;
				else
					b = p-eol.Length()+1;

			maxbuf-=dwb;
			if (maxbuf > 0)
				Sleep(1);
		}
		out->PutS(buf, p-buf.Data());
		if (timeout > 0) {
			SetCommTimeouts(myCom, &to);
		}
		return 0;
	}
Exemple #5
0
void EvalGte(const void *data, qCtx *ctx, qStr *out, qArgAry *args) {
	if (args->Count() > 1 && 
		ParseDbl((*args)[0])>=ParseDbl((*args)[1])
		)
		out->PutC('T');
}