示例#1
0
Ref<FetchProtocol>
SourceManager::getFetchProtocolForUri (ConstMemory const uri)
{
    ConstMemory protocol_name;
    {
        Count i = 0;
        for (Count const i_end = uri.len(); i < i_end; ++i) {
            if (uri.mem() [i] == ':')
                break;
        }
        protocol_name = uri.region (0, i);
    }

    Ref<FetchProtocol> fetch_protocol;
    {
        mutex.lock ();
        FetchProtocolHash::EntryKey const fetch_protocol_key = fetch_protocol_hash.lookup (protocol_name);
        if (fetch_protocol_key) {
            fetch_protocol = fetch_protocol_key.getData();
        }
        mutex.unlock ();
    }

    if (!fetch_protocol) {
        logE_ (_func, "Fetch protocol not found: ", protocol_name);
        return NULL;
    }

    return fetch_protocol;
}
示例#2
0
static bool
whitespaceBetweenWordsNeeded (ConstMemory const &left,
			      ConstMemory const &right)
{
    if (left .len() == 0 ||
	right.len() == 0)
    {
	return false;
    }

    if (isalnum (left.mem() [left.len() - 1]) &&
	isalnum (right.mem() [0]))
    {
	return true;
    }

    return false;
}
示例#3
0
void
HttpRequest::parseParameters_paramCallback (ConstMemory   const name,
                                            ConstMemory   const value,
                                            void        * const _self)
{
    HttpRequest * const self = static_cast <HttpRequest*> (_self);

    HttpRequest::Parameter * const param = new (std::nothrow) HttpRequest::Parameter;
    assert (param);
    param->name = name;
    param->value = value;

    self->parameter_hash.add (param);

    //** unescape parsed parameter
    std::string key ((const char*) name.mem(), name.len());
    if(value.len() == 0)
    {
        self->decoded_args[key] = std::string("true");
        return;
    }
    std::string undecoded_value((const char*)value.mem());

    size_t req_end = undecoded_value.find(" HTTP");
    size_t param_end = undecoded_value.find_first_of('&');

    size_t end;

    if (param_end > 0 && req_end == -1)
        end = param_end;
    else if (param_end == -1 && req_end > 0)
        end = req_end;
    else if (param_end > 0 && req_end > 0)
        end = std::min (param_end, req_end);
    else 
        end = undecoded_value.length();

    std::string decoded_value;
    undecoded_value = undecoded_value.substr(0, end);

    url_decode(undecoded_value, decoded_value);

    self->decoded_args[key] = decoded_value;
}
mt_throws AsyncIoResult
NativeAsyncFile::write (ConstMemory   const mem,
                        Size        * const ret_nwritten)
{
    if (ret_nwritten)
	*ret_nwritten = 0;

    // According to POSIX, if we pass a value larger than SSIZE_MAX to read,
    // then the result is implementation-defined.
    Size len;
    if (mem.len() > SSIZE_MAX)
	len = SSIZE_MAX;
    else
	len = mem.len();

    ssize_t const res = ::write (fd, mem.mem(), len);

    if (res == -1) {
	if (errno == EAGAIN || errno == EWOULDBLOCK) {
	    requestOutput ();
	    return AsyncIoResult::Again;
	}

	if (errno == EINTR)
	    return AsyncIoResult::Normal;

	if (errno == EPIPE) {
	  // If there'll be a need to distinguish Eof from Error, then this
	  // is the place to intervene.
	    return AsyncIoResult::Error;
	}

	exc_throw (PosixException, errno);
	exc_push_ (IoException);
	return AsyncIoResult::Error;
    } else
    if (res < 0) {
	exc_throw (InternalException, InternalException::BackendMalfunction);
	return AsyncIoResult::Error;
    }

    if ((Size) res > len) {
	exc_throw (InternalException, InternalException::BackendMalfunction);
	return AsyncIoResult::Error;
    }

    if (ret_nwritten)
	*ret_nwritten = res;

    return AsyncIoResult::Normal;
}
示例#5
0
void _libMary_unreachable_ (ConstMemory const &mem,
                            ConstMemory const &func)
{
    fprintf (stderr, "%.*s%.*s: unreachable point reached\n", (int) mem.len(), mem.mem(), (int) func.len(), func.mem());
    abort ();
}
示例#6
0
void
PagePool::PageListArray::set (Size        const offset,
                              ConstMemory const mem)
{
    doGetSet (offset, NULL /* data_get */, mem.mem() /* data_set */, mem.len(), false /* get */);
}