status_t UDF_ReadFromReader(Reader& origReader, UniversalDataFormat& out)
{
    BufferedReader reader(origReader, 1024);
    ulong_t lineNo = 0;
    ulong_t controlDataLength = 0;
    bool eof = false;
    out.reset();
    while (!eof)
    {
        NarrowString line;
        status_t error = reader.readLine(eof, line);
        if (errNone != error)
            return error;
            
        if (eof && line.empty()) //writer puts '\n' after last line... 
            break;

        error = parseUniversalDataFormatTextLine(line.data(), line.length(), out, lineNo, controlDataLength);
        if (errNone != error)
            return error;
    }
    assert(controlDataLength == out.dataLength());
    if (controlDataLength != out.dataLength())
        return SocketConnection::errResponseMalformed
        ;
    return errNone;
}
Example #2
0
static status_t validateAddress(const NarrowString& origAddress, NarrowString& validAddress, ushort_t& port)
{
    NarrowString::size_type pos = origAddress.find(':', 1);
    if (origAddress.npos == pos)
        return netErrParamErr;
    
    ushort_t portLength = origAddress.length() - pos - 1;
    if (portLength>0)
    {
        long value=0;
        status_t error = numericValue(origAddress.data()+pos+1, origAddress.data()+pos+1+portLength, value);
        if ((errNone != error) || (value > ushort_t(-1)))
            return netErrParamErr;

        port = ushort_t(value);
    }

    if (0 == port)
        return netErrParamErr;        

    validAddress.assign(origAddress, 0, pos);
    return errNone;
}
Example #3
0
inline void HexBinEncode(const NarrowString& in, NarrowString& out) {HexBinEncodeBlob(in.data(), in.size(), out);}