ECode ProfileManagerService::NotificationGroupExistsByName(
    /* [in] */ const String& notificationGroupName,
    /* [out] */ Boolean* result)
{
    VALIDATE_NOT_NULL(result);

    AutoPtr<ICollection> values;
    mGroups->GetValues((ICollection**)&values);

    AutoPtr<IIterator> it;
    values->GetIterator((IIterator**)&it);
    Boolean bHasNxt = FALSE;
    while ((it->HasNext(&bHasNxt), bHasNxt)) {
        AutoPtr<IInterface> p;
        it->GetNext((IInterface**)&p);
        AutoPtr<INotificationGroup> group = INotificationGroup::Probe(p);
        String name;
        group->GetName(&name);
        if (name.EqualsIgnoreCase(notificationGroupName)) {
            *result = TRUE;
            return NOERROR;
        }
        it = IIterator::Probe(p);
    }

    *result = FALSE;
    return NOERROR;
}
ECode ProfileManagerService::ProfileExistsByName(
    /* [in] */ const String& profileName,
    /* [out] */ Boolean* result)
{
    VALIDATE_NOT_NULL(result);
    AutoPtr<ISet> entrySet;
    mProfileNames->GetEntrySet((ISet**)&entrySet);

    AutoPtr<IIterator> it;
    entrySet->GetIterator((IIterator**)&it);
    Boolean bHasNxt = FALSE;
    while ((it->HasNext(&bHasNxt), bHasNxt)) {
        AutoPtr<IInterface> p;
        it->GetNext((IInterface**)&p);
        AutoPtr<IMapEntry> entry = IMapEntry::Probe(p);
        AutoPtr<IInterface> k;
        entry->GetKey((IInterface**)&k);
        AutoPtr<ICharSequence> cs = ICharSequence::Probe(k);
        String str;
        cs->ToString(&str);
        if (str.EqualsIgnoreCase(profileName)) {
            *result = TRUE;
            return NOERROR;
        }
    }

    *result = FALSE;
    return NOERROR;
}
Example #3
0
Boolean Request::CanResponseHaveBody(
    /* [in] */ IHttpRequest* request,
    /* [in] */ Int32 status)
{
    AutoPtr<IRequestLine> line;
    request->GetRequestLine((IRequestLine**)&line);
    String str;
    line->GetMethod(&str);
    if (str.EqualsIgnoreCase("HEAD")) {
        return FALSE;
    }
    return status >= IHttpStatus::SC_OK
        && status != IHttpStatus::SC_NO_CONTENT
        && status != IHttpStatus::SC_NOT_MODIFIED;
}
Example #4
0
Boolean Proxy::IsLocalHost(
    /* [in] */ const String& host)
{
    if (host.IsNull()) {
        return FALSE;
    }

    if (!(host.IsNull())) {
        if (host.EqualsIgnoreCase("localhost")) {
            return TRUE;
        }
        AutoPtr<IInetAddress> address;
        NetworkUtils::NumericToInetAddress(host, (IInetAddress**)&address);
        Boolean isLoopback;
        address->IsLoopbackAddress(&isLoopback);
        if (isLoopback == TRUE) {
            return TRUE;
        }
    }

    return FALSE;
}
Example #5
0
ECode Request::ReadResponse(
    /* [in] */ IElastosHttpClientConnection* httpClientConnection)
{
    if (mCancelled){
        return NOERROR; // don't send cancelled requests
    }

    AutoPtr<IStatusLine> statusLine;
    Boolean hasBody = FALSE;
    httpClientConnection->Flush();
    Int32 statusCode = 0;

    AutoPtr<IHeaders> header;
    CHeaders::New((IHeaders**)&header);
    do {
        statusLine = NULL;
        FAIL_RETURN(httpClientConnection->ParseResponseHeader(header, (IStatusLine**)&statusLine));
        statusLine->GetStatusCode(&statusCode);
    } while (statusCode < IHttpStatus::SC_OK);
    if (HttpLog::LOGV) {
        String str;
        IObject::Probe(statusLine)->ToString(&str);
        HttpLog::V(String("Request.readResponseStatus() ") +
                StringUtils::ToString(str.GetLength()) + String(" ") + str);
    }

    AutoPtr<IProtocolVersion> v;
    statusLine->GetProtocolVersion((IProtocolVersion**)&v);
    Int32 major;
    Int32 minor;
    v->GetMajor(&major);
    v->GetMinor(&minor);
    String phrase;
    statusLine->GetReasonPhrase(&phrase);
    mEventHandler->Status(major, minor, statusCode, phrase);
    mEventHandler->Headers(header);
    AutoPtr<IHttpEntity> entity;
    AutoPtr<IHttpRequest> req = IHttpRequest::Probe(mHttpRequest);
    hasBody = CanResponseHaveBody(req, statusCode);

    if (hasBody) {
        httpClientConnection->ReceiveResponseEntity(header, (IHttpEntity**)&entity);
    }

    // restrict the range request to the servers claiming that they are
    // accepting ranges in bytes
    String ranges;
    header->GetAcceptRanges(&ranges);
    Boolean supportPartialContent = ranges.EqualsIgnoreCase("bytes");

    if (entity != NULL) {
        AutoPtr<IInputStream> is;
        entity->GetContent((IInputStream**)&is);

        // process gzip content encoding
        AutoPtr<IHeader> contentEncoding;
        entity->GetContentEncoding((IHeader**)&contentEncoding);
        AutoPtr<IInputStream> nis;
        AutoPtr<ArrayOf<Byte> > buf;
        Int32 count = 0;

        String value;
        if (contentEncoding != NULL &&
            (contentEncoding->GetValue(&value), value).Equals("gzip")) {
            ECode ec = CGZIPInputStream::New(is, (IInputStream**)&nis);
            if(FAILED(ec)) {
                // don't throw if we have a non-OK status code
                if (statusCode == IHttpStatus::SC_OK
                        || statusCode == IHttpStatus::SC_PARTIAL_CONTENT) {
                    if (supportPartialContent && count > 0) {
                        // if there is uncommited content, we should commit them
                        // as we will continue the request
                        mEventHandler->Data(buf, count);
                    }

                    if (nis != NULL) {
                        nis->Close();
                    }

                    return ec;
                }
            }
        } else {
            nis = is;
        }

        /* accumulate enough data to make it worth pushing it
         * up the stack */
        ((Connection*)mConnection.Get())->GetBuf((ArrayOf<Byte>**)&buf);
        Int32 len = 0;
        Int32 lowWater = buf->GetLength() / 2;
        while (len != -1) {
                {
                    AutoLock syncLock(mClientResource);
                    while (mLoadingPaused) {
                        // Put this (network loading) thread to sleep if WebCore
                        // has asked us to. This can happen with plugins for
                        // example, if we are streaming data but the plugin has
                        // filled its internal buffers.
                        if(FAILED(Wait())) {
                            HttpLog::E(String("Interrupted exception whilst network thread paused at WebCore's request."));
                        }
                    }
                }

            ECode ec;
            ec = nis->Read(buf, count, buf->GetLength() - count, &len);
            if(FAILED(ec)) {
                /* InflaterInputStream throws an EOFException when the
                   server truncates gzipped content.  Handle this case
                   as we do truncated non-gzipped content: no error */
                if (count > 0) {
                    // if there is uncommited content, we should commit them
                    mEventHandler->Data(buf, count);
                }
                if (HttpLog::LOGV) HttpLog::V(String("readResponse() handling "));
            }

            if (len != -1) {
                count += len;
                if (supportPartialContent) mReceivedBytes += len;
            }
            if (len == -1 || count >= lowWater) {
                if (HttpLog::LOGV) {
                    HttpLog::V(String("Request.readResponse() ") + StringUtils::ToString(count));
                }
                mEventHandler->Data(buf, count);
                count = 0;
            }
        }

        if (nis != NULL) {
            nis->Close();
        }
    }

    AutoPtr<IProtocolVersion>  ver;
    statusLine->GetProtocolVersion((IProtocolVersion**)&ver);
    Int32 type;
    header->GetConnectionType(&type);
    ((Connection*)mConnection.Get())->SetCanPersist(entity, ver, type);
    mEventHandler->EndData();
    Complete();

    if (HttpLog::LOGV) {
        String name;
        mHost->GetSchemeName(&name);
        String port;
        GetHostPort(&port);
        HttpLog::V("Request.readResponse(): done %s://%s%s",
                name.string(), port.string(), mPath.string());
    }

    return NOERROR;
}