Пример #1
0
void
tab_attachments::add_attachment(const wxString &file_name) {
  mmg_attachment_cptr attch = mmg_attachment_cptr(new mmg_attachment_t);

  attch->file_name  = file_name;
  wxString name     = file_name.AfterLast(wxT(PSEP));
  wxString ext      = name.AfterLast(wxT('.'));
  name             += wxString(wxT(" (")) + file_name.BeforeLast(wxT(PSEP)) + wxT(")");
  lb_attachments->Append(name);

  if (ext.Length() > 0)
    attch->mime_type = wxU(guess_mime_type(wxMB(file_name), true));
  attch->style       = 0;
  attch->stored_name = derive_stored_name_from_file_name(attch->file_name);

  attachments.push_back(attch);
}
Пример #2
0
static void
constructed(GObject *object)
{
    ChupaDataPrivate *priv;
    gchar *mime_type;
    const gchar *filename = NULL;

    priv = CHUPA_DATA_GET_PRIVATE(object);
    g_return_if_fail(priv->stream);

    if (!priv->metadata) {
        priv->metadata = chupa_metadata_new();
    }
    filename = chupa_metadata_get_string(priv->metadata, meta_filename, NULL);
    mime_type = guess_mime_type(filename, priv->stream, NULL);
    chupa_metadata_set_mime_type(priv->metadata, mime_type);
    g_free(mime_type);
}
Пример #3
0
static void static_files_cb(struct evhttp_request *req, void *arg)
{
    http_serverlog_request(req);
    const char *static_root = arg;
    apr_pool_t *local_pool;
    const char *full_name;
    struct stat64 file_stat;
    const char *mime_type;

    if(!static_root)
    {
        LOG4C_ERROR(logger, "static root not configured");
        evhttp_send_error(req, HTTP_NOTFOUND, "Static file server not configured");
        return;
    }

    const char *uri = evhttp_request_get_uri(req);

    if (strstr(uri, "..") != NULL)
    {
        LOG4C_ERROR(logger, "illegal URL");
        evhttp_send_error(req, HTTP_BADREQUEST, "Illegal URL");
        return;
    }

    CREATE_POOL(local_pool, NULL);

    const char *path = get_path_from_uri(local_pool, uri);

    mime_type = guess_mime_type(uri);

    LOG4C_DEBUG(logger, "mime type is %s", mime_type);

    full_name = apr_pstrcat(local_pool, static_root, "/", path, NULL);

    if (lstat64(full_name, &file_stat) < 0)
    {
        LOG4C_ERROR(logger, "file not found");
        evhttp_send_error(req, HTTP_NOTFOUND, NULL);
        return;
    }

    int fd = open(full_name, O_RDONLY);
    if (fd < 0)
    {
        LOG4C_ERROR(logger, "open failed");
        evhttp_send_error(req, HTTP_NOTFOUND, NULL);
        return;
    }

    struct evbuffer *rep_buf = evbuffer_new();

    evhttp_add_header(evhttp_request_get_output_headers(req), "Content-Type", mime_type);
    evbuffer_set_flags(rep_buf, EVBUFFER_FLAG_DRAINS_TO_FD);
    //TODO: LIBEVENT DOES NOT SUPPORT LARGE FILES - USES off_t BUT _FILE_OFFSET_BITS=64 IS NOT DEFINED!
    evbuffer_add_file(rep_buf, fd, 0, file_stat.st_size); //
    evhttp_send_reply(req, HTTP_OK, "OK", rep_buf);

    evbuffer_free(rep_buf);

    RELEASE_POOL(local_pool);
}
Пример #4
0
void
ssa_parser_c::add_attachment_maybe(std::string &name,
                                   std::string &data_uu,
                                   ssa_section_e section) {
    if (name.empty() || data_uu.empty() || ((SSA_SECTION_FONTS != section) && (SSA_SECTION_GRAPHICS != section))) {
        name    = "";
        data_uu = "";
        return;
    }

    ++m_attachment_id;

    if (!m_reader->attachment_requested(m_attachment_id)) {
        name    = "";
        data_uu = "";
        return;
    }

    attachment_t attachment;

    std::string short_name = m_file_name;
    size_t pos             = short_name.rfind('/');

    if (std::string::npos != pos)
        short_name.erase(0, pos + 1);
    pos = short_name.rfind('\\');
    if (std::string::npos != pos)
        short_name.erase(0, pos + 1);

    attachment.ui_id        = m_attachment_id;
    attachment.name         = m_cc_utf8->utf8(name);
    attachment.description  = (boost::format(SSA_SECTION_FONTS == section ? Y("Imported font from %1%") : Y("Imported picture from %1%")) % short_name).str();
    attachment.to_all_files = true;

    size_t allocated        = 1024;
    attachment.data         = memory_c::alloc(allocated);
    attachment.data->set_size(0);

    const unsigned char *p  = (const unsigned char *)data_uu.c_str();
    for (pos = 0; data_uu.length() > (pos + 4); pos += 4)
        decode_chars(p[pos], p[pos + 1], p[pos + 2], p[pos + 3], attachment.data, 3, allocated);

    switch (data_uu.length() % 4) {
    case 2:
        decode_chars(p[pos], p[pos + 1], 0, 0, attachment.data, 1, allocated);
        break;
    case 3:
        decode_chars(p[pos], p[pos + 1], p[pos + 2], 0, attachment.data, 2, allocated);
        break;
    }

    attachment.mime_type = guess_mime_type(name, false);

    if (attachment.mime_type == "")
        attachment.mime_type = "application/octet-stream";

    add_attachment(attachment);

    name    = "";
    data_uu = "";
}