use of io.questdb.std.str.DirectByteCharSequence in project questdb by bluestreak01.
the class TextQueryProcessor method parseUrl.
private boolean parseUrl(HttpChunkedResponseSocket socket, HttpRequestHeader request, TextQueryProcessorState state) throws PeerDisconnectedException, PeerIsSlowToReadException {
// Query text.
final DirectByteCharSequence query = request.getUrlParam("query");
if (query == null || query.length() == 0) {
info(state).$("Empty query request received. Sending empty reply.").$();
sendException(socket, 0, "No query text", state);
return false;
}
// Url Params.
long skip = 0;
long stop = Long.MAX_VALUE;
CharSequence limit = request.getUrlParam("limit");
if (limit != null) {
int sepPos = Chars.indexOf(limit, ',');
try {
if (sepPos > 0) {
skip = Numbers.parseLong(limit, 0, sepPos);
if (sepPos + 1 < limit.length()) {
stop = Numbers.parseLong(limit, sepPos + 1, limit.length());
}
} else {
stop = Numbers.parseLong(limit);
}
} catch (NumericException ex) {
// Skip or stop will have default value.
}
}
if (stop < 0) {
stop = 0;
}
if (skip < 0) {
skip = 0;
}
if ((stop - skip) > configuration.getMaxQueryResponseRowLimit()) {
stop = skip + configuration.getMaxQueryResponseRowLimit();
}
state.query.clear();
try {
TextUtil.utf8Decode(query.getLo(), query.getHi(), state.query);
} catch (Utf8Exception e) {
info(state).$("Bad UTF8 encoding").$();
sendException(socket, 0, "Bad UTF8 encoding in query text", state);
return false;
}
CharSequence fileName = request.getUrlParam("filename");
state.fileName = null;
if (fileName != null && fileName.length() > 0) {
state.fileName = fileName.toString();
}
state.skip = skip;
state.count = 0L;
state.stop = stop;
state.noMeta = Chars.equalsNc("true", request.getUrlParam("nm"));
state.countRows = Chars.equalsNc("true", request.getUrlParam("count"));
return true;
}
use of io.questdb.std.str.DirectByteCharSequence in project questdb by bluestreak01.
the class CairoTextWriter method onFieldsNonPartitioned.
public void onFieldsNonPartitioned(long line, ObjList<DirectByteCharSequence> values, int valuesLength) {
final TableWriter.Row w = writer.newRow();
for (int i = 0; i < valuesLength; i++) {
final DirectByteCharSequence dbcs = values.getQuick(i);
if (dbcs.length() == 0) {
continue;
}
if (onField(line, dbcs, w, i))
return;
}
w.append();
}
use of io.questdb.std.str.DirectByteCharSequence in project questdb by bluestreak01.
the class HttpHeaderParser method parse.
public long parse(long ptr, long hi, boolean _method) {
long p;
if (_method && needMethod) {
int l = parseMethod(ptr, hi);
p = ptr + l;
} else {
p = ptr;
}
DirectByteCharSequence v;
while (p < hi) {
if (_wptr == this.hi) {
throw HttpException.instance("header is too large");
}
char b = (char) Unsafe.getUnsafe().getByte(p++);
if (b == '\r') {
continue;
}
Unsafe.getUnsafe().putByte(_wptr++, (byte) b);
switch(b) {
case ':':
if (headerName == null) {
headerName = pool.next().of(_lo, _wptr - 1);
_lo = _wptr + 1;
}
break;
case '\n':
if (headerName == null) {
incomplete = false;
parseKnownHeaders();
return p;
}
v = pool.next().of(_lo, _wptr - 1);
_lo = _wptr;
headers.put(headerName, v);
headerName = null;
break;
default:
break;
}
}
return p;
}
use of io.questdb.std.str.DirectByteCharSequence in project questdb by bluestreak01.
the class HttpHeaderParser method parseContentType.
private void parseContentType() {
DirectByteCharSequence seq = getHeader(CONTENT_TYPE_HEADER);
if (seq == null) {
return;
}
long p = seq.getLo();
long _lo = p;
long hi = seq.getHi();
DirectByteCharSequence name = null;
boolean contentType = true;
boolean swallowSpace = true;
while (p <= hi) {
char b = (char) Unsafe.getUnsafe().getByte(p++);
if (b == ' ' && swallowSpace) {
_lo = p;
continue;
}
if (p > hi || b == ';') {
if (contentType) {
this.contentType = pool.next().of(_lo, p - 1);
_lo = p;
contentType = false;
continue;
}
if (name == null) {
throw HttpException.instance("Malformed ").put(CONTENT_TYPE_HEADER).put(" header");
}
if (Chars.equals("charset", name)) {
this.charset = pool.next().of(_lo, p - 1);
name = null;
_lo = p;
continue;
}
if (Chars.equals("boundary", name)) {
this.boundary = pool.next().of(_lo, p - 1);
_lo = p;
name = null;
continue;
}
if (p > hi) {
break;
}
} else if (b == '=') {
name = name == null ? pool.next().of(_lo, p - 1) : name.of(_lo, p - 1);
_lo = p;
swallowSpace = false;
}
}
}
use of io.questdb.std.str.DirectByteCharSequence in project questdb by bluestreak01.
the class HttpHeaderParser method parseContentDisposition.
private void parseContentDisposition() {
DirectByteCharSequence contentDisposition = getHeader(CONTENT_DISPOSITION_HEADER);
if (contentDisposition == null) {
return;
}
long p = contentDisposition.getLo();
long _lo = p;
long hi = contentDisposition.getHi();
boolean expectFormData = true;
boolean swallowSpace = true;
DirectByteCharSequence name = null;
while (p <= hi) {
char b = (char) Unsafe.getUnsafe().getByte(p++);
if (b == ' ' && swallowSpace) {
_lo = p;
continue;
}
if (p > hi || b == ';') {
if (expectFormData) {
this.contentDisposition = pool.next().of(_lo, p - 1);
_lo = p;
expectFormData = false;
continue;
}
if (name == null) {
throw HttpException.instance("Malformed ").put(CONTENT_DISPOSITION_HEADER).put(" header");
}
if (Chars.equals("name", name)) {
this.contentDispositionName = unquote("name", pool.next().of(_lo, p - 1));
swallowSpace = true;
_lo = p;
name = null;
continue;
}
if (Chars.equals("filename", name)) {
this.contentDispositionFilename = unquote("filename", pool.next().of(_lo, p - 1));
_lo = p;
name = null;
continue;
}
if (p > hi) {
break;
}
} else if (b == '=') {
name = name == null ? pool.next().of(_lo, p - 1) : name.of(_lo, p - 1);
_lo = p;
swallowSpace = false;
}
}
}
Aggregations