Пример #1
0
int file_get_info_by_id(mdb_conn *conn, int id, char *url, int pid, file_t **file)
{
    char mmckey[LEN_MMC_KEY];
    file_t *fl;
    size_t datalen;
    char *buf;
    int ret;
    
    if (id < 0 && (url == NULL || pid < 0))    return RET_RBTOP_INPUTE;

    if (id <= 0)
        snprintf(mmckey, LEN_MMC_KEY, "%s.%d.%s", PRE_MMC_FILE, pid, url);
    else
        snprintf(mmckey, LEN_MMC_KEY, "%s.%d", PRE_MMC_FILE, id);
    buf = mmc_get(mmckey, &datalen, 0);
    if (buf == NULL || datalen < sizeof(file_t)) {
        if (buf != NULL && datalen < sizeof(file_t)) {
            mtc_warn("get %d %d.%s info error from mmc %d",
                     id, pid, url, datalen);
        }
        if (mdb_get_errcode(conn) != MDB_ERR_NONE) {
            mtc_err("conn err %s", mdb_get_errmsg(conn));
            return RET_RBTOP_INPUTE;
        }
        fl = file_new();
        if (fl == NULL) return RET_RBTOP_MEMALLOCE;
        if (id <= 0) {
            LDB_QUERY_RAW(conn, "fileinfo", FILE_QUERY_COL,
                          "pid=%d AND name=$1", "s", pid, url);
        } else {
            LDB_QUERY_RAW(conn, "fileinfo", FILE_QUERY_COL,
                          "id=%d", NULL, id);
        }
        ret = FILE_GET_RAW(conn, fl);
        if (ret != MDB_ERR_NONE) {
            mtc_err("get %d %d.%s info failure from db %s",
                    id, pid, url, mdb_get_errmsg(conn));
            if (ret == MDB_ERR_NORESULT)
                return RET_RBTOP_NEXIST;
            return RET_RBTOP_SELECTE;
        } else {
            file_pack(fl, &buf, &datalen);
            mmc_store(MMC_OP_SET, mmckey, (void*)buf, datalen, ONE_HOUR, 0);
        }
    } else {
        ret = file_unpack(buf, datalen, &fl, NULL);
        if (ret != RET_RBTOP_OK) {
            mtc_err("assembly file from mmc error");
            return RET_RBTOP_MMCERR;
        }
    }
    free(buf);
    *file = fl;
    return RET_RBTOP_OK;
}
Пример #2
0
/* Pack the information from any client method into a generic xmlrpc
   struct to send to the server */
xmlrpc_value *
callinfo_pack(xmlrpc_env *envP, struct call_info *cip)
{
  xmlrpc_value *s = xmlrpc_struct_new(envP);
  xmlrpc_value *methargs = xmlrpc_array_new(envP);
  xmlrpc_value *files = xmlrpc_array_new(envP);
  int i;

  xmlrpc_struct_set_value(envP, s, "clientIP", xmlrpc_string_new(envP, nonull(cip->clientIP)));
  xmlrpc_struct_set_value(envP, s, "serverURL", xmlrpc_string_new(envP, nonull(cip->serverURL)));
  xmlrpc_struct_set_value(envP, s, "session", xmlrpc_string_new(envP, nonull(cip->session)));
  xmlrpc_struct_set_value(envP, s, "method", xmlrpc_string_new(envP, nonull(cip->method)));
  xmlrpc_struct_set_value(envP, s, "user", xmlrpc_string_new(envP, nonull(cip->user)));
  xmlrpc_struct_set_value(envP, s, "password", xmlrpc_string_new(envP, nonull(cip->password)));
  xmlrpc_struct_set_value(envP, s, "project", xmlrpc_string_new(envP, nonull(cip->project)));
  xmlrpc_struct_set_value(envP, s, "version", xmlrpc_string_new(envP, nonull(cip->version)));

  if (cip->methodargs)
    {
      for (i = 0; cip->methodargs[i]; ++i)
	{
	  if (!strncmp(cip->methodargs[i], "file:", 5))
	    {
	      char *file_what, *file_name;
	      
	      file_what = strdup(&cip->methodargs[i][5]);
	      file_name = strchr(file_what, '=');
	      if (file_name)
		{
		  xmlrpc_value * fstruct;
		  *file_name++ = '\0';
		  fstruct = file_pack(envP, file_what, file_name);
		  xmlrpc_array_append_item(envP, files, fstruct);
		}
	      else
		{
		  fprintf(stderr, "oracc-client: bad -Mfile arg, expected -Mfile:WHAT=NAME\n");
		  exit(1);
		}
	    }
	  else
	    xmlrpc_array_append_item(envP, methargs, xmlrpc_string_new(envP, cip->methodargs[i]));
	}
    }

  xmlrpc_struct_set_value(envP, s, "method-args", methargs);
  xmlrpc_struct_set_value(envP, s, "method-data", files);

  return s;
}
Пример #3
0
int file_get_info_by_uri(mdb_conn *conn, char *uri, file_t **file)
{
    file_t *fl;
    size_t datalen;
    char *buf;
    int ret;
    
    if (uri == NULL) return RET_RBTOP_INPUTE;

    buf = mmc_getf(&datalen, 0, PRE_MMC_FILE".%s", uri);
    if (buf == NULL || datalen < sizeof(file_t)) {
        if (buf != NULL && datalen < sizeof(file_t)) {
            mtc_warn("get %s info error from mmc %d", uri, datalen);
        }
        if (mdb_get_errcode(conn) != MDB_ERR_NONE) {
            mtc_err("conn err %s", mdb_get_errmsg(conn));
            return RET_RBTOP_INPUTE;
        }
        fl = file_new();
        if (fl == NULL) return RET_RBTOP_MEMALLOCE;
        LDB_QUERY_RAW(conn, "fileinfo", FILE_QUERY_COL, "uri=$1", "s", uri);
        ret = FILE_GET_RAW(conn, fl);
        if (ret != MDB_ERR_NONE) {
            mtc_err("get %s info failure from db %s", uri, mdb_get_errmsg(conn));
            if (ret == MDB_ERR_NORESULT)
                return RET_RBTOP_NEXIST;
            return RET_RBTOP_SELECTE;
        } else {
            file_pack(fl, &buf, &datalen);
            mmc_storef(MMC_OP_SET, (void*)buf, datalen, ONE_HOUR, 0,
                       PRE_MMC_FILE".%s", uri);
        }
    } else {
        ret = file_unpack(buf, datalen, &fl, NULL);
        if (ret != RET_RBTOP_OK) {
            mtc_err("assembly file from mmc error");
            return RET_RBTOP_MMCERR;
        }
    }
    free(buf);
    *file = fl;
    return RET_RBTOP_OK;
}