Beispiel #1
0
void JIceNotify::postList(const std::string &domain, const std::list<std::string> &data)
{
    ::Notify::JIceNotifyPrx proxy = parseDomain(domain);
    if (proxy) {
        proxy->postList(domain, data);
    }
}
Beispiel #2
0
void JIceNotify::postString(const std::string &domain, const std::string &msg)
{
    ::Notify::JIceNotifyPrx proxy = parseDomain(domain);
    if (proxy) {
        proxy->postString(domain, msg);
    }
}
Beispiel #3
0
void JIceNotify::postBuffer(const std::string &domain, const char *buffer, int size)
{
    ::Notify::JIceNotifyPrx proxy = parseDomain(domain);
    if (proxy) {
        proxy->postBuffer(domain, std::make_pair<::Ice::Byte*, ::Ice::Byte*>(
                              (::Ice::Byte*)buffer, (::Ice::Byte*)(buffer + size)));
    }
}
Beispiel #4
0
int JIceNotify::sendList(const std::string &domain, const std::list<std::string> &data)
{
    ::Notify::JIceNotifyPrx proxy = parseDomain(domain);
    if (proxy) {
        return proxy->sendList(domain, data);
    } else {
        return IIceNotify::ProxyInvalid;
    }
}
Beispiel #5
0
int JIceNotify::sendString(const std::string &domain, const std::string &msg)
{
    ::Notify::JIceNotifyPrx proxy = parseDomain(domain);
    if (proxy) {
        return proxy->sendString(domain, msg);
    } else {
        return IIceNotify::ProxyInvalid;
    }
}
Beispiel #6
0
int JIceNotify::sendBuffer(const std::string &domain, const char *buffer, int size)
{
    ::Notify::JIceNotifyPrx proxy = parseDomain(domain);
    if (proxy) {
        return proxy->sendBuffer(domain, std::make_pair<::Ice::Byte*, ::Ice::Byte*>(
                                     (::Ice::Byte*)buffer, (::Ice::Byte*)(buffer + size)));
    } else {
        return IIceNotify::ProxyInvalid;
    }
}
Beispiel #7
0
/*
 * 获取该规则期望过滤的域名
 */
