void EvalXTCPRecv(const void *obj, qCtx *ctx, qStr *out, qArgAry *args) { Sock *s = (Sock *) obj; int len; char *line = NULL; if (args->Count() > 0) { len = ParseInt((*args)[0]); len = s->Read(len); line = s->GetBuf(); } else { len = s->ReadLine(&line); } if (len > 0) out->PutS(line, len); else if (len < 0 ) { if (len == Sock::ERR_TIMEOUT) { ctx->ThrowF(out, 702, "Timeout while waiting to read data from host %s:%d, %y", s->GetHost(), s->GetPort()); } else { ctx->ThrowF(out, 702, "Error while reading data from host %s:%d, %y", s->GetHost(), s->GetPort(), GetLastError()); } } }
void qObjProto::EvalWhois(qCtx *ctx, qStr *out, qArgAry *args) { if (args->Count() < 1) { ctx->Throw(out, 655, "USAGE: %whois(host[;host;host...][,body[,server[,bindip]]])"); return; } CStrAry hosts; CStr hostStr = (*args)[0]; CStr bodyStr = (*args)[1]; CStr serv = (*args)[2]; CStr bindip = (*args)[3]; ProtoParseHosts(hosts, hostStr); if (hosts.Count() == 0) return; int port; if(serv.IsEmpty()) serv = DEFAULT_WHOIS_HOST; port = IPPORT_WHOIS; int sock_rval, i; Sock sock; if(!bindip.IsEmpty()) sock.Bind(bindip); CStr body, dom, ref, reg, url; qCtxTmp tmpCtx(ctx); if (!bodyStr.IsEmpty()) { tmpCtx.MapObj(&body, "results"); tmpCtx.MapObj(&body, "body"); tmpCtx.MapObj(&dom, "domain"); tmpCtx.MapObj(&ref, "refer"); tmpCtx.MapObj(&dom, "domain-name"); tmpCtx.MapObj(®, "registrar"); tmpCtx.MapObj(&ref, "whois-server"); tmpCtx.MapObj(&url, "referral-url"); } for (i = 0; i < hosts.Count(); ++i) { PROTO_OPEN_SOCK(); body = CStr(); ref = CStr(); dom = hosts[i]; sock.Write(hosts[i]<<"\r\n", hosts[i].Length()+2); do { if ((sock_rval = sock.Read(SOCK_DEFAULT_BUF_SIZE)) < 0) { if (sock_rval == Sock::ERR_TIMEOUT) ctx->ThrowF(out, 705, "Time out while reading from host %s:%d, %y", (const char *) serv, port, GetLastError()); else if (sock_rval) ctx->ThrowF(out, 706, "Error reading from host %s:%d, %y", (const char *) serv, port, GetLastError()); return; } if (!bodyStr.IsEmpty()) body << CStr(sock.GetBuf(), sock_rval); else out->PutS(sock.GetBuf(), sock_rval); } while( sock_rval > 0); // If something was received if (!bodyStr.IsEmpty()) { const char *p; if ((p = stristr(body.GetBuffer(),"Whois Server:"))) { p += 14; while (isspace(*p)) ++p; char *e = strchr(p, '\n'); ref = CStr(p, e-p); } if ((p = stristr(body.GetBuffer(),"Registrar:"))) { p += 14; while (isspace(*p)) ++p; char *e = strchr(p, '\n'); reg = CStr(p, e-p); } if ((p = stristr(body.GetBuffer(),"Referral URL:"))) { p += 14; while (isspace(*p)) ++p; char *e = strchr(p, '\n'); url = CStr(p, e-p); } tmpCtx.Parse(bodyStr, out); } sock.Close(); } return; }