Esempio n. 1
0
File: otjt.c Progetto: kingiol/cmoon
int tjt_add_image(CGI *cgi, mdb_conn *conn, session_t *ses)
{
    unsigned char hash[LEN_MD5];
    int ret;

    FILE *fp = cgi_filehandle(cgi, "imagename");

    PRE_DBOP(cgi->hdf, conn);

    if (fp == NULL) {
        mtc_err("input file named: imagename not found");
        return RET_RBTOP_INPUTE;
    }

    /* TODO image don't divide into tjt_x currently */
    ret = lutil_image_accept(fp, "tjt", hash);
    if (ret != RET_RBTOP_OK) {
        mtc_err("accept image failure %d", ret);
        return ret;
    }

    hdf_set_valuef(cgi->hdf, PRE_OUTPUT".imageurl=%s/%s/%s/%s.jpg",
                   IMG_DOMAIN, IMG_PATH, IMG_ORI, hash);
    hdf_set_valuef(cgi->hdf, PRE_OUTPUT".imagename=%s.jpg", hash);
    return RET_RBTOP_OK;
}
Esempio n. 2
0
File: mimg.c Progetto: adderly/cmoon
NEOERR* mimg_accept(CGI *cgi, char *form_name, char *imgroot,
                    char result[LEN_MD5], int *ftype)
{
    unsigned char data[IMAGE_MD5_SIZE];
    unsigned int bytes;
    char tok[3] = {0};
    NEOERR *err;
    FILE *fp, *fpout;
    char *s;

    MCS_NOT_NULLC(cgi->hdf, imgroot, ftype);

    /* TODO memory leak */
    fp = mfile_get_safe_from_std(cgi_filehandle(cgi, form_name));
    MCS_NOT_NULLA(fp);

    s = mfile_get_type(cgi, form_name);
    if (!s || strncmp(s, "image/", 6)) {
        return nerr_raise(NERR_ASSERT, "file %s not image type", s);
    }
    s = s + 6;
    *ftype = mimg_type_str2int(s);

    memset(data, 0x0, sizeof(data));
    fseek(fp, 0, SEEK_SET);
    bytes = fread(data, 1, sizeof(data), fp);

    if (bytes <= 0) return nerr_raise(NERR_IO, "read image file error %d ", bytes);
    mstr_md5_buf(data, bytes, result);

    strncpy(tok, result, 2);
    err = mfile_openf(&fpout, "w+", "%s/%s/%s.%s",
                      imgroot, tok, result, mimg_type_int2str(*ftype));
    if (err != STATUS_OK) return nerr_pass(err);

    s = hdf_get_value(cgi->hdf, PRE_QUERY"._upfile_data_type", NULL);
    if (s && !strcmp(s, "dataurl")) {
        err = mb64_decode(fp, fpout);
        if (err != STATUS_OK) return nerr_pass(err);
    } else {
        if (bytes < IMAGE_MD5_SIZE-10) {
            fwrite(data, 1, bytes, fpout);
        } else {
            mfile_copy(fpout, fp);
        }
    }
    fclose(fpout);

    return STATUS_OK;
}
Esempio n. 3
0
static PyObject * p_cgi_filehandle (PyObject *self, PyObject *args)
{
  CGI *cgi = ((CGIObject *) self)->cgi;
  char *name;
  FILE *fp;

  if (!PyArg_ParseTuple(args, "s:filehandle(form_name)", &name))
    return NULL;

  fp = cgi_filehandle (cgi, name);
  if (fp == NULL)
  {
    Py_INCREF(Py_None);
    return Py_None;
  }
  return PyFile_FromFile (fp, name, "w+", NULL);
}
Esempio n. 4
0
bool CGI::TranslateFile(void *cgi, const char *key, std::map<std::string, File> *files)
{
    ::CGI *c = reinterpret_cast< ::CGI *>(cgi);

    FILE *fp = cgi_filehandle(c, key);
    if (!fp) {
        return false;
    }

    std::string path;
    if (key) {
        path = std::string("Query.") + key;
    } else {
        path = "PUT";
    }

    long size = -1;
    if (fseek(fp, 0, SEEK_END) == 0) {
        size = ftell(fp);
    }

    rewind(fp);
    File file;
    file._fp = fp;
    file._size = static_cast<size_t>(size);

    const char *name = hdf_get_value(c->hdf, path.c_str(), NULL);
    if (name) {
        file._name = name;
    }

    std::string stype = path + ".Type";
    const char *type = hdf_get_value(c->hdf, stype.c_str(), NULL);
    if (type) {
        file._type = type;
    }

    std::string sname = path + ".FileName";
    const char *tmp_name = hdf_get_value(c->hdf, sname.c_str(), NULL);
    if (tmp_name) {
        file._tmp_name = tmp_name;
    }

    files->insert(std::make_pair(key ? key : "", file));
    return true;
}
Esempio n. 5
0
FILE* neiku::CgX::getFile(const char* szName)
{
    CHECK_INIT(NULL);
    return cgi_filehandle(m_pCGI, szName);
}