void FilterRule::getDomains(StringVector & domains)
{
	if(!m_domains.empty())
	{
		domains.insert(domains.end(),m_domains.begin(),m_domains.end());
		return;
	}
	std::string s=parseDomain(m_reFilter);
	if(!s.empty())
		domains.push_back(s);
}
Beispiel #8
0
void JIceNotify::postVariant(const QString &domain, const QVariant &variant)
{
    ::Notify::JIceNotifyPrx proxy = parseDomain(domain.toStdString());
    if (!proxy) {
        std::string s;
        switch (variant.type()) {
        case QVariant::Bool:

            break;
        default:
            return;
        }
        proxy->sendVariant(domain.toStdString(), s);
    }

    //
}
Beispiel #9
0
int JIceNotify::sendVariant(const QString &domain, const QVariant &variant)
{
    ::Notify::JIceNotifyPrx proxy = parseDomain(domain.toStdString());
    if (proxy) {
        std::string s;
        switch (variant.type()) {
        case QVariant::Bool:
            s = variant.toString().toStdString();
            break;
        default:
            return IIceNotify::VariantNotSupported;
        }
        return proxy->sendVariant(domain.toStdString(), s);
    } else {
        return IIceNotify::ProxyInvalid;
    }
}
Beispiel #10
0
bool cWebvideoConfig::ReadConfigFile(const char *inifile) {
    dictionary *conf = iniparser_load(inifile);

    if (!conf)
        return false;

    info("loading config file %s", inifile);

    const char *templatepath = iniparser_getstring(conf, "webvi:templatepath", NULL);
    if (templatepath) {
        debug("templatepath = %s (from %s)", templatepath, inifile);
        SetTemplatePath(templatepath);
    }

    const char *vfat = iniparser_getstring(conf, "webvi:vfat", NULL);
    if (vfat) {
        debug("vfat = %s (from %s)", vfat, inifile);

        if (strcmp(vfat, "1") == 0 ||
                strcmp(vfat, "true") == 0 ||
                strcmp(vfat, "yes") == 0 ||
                strcmp(vfat, "on") == 0)
        {
            vfatNames = true;
        } else if (strcmp(vfat, "0") == 0 ||
                   strcmp(vfat, "false") == 0 ||
                   strcmp(vfat, "no") == 0 ||
                   strcmp(vfat, "off") == 0)
        {
            vfatNames = false;
        } else {
            warning("Invalid value for config option vfat: %s in %s", vfat, inifile);
        }
    }

    for (int i=0; i<iniparser_getnsec(conf); i++) {
        const char *section = iniparser_getsecname(conf, i);

        if (strcmp(section, "webvi") != 0) {
            const int maxsectionlen = 100;
            char key[128];
            char *keyname;
            const char *sitename;

            cString domain = parseDomain(section);
            if (strlen(domain) == 0)
                sitename = section;
            else
                sitename = domain;

            strncpy(key, section, maxsectionlen);
            key[maxsectionlen] = '\0';
            strcat(key, ":");
            keyname = key+strlen(key);

            strcpy(keyname, "download-min-quality");
            const char *download_min = iniparser_getstring(conf, key, NULL);

            strcpy(keyname, "download-max-quality");
            const char *download_max = iniparser_getstring(conf, key, NULL);

            strcpy(keyname, "stream-min-quality");
            const char *stream_min = iniparser_getstring(conf, key, NULL);

            strcpy(keyname, "stream-max-quality");
            const char *stream_max = iniparser_getstring(conf, key, NULL);

            if (download_min || download_max) {
                cDownloadQuality *limits = new cDownloadQuality(sitename);
                limits->SetMin(download_min);
                limits->SetMax(download_max);
                downloadLimits.Add(limits);

                debug("download priorities for %s (from %s): min = %s, max = %s",
                      sitename, inifile, download_min, download_max);
            }

            if (stream_min || stream_max) {
                cDownloadQuality *limits = new cDownloadQuality(sitename);
                limits->SetMin(stream_min);
                limits->SetMax(stream_max);
                streamLimits.Add(limits);

                debug("streaming priorities for %s (from %s): min = %s, max = %s",
                      sitename, inifile, stream_min, stream_max);
            }
        }
    }

    iniparser_freedict(conf);

    return true;
}
Beispiel #11
0
void RedirectRule::getDomains(std::string &domain)
{
	std::string s=parseDomain(m_reRedirect);
	if(!s.empty())
		domain = s;
}
Beispiel #12
0
void ReplaceRule::getDomains(std::string &domain)
{
	std::string s=parseDomain(m_reReplace);
	if(!s.empty())
		domain = s;
}
std::string FileTransferCurl::Download(FileDownloadInfo *downloadInfo)
{
    CURL *curl;
    FILE *fp;
    CURLcode result;
    std::string result_string;
    bool error = 0;
    int http_status = 0;

    const char *source = (downloadInfo->source).c_str();
    const char *target = (downloadInfo->target).c_str();

    std::string source_escaped(curl_easy_escape(curl, curl_easy_escape(curl, source, 0), 0));
    std::string target_escaped(curl_easy_escape(curl, curl_easy_escape(curl, target, 0), 0));

    const char *targetDir = downloadInfo->target.substr(0, downloadInfo->target.find_last_of('/')).c_str();

    // Check if target directory exists with write permissions
    if (access(targetDir, R_OK)) {
        if (mkdir_p(targetDir, S_IRWXU | S_IRWXG)) {
            return buildDownloadErrorString(PERMISSIONS_ERR, source_escaped, target_escaped, http_status);
        }
    }

    curl = curl_easy_init();

    if (!curl) {
        return buildDownloadErrorString(CONNECTION_ERR, source_escaped, target_escaped, http_status);
    }

    fp = fopen(target, "wb");
    curl_easy_setopt(curl, CURLOPT_URL, source);
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, DownloadWriteCallback);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);

    // Check domain
    bool blockedDomain = false;
    const std::string parsedDomain(parseDomain(downloadInfo->source.c_str()));
    const DomainVerifyMap::iterator findDomain = m_pVerifyMap->find(parsedDomain);

    if (findDomain != m_pVerifyMap->end()) {
        if (findDomain->second) {
            curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
        } else {
            blockedDomain = true;
        }
    }

    result = curl_easy_perform(curl);

    if (result == CURLE_SSL_CACERT) {
        if (!blockedDomain) {
            result = openDialog(curl, downloadInfo->windowGroup, parsedDomain);
        }
    }

    if (result == CURLE_OK) {
        curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_status);

        if (http_status >= 200 && http_status < 300) {
            result_string = buildDownloadSuccessString(true, false, downloadInfo->source.substr(downloadInfo->source.find_last_of('/')+1), downloadInfo->target);
        } else if (http_status == 404) {
            error = 1;
            result_string = buildDownloadErrorString(FILE_NOT_FOUND_ERR, source_escaped, target_escaped, http_status);
        } else if (http_status >= 400 && http_status < 500) {
            error = 1;
            result_string = buildDownloadErrorString(INVALID_URL_ERR, source_escaped, target_escaped, http_status);
        } else {
            error = 1;
            result_string = buildDownloadErrorString(CONNECTION_ERR, source_escaped, target_escaped, http_status);
        }
    } else {
        FileTransferErrorCodes error_code;

        switch (result)
        {
            case CURLE_READ_ERROR:
            case CURLE_FILE_COULDNT_READ_FILE:
                error_code = FILE_NOT_FOUND_ERR;
                break;
            case CURLE_URL_MALFORMAT:
                error_code = INVALID_URL_ERR;
                break;
            default:
                error_code = CONNECTION_ERR;
                break;
        }

        error = 1;
        result_string = buildDownloadErrorString(error_code, source_escaped, target_escaped, http_status);
    }

    fclose(fp);

    if (error) {
        remove(downloadInfo->target.c_str());
    }

    curl_easy_cleanup(curl);

    return result_string;
}
std::string FileTransferCurl::Upload(FileUploadInfo *uploadInfo)
{
    CURL *curl;
    CURLcode result;
    std::string result_string;

    struct curl_httppost *formpost = NULL;
    struct curl_httppost *lastptr = NULL;
    struct curl_slist *headerlist = NULL;

    FILE *upload_file = NULL;

    std::string source_escaped(curl_easy_escape(curl, curl_easy_escape(curl, uploadInfo->sourceFile.c_str(), 0), 0));
    std::string target_escaped(curl_easy_escape(curl, curl_easy_escape(curl, uploadInfo->targetURL.c_str(), 0), 0));

    int http_status = 0;

    // Initialize the easy interface for curl
    curl = curl_easy_init();
    if (!curl) {
        return buildUploadErrorString(CONNECTION_ERR, source_escaped, target_escaped, http_status);
    }

    // Set up the form and fill in the file upload fields
    if (uploadInfo->chunkedMode) {
        upload_file = fopen(uploadInfo->sourceFile.c_str(), "r");

        if (!upload_file) {
            return buildUploadErrorString(FILE_NOT_FOUND_ERR, source_escaped, target_escaped, http_status);
        }

        // Find the file size
        fseek(upload_file, 0L, SEEK_END);
        int file_size = ftell(upload_file);
        rewind(upload_file);

        uploadAttributes uploadAtt;

        uploadAtt.file = upload_file;
        uploadAtt.max_chunk_size = uploadInfo->chunkSize;

        curl_formadd(&formpost,
                     &lastptr,
                     CURLFORM_STREAM, &uploadAtt,
                     CURLFORM_CONTENTSLENGTH, file_size,
                     CURLFORM_COPYNAME, uploadInfo->fileKey.c_str(),
                     CURLFORM_FILENAME, uploadInfo->fileName.c_str(),
                     CURLFORM_CONTENTTYPE, uploadInfo->mimeType.c_str(),
                     CURLFORM_END);
    } else {
        curl_formadd(&formpost,
                     &lastptr,
                     CURLFORM_FILE, uploadInfo->sourceFile.c_str(),
                     CURLFORM_COPYNAME, uploadInfo->fileKey.c_str(),
                     CURLFORM_FILENAME, uploadInfo->fileName.c_str(),
                     CURLFORM_CONTENTTYPE, uploadInfo->mimeType.c_str(),
                     CURLFORM_END);
    }

    if (uploadInfo->params.size() > 0) {
        std::vector<std::string>::const_iterator it;

        for (it = uploadInfo->params.begin(); it < uploadInfo->params.end(); it++) {
            const char *key = it->c_str();
            it++;
            const char *value = it->c_str();

            curl_formadd(&formpost,
                         &lastptr,
                         CURLFORM_COPYNAME, key,
                         CURLFORM_COPYCONTENTS, value,
                         CURLFORM_END);
        }
    }

    // Set up the headers
    headerlist = curl_slist_append(headerlist, "Expect:");

    if (uploadInfo->chunkedMode) {
        headerlist = curl_slist_append(headerlist, "Transfer-Encoding: chunked");
    }

    // Set up the callbacks
    std::string write_data;
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, static_cast<void *>(&write_data));
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, UploadWriteCallback);

    if (uploadInfo->chunkedMode) {
        curl_easy_setopt(curl, CURLOPT_READFUNCTION, UploadReadCallback);
    }

    // Allow redirects
    curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
    curl_easy_setopt(curl, CURLOPT_POSTREDIR, CURL_REDIR_POST_ALL);

    // Attach the different components
    curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
    curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
    curl_easy_setopt(curl, CURLOPT_URL, uploadInfo->targetURL.c_str());

    curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1);

    // Check domain
    bool blockedDomain = false;
    const std::string parsedDomain(parseDomain(uploadInfo->targetURL.c_str()));
    const DomainVerifyMap::iterator findDomain = m_pVerifyMap->find(parsedDomain);

    if (findDomain != m_pVerifyMap->end()) {
        if (findDomain->second) {
            curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
        } else {
            blockedDomain = true;
        }
    }

    // Perform file transfer (blocking)
    result = curl_easy_perform(curl);

    if (result == CURLE_SSL_CACERT) {
        if (!blockedDomain) {
            result = openDialog(curl, uploadInfo->windowGroup, parsedDomain);
        }
    }

    if (result == CURLE_OK) {
        curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_status);
        if (http_status >= 200 && http_status < 300) {
            double bytes_sent;
            curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_UPLOAD, &bytes_sent);

            result_string = buildUploadSuccessString(bytes_sent, http_status, write_data);
        } else if (http_status == 404) {
            result_string = buildUploadErrorString(INVALID_URL_ERR, source_escaped, target_escaped, http_status);
        } else {
            result_string = buildUploadErrorString(CONNECTION_ERR, source_escaped, target_escaped, http_status);
        }
    } else {
        FileTransferErrorCodes error_code;
        switch (result)
        {
            case CURLE_READ_ERROR:
            case CURLE_FILE_COULDNT_READ_FILE:
                error_code = FILE_NOT_FOUND_ERR;
                break;
            case CURLE_URL_MALFORMAT:
                error_code = INVALID_URL_ERR;
                break;
            default:
                error_code = CONNECTION_ERR;
                break;
        }

        result_string = buildUploadErrorString(error_code, source_escaped, target_escaped, http_status);
    }

    // Clean up
    if (uploadInfo->chunkedMode) {
        fclose(upload_file);
    }

    curl_easy_cleanup(curl);
    curl_formfree(formpost);
    curl_slist_free_all(headerlist);

    return result_string;
}