コード例 #1
0
ファイル: mod_uploader.cpp プロジェクト: kimata/mod_uploader
static int uploader_post_config_server(apr_pool_t *p, server_rec *s)
{
    UploaderConfig **configs;
    UploaderConfig *config;

    configs = (UploaderConfig **)AVOID_ALIGN_WARN uploader_config_array->elts;

    for (int i = 0; i < uploader_config_array->nelts; i++) {
        config = configs[i];

        try {
            config->init();
            config->is_debug_mode = get_apache_debug_mode();

            apr_pool_cleanup_register(p, config, uploader_finalize_dir_config,
                                      apr_pool_cleanup_null);
        } catch(const char *message) {
            logger.error(__FILE__, __LINE__, s,
                         "(%s) %s: %s", "UploaderConfig::init", message,
                         get_last_error_message(p));

            return HTTP_INTERNAL_SERVER_ERROR;
        }
    }

    return OK;
}
コード例 #2
0
ファイル: mod_uploader.cpp プロジェクト: kimata/mod_uploader
static int uploader_handler(request_rec *r)
{
    UploaderConfig *config;

    if (strcmp(r->handler, HANDLER_NAME)) {
        return DECLINED;
    }

    if (UNLIKELY(!ap_is_initial_req(r))) {
        return DECLINED;
    }

    config = uploader_get_dir_config(r);

    if (UNLIKELY(!config->is_active())) {
        return DECLINED;
    }

    try {
        if (UNLIKELY(config->is_debug_mode)) {
            config->update_template();
        }

        return uploader_command_handler<ApacheResponse>(r, config,
                                                        r->path_info);
    } catch(const char *message) {
        logger.error(__FILE__, __LINE__, r, "Exception: %s", message);

        return HTTP_INTERNAL_SERVER_ERROR;
    }
}
コード例 #3
0
/*!
 * Return url for upload image
 */
QUrl Uploader_MediaCrush::apiUrl()
{
    UploaderConfig config;
    // QUrl("https://mediacru.sh/api/upload/file")

    return config.loadSingleParam("mediacru.sh", KEY_MCSH_URL).toUrl();
}
コード例 #4
0
void UploaderConfigWidget::loadSettings()
{
    qDebug() << "load uploder common settings";

    UploaderConfig config;
    QVariantMap loadValues;
    loadValues.insert("autoCopyDirectLink", QVariant(false));
    loadValues.insert(KEY_DEFAULT_HOST, "");
    loadValues = config.loadSettings("common", loadValues);

    QString defaultHost = loadValues[KEY_DEFAULT_HOST].toString();
    if (defaultHost.isEmpty() == true)
    {
        _ui->cbxDefaultHost->setCurrentIndex(0);
    }
    else
    {
        qint8 index = config.labelsList().indexOf(defaultHost);

        if (index == -1)
        {
            index++;
        }

        _ui->cbxDefaultHost->setCurrentIndex(index);
    }

    _ui->checkAutoCopyMainLink->setChecked(loadValues["autoCopyDirectLink"].toBool());
}
コード例 #5
0
/******************************************************************************
 * public メソッド
 *****************************************************************************/
UploaderConfig *CGIConfigReader::read(apr_pool_t *pool,
                                           const char *conf_file_path)
{
    UploaderConfig *config;

    APR_PCALLOC(config, UploaderConfig *, pool, sizeof(UploaderConfig));
    new(config) UploaderConfig(pool);

    std::auto_ptr<ConfigReader::config_map>
        cmap(ConfigReader::read(pool, conf_file_path));
    for (ConfigReader::config_map::const_iterator i = cmap.get()->begin();
         i != cmap.get()->end(); i++) {
        SET_STR_PARAM(BASE_URL,             base_url);
        SET_STR_PARAM(DATA_DIRECTORY,       data_dir_path);
        SET_STR_PARAM(FILE_DIRECTORY,       file_dir_path);
        SET_STR_PARAM(THUMB_DIRECTORY,      thumb_dir_path);
        SET_STR_PARAM(TEMP_DIRECTORY,       temp_dir_path);
        SET_INT64_PARAM(TOTAL_FILE_SIZE,    total_file_size_limit);
        SET_INT_PARAM(TOTAL_FILE_NUMBER,    total_file_number_limit);
        SET_INT64_PARAM(FILE_SIZE_LIMIT,    file_size_limit);
        SET_INT_PARAM(PER_PAGE_ITEM_NUMBER, per_page_item_number);

        SET_TMPL_PARAM(INDEX_VIEW_TEMPLATE,     INDEX_VIEW);
        SET_TMPL_PARAM(PROGRESS_VIEW_TEMPLATE,  PROGRESS_VIEW);
        SET_TMPL_PARAM(DOWNLOAD_VIEW_TEMPLATE,  DOWNLOAD_VIEW);
        SET_TMPL_PARAM(THUMBNAIL_VIEW_TEMPLATE, THUMBNAIL_VIEW);
        SET_TMPL_PARAM(ADMIN_VIEW_TEMPLATE,     ADMIN_VIEW);
        SET_TMPL_PARAM(ERROR_VIEW_TEMPLATE,     ERROR_VIEW);
    }

    config->init();

    return config;
}
コード例 #6
0
ファイル: moduleuploader.cpp プロジェクト: DOOMer/screengrab
void ModuleUploader::init()
{
    Core *core = Core::instance();

    if (core->checkCmdLineOption(_optUpload) == true  && _ignoreCmdParam == false)
    {
        UploaderConfig config;
        QString selectedtHost = config.loadSingleParam(QByteArray("common"), QByteArray(KEY_DEFAULT_HOST)).toString();

        Uploader *uploader = 0;
        switch(config.labelsList().indexOf(selectedtHost))
        {
        case 0:
            uploader = new Uploader_ImgUr;
            break;
        default:
            uploader = new Uploader_ImgUr;
        }

        connect(uploader, &Uploader::uploadDoneStr, this, &ModuleUploader::shadowUploadDone);
        connect(uploader, &Uploader::uploadFail, this, &ModuleUploader::shadowUploadFail);

        uploader->startUploading();

        _ignoreCmdParam = true;
    }
    else
    {
        DialogUploader *ui = new DialogUploader();
        ui->exec();
    }
}
コード例 #7
0
ファイル: mod_uploader.cpp プロジェクト: kimata/mod_uploader
static int uploader_handler(request_rec *r)
{
    UploaderConfig *config;

    if (UNLIKELY(!ap_is_initial_req(r))) {
        return DECLINED;
    }

    config = uploader_get_dir_config(r);

    if (UNLIKELY(!config->is_active())) {
        return DECLINED;
    }

    TemporaryPool temp_pool;
    ApacheResponse::Handle r_wrapper(temp_pool.get(), r);
    try {
        return uploader_command_handler<ApacheResponse>(&r_wrapper, config,
                                                        r->path_info);
    } catch(const char *message) {
        logger.error(__FILE__, __LINE__, &r_wrapper, "Exception: %s", message);

        return HTTP_INTERNAL_SERVER_ERROR;
    }
}
コード例 #8
0
void DialogUploader::slotUploadDone()
{
qDebug() << "start dialog uploader done";
    QList<ResultString_t> links = _uploader->parsedLinksToGui();
    _ui->editDirectLink->setText(links.first().first);
    _ui->editDeleteLink->setText(links.last().first);

    for (int i =1; i < links.count()-1; ++i)
    {
        _ui->cbxExtCode->addItem(links.at(i).second);
        _resultLinks << links.at(i).first;
    }

    _ui->stackedWidget->setCurrentIndex(0);
    _ui->labUploadStatus->setText(tr("Upload completed"));
    _ui->progressBar->setVisible(false);
    _ui->cbxUploaderList->setEnabled(false);

    UploaderConfig config;
    if (config.autoCopyResultLink())
        QApplication::clipboard()->setText(_ui->editDirectLink->text());

    if (_resultLinks.count() > 0)
    {
        connect(_ui->cbxExtCode, SIGNAL(currentIndexChanged(int)), this, SLOT(slotChangeExtCode(int)));
        _ui->cbxExtCode->setCurrentIndex(0);
        _ui->editExtCode->setText(_resultLinks.at(0));
    }
コード例 #9
0
ファイル: mod_uploader.cpp プロジェクト: kimata/mod_uploader
static apr_status_t uploader_finalize_dir_config(void *data)
{
    UploaderConfig *config;

    config = AS_UCONFIG(data);
    config->finalize();

    return APR_SUCCESS;
}
コード例 #10
0
void UploaderConfigWidget_MediaCrush::saveSettings()
{
    UploaderConfig config;

    QVariantMap savingValues;
    savingValues.insert(KEY_MCSH_URL, ui->editUrl->text());

    config.saveSettings("mediacru.sh", savingValues);
}
コード例 #11
0
void UploaderConfigWidget::saveSettings()
{
    UploaderConfig config;
    QVariantMap savingValues;
    savingValues.insert(KEY_AUTO_COPY_RESULT_LIMK, _ui->checkAutoCopyMainLink->isChecked());

    QString defaultHost = config.labelsList().at(_ui->cbxDefaultHost->currentIndex());
    savingValues.insert(KEY_DEFAULT_HOST, defaultHost);

    config.saveSettings("common", savingValues);

    QMetaObject::invokeMethod(_imgur, "saveSettings");

}
コード例 #12
0
DialogUploader::DialogUploader(QWidget *parent) :
    QDialog(parent),
    _ui(new Ui::DialogUploader)
{
    _ui->setupUi(this);
    _ui->stackedWidget->setCurrentIndex(0);
    _uploader = 0;
    _uploaderWidget = 0;
    slotSeletHost(0);

    _ui->cbxUploaderList->addItems(UploaderConfig::labelsList());

    UploaderConfig config;
    QString defaultHost = config.loadSingleParam(QByteArray("common"), QByteArray(KEY_DEFAULT_HOST)).toString();

    if (defaultHost.isEmpty())
        _selectedHost = 0;
    else
    {
        _selectedHost = config.labelsList().indexOf(defaultHost);
        if (_selectedHost == -1)
            _selectedHost = 0;
    }

    // load ishot preview
    QSize imgSize = Core::instance()->getPixmap()->size();
    QString pixmapSize = tr("Size: ") + QString::number(imgSize.width()) + "x" + QString::number(imgSize.height()) + tr(" pixel");
    _ui->labImgSize->setText(pixmapSize);

    _ui->labImage->setFixedWidth(256);
    _ui->labImage->setFixedHeight(192);
    _ui->labImage->setPixmap(Core::instance()->getPixmap()->scaled(_ui->labImage->size(),
                Qt::KeepAspectRatio, Qt::SmoothTransformation));

    // progressbar
    _ui->progressBar->setVisible(false);
    _ui->progressBar->setFormat(tr("Uploaded ") + "%p%" + " (" + "%v" + " of " + "%m bytes");

    // upload staus labelsList
    _ui->labUploadStatus->setText(tr("Ready to upload"));

    connect(_ui->butClose, &QPushButton::clicked, this, &DialogUploader::close);
    connect(_ui->butUpload, &QPushButton::clicked, this, &DialogUploader::slotUploadStart);

    void (QComboBox::*uploaderChnage)(int) = &QComboBox::currentIndexChanged;
    connect(_ui->cbxUploaderList, uploaderChnage, this, &DialogUploader::slotSeletHost);

    _ui->cbxUploaderList->setCurrentIndex(_selectedHost);
}
コード例 #13
0
ファイル: uploader.cpp プロジェクト: QtDesktop/screengrab
Uploader::Uploader(QObject *parent) :
    QObject(parent), _multipartData(nullptr)
{
    qsrand(126);
    _strBoundary = "uploadbound" + QByteArray::number(qrand());
    _net = new QNetworkAccessManager(this);
    _serverReply = nullptr;
    initUploadedStrList();

    UploaderConfig config;
    if (config.checkExistsConfigFile() == false)
    {
        config.defaultSettings();
    }
}
コード例 #14
0
int main(int argc, const char * const *argv)
{
    apr_pool_t *pool;
    UploaderConfig *config;
    int status;

    apr_app_initialize(&argc, &argv, NULL);
    apr_pool_create(&pool, NULL);

    config = NULL;
    status = 0;
    try {
        config = UploaderConfigReader::read(pool, CONF_FILE_NAME);
        config->child_init();

        // ベンチマーク用
        bench_count = atoi(getenv("UPLOADER_BENCH"));
        if (bench_count == 0) {
            bench_count++;
        }

        STRACE_MARKER();
        for (apr_size_t i = 0; i < bench_count; i++) {
            TemporaryPool temp_pool(pool);
            CGIResponse::Handle handle(temp_pool.get());

            status = uploader_command_handler<CGIResponse>
                (&handle, config, arg);
        }
        STRACE_MARKER();

        config->finalize();
        apr_pool_destroy(pool);
        apr_terminate();

        return status;
    } catch(const char *message) {
        std::cout << "Fatal Error: " << message << std::endl;

        if (config != NULL) {
            config->finalize();
        }
        apr_pool_destroy(pool);
        apr_terminate();

        return EXIT_FAILURE;
    }
}
コード例 #15
0
UploaderConfigWidget_MediaCrush::UploaderConfigWidget_MediaCrush(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::UploaderConfigWidget_MediaCrush)
{
    ui->setupUi(this);

    // load settings
    UploaderConfig config;

    QVariantMap loadedValues;
    loadedValues.insert(KEY_MCSH_URL, "");

    loadedValues = config.loadSettings("mediacru.sh", loadedValues);
    ui->editUrl->setText(loadedValues[KEY_MCSH_URL].toString());

}
コード例 #16
0
ファイル: mod_uploader.cpp プロジェクト: kimata/mod_uploader
static void uploader_child_init_server(apr_pool_t *pool, server_rec *s)
{
    UploaderConfig **configs;
    UploaderConfig *config;

    configs = (UploaderConfig **)AVOID_ALIGN_WARN uploader_config_array->elts;

    for (int i = 0; i < uploader_config_array->nelts; i++) {
        config = configs[i];

        try {
            config->child_init();
        } catch(const char *message) {
            logger.error(__FILE__, __LINE__, s,
                         "(%s) %s: %s", "UploaderConfig::child_init", message,
                         get_last_error_message(pool));
        }
    }
}
コード例 #17
0
ファイル: moduleuploader.cpp プロジェクト: DOOMer/screengrab
void ModuleUploader::defaultSettings()
{
    UploaderConfig config;
    config.defaultSettings();
}
コード例 #18
0
ファイル: cgi_uploader.cpp プロジェクト: el1n/mod_uploader
int main(int argc, const char * const *argv)
{
    apr_pool_t *pool;
    const char *arg;
    UploaderConfig *config;
    int status;
    apr_size_t bench_count;

    apr_app_initialize(&argc, &argv, NULL);
    apr_pool_create(&pool, NULL);

    config = NULL;
    status = 0;
    try {
        arg = getenv("PATH_INFO");
        if (arg == NULL) {
            std::cout << "Location: http://";
            std::cout << CGIResponse::get_env(pool, "SERVER_NAME");

            if ((strcmp(CGIResponse::get_env(pool, "SERVER_PORT"),
                        "80") != 0)) {
                std::cout << ":" << CGIResponse::get_env(pool, "SERVER_PORT");
            }

            std::cout << CGIResponse::get_env(pool, "SCRIPT_NAME") << "/\r\n\r\n";
            return EXIT_SUCCESS;
        }

        config = CGIConfigReader::read(pool, CONF_FILE_NAME);
        config->child_init();

        // ベンチマーク用
        bench_count = atoi(getenv("UPLOADER_BENCH"));
        if (bench_count == 0) {
            bench_count++;
        }

        STRACE_MARKER();
        for (apr_size_t i = 0; i < bench_count; i++) {
            TemporaryPool temp_pool(pool);
            CGIResponse::Handle handle(temp_pool.get());

            status = uploader_command_handler<CGIResponse>
                (&handle, config, arg);
        }
        STRACE_MARKER();

        config->finalize();
        apr_pool_destroy(pool);
        apr_terminate();

        return status;
    } catch(const char *message) {
        // できれば Internal Server Error にしたいけど,問い合わせが多
        // くなりそうなので...
        std::cout << "Content-type: text/html; charset=UTF-8\r\n\r\n";
        std::cout << "Fatal Error: " << message << std::endl;

        if (config != NULL) {
            config->finalize();
        }
        apr_pool_destroy(pool);
        apr_terminate();

        return EXIT_FAILURE;
    }
}