Beispiel #1
0
Result
AmfDecoder::doDecodeStringData_AMF3 (Memory   const mem,
                                     Size   * const ret_len,
                                     Size   * const ret_full_len)
{
    Uint32 length;
    if (!decodeU29 (&length))
        return Result::Failure;

    bool const is_ref = !(length & 1);
    length >>= 1;

    Size tocopy;
    Size string_len;
    if (is_ref) {
        StRef<String> const str = getString (length /* index */);
        if (!str) {
            logD_ (_func, "unresolved string reference");
            return Result::Failure;
        }

        string_len = str->len();
        tocopy = (mem.len() > string_len ? string_len : mem.len());
        memcpy (mem.mem(), str->mem().mem(), tocopy);
    } else {
        string_len = length;
        if (msg_len - cur_offset < string_len) {
            logE_ (_func, "message is too short");
            return Result::Failure;
        }

        StRef<String> const str = st_grab (new String (string_len));
        array->get (cur_offset, str->mem());
        string_table.append (str);

        tocopy = (mem.len() > string_len ? string_len : mem.len());
        array->get (cur_offset, mem.region (0, tocopy));
        cur_offset += string_len;
    }

    if (ret_len)
        *ret_len = tocopy;

    if (ret_full_len)
        *ret_full_len = string_len;

    return Result::Success;
}
Beispiel #2
0
Result FileNameToUnixTimeStamp::Convert(const StRef<String> & fileName, /*output*/ Time & timeOfRecord)
{
    if(fileName == NULL || !fileName->len())
        return Result::Failure;

    Result res = Result::Success;
    std::string stdStr(fileName->cstr());
    std::string delimiter1 = "_";
    std::string delimiter2 = ".";
    size_t pos = 0;
    std::string token;
    pos = stdStr.rfind(delimiter1);

    if(pos != std::string::npos)
    {
        token = stdStr.substr(0, pos);
        stdStr.erase(0, pos + delimiter1.length());
        pos = stdStr.rfind(delimiter2);

        if(pos != std::string::npos)
        {
            token = stdStr.substr(0, pos);
            res = strToUint64_safe(token.c_str(), &timeOfRecord);
        }
        else
        {
            logE_(_func_,"Didn't find '.' symbol in file_name = ", fileName->mem());
            res = Result::Failure;
        }
    }
    else
    {
        logE_(_func_,"Didn't find '_' symbol in file_name = ", fileName->mem());
        res = Result::Failure;
    }

    return res;
}