Beispiel #1
0
int cmd_list(int argc, char *argv[])
{
  storage_t storage;
  const char *elem;

  if (argc != 2)
  {
    int help_argc = 2;
    char *help_argv[] = { "help_err", "list", NULL };
    return cmd_help(help_argc, help_argv);
  }

  if ((storage = storage_new(argv[1], 0)) == NULL)
    errx(EXIT_FAILURE, "unable to open storage: %s", argv[1]);

  elem = storage_list(storage, "backups");
  while (elem != NULL)
  {
    printf("%s\n", elem);
    elem = storage_list(storage, NULL);
  }

  storage_delete(storage);

  return EXIT_SUCCESS;
}
Beispiel #2
0
int cmd_purge(int argc, char *argv[])
{
  storage_t storage;
  strset_t backups;
  strset_t objects;
  const char *elem;
  struct mark_backup_args args;

  if (argc != 2)
  {
    int help_argc = 2;
    char *help_argv[] = { "help_err", "purge", NULL };
    return cmd_help_err(help_argc, help_argv);
  }

  if ((storage = storage_new(argv[1], false, true)) == NULL)
    logger(LOG_ERROR, "unable to open storage: %s", argv[1]);

  if (!storage_lock(storage, true, options_get()->force))
    logger(LOG_ERROR, "backup directory locked, use -f to force operation");

  backups = strset_new();
  objects = strset_new();

  /* Get the list of backups. */
  elem = storage_list(storage, "backups");
  while (elem != NULL)
  {
    strset_add(backups, elem);
    elem = storage_list(storage, NULL);
  }

  /* Get the list of objects. */
  elem = storage_list(storage, "objects");
  while (elem != NULL)
  {
    strset_add(objects, elem);
    elem = storage_list(storage, NULL);
  }

  /*
  ** For each backup, call mark_backup, which will mark all the objects of a
  ** backup as used (it will actually remove them from the `objects` strset.
  */
  args.objects = objects;
  args.storage = storage;
  strset_foreach(backups, mark_backup, &args);

  /* Delete every object remaining in the `objects` strset. */
  strset_foreach(objects, delete_object, (void *) storage);

  strset_delete(backups);
  strset_delete(objects);
  storage_unlock(storage);
  storage_delete(storage);

  return EXIT_SUCCESS;
}
Beispiel #3
0
void __connman_storage_delete_global(void)
{
	gchar *pathname;

	pathname = g_strdup_printf("%s/%s", STORAGEDIR, SETTINGS);
	if (!pathname)
		return;

	storage_delete(pathname);

	g_free(pathname);
}
Beispiel #4
0
int cmd_restore(int argc, char *argv[])
{
    storage_t storage;
    FILE *backup;
    char *backup_name;
    char *download_path;
    char buf[4096];

    if (!(argc == 3 || (argc == 2 && options['i'])))
    {
        int help_argc = 2;
        char *help_argv[] = { "help_err", "restore", NULL };
        return cmd_help(help_argc, help_argv);
    }

    if ((storage = storage_new(argv[1], 0)) == NULL)
        errx(EXIT_FAILURE, "unable to open storage: %s", argv[1]);

    if (argc == 3)
    {
        backup_name = estrdup(argv[2]);
    }
    else
    {
        printf("Available backups:\n");
        if (cmd_list(argc, argv) == EXIT_FAILURE)
            return EXIT_FAILURE;
        backup_name = readline("Enter the backup name to restore: ");
        /* Cleanly exit if the user did not enter any backup to restore. */
        if (backup_name == NULL || strlen(backup_name) == 0)
            return EXIT_SUCCESS;
    }

    download_path = path_concat("backups", backup_name);
    free(backup_name);
    if ((backup = storage_retrieve_file(storage, download_path)) == NULL)
        errx(EXIT_FAILURE, "unable to retrieve the backup description file");
    free(download_path);

    while (fgets(buf, 4096, backup) != NULL)
        unhash_dispatch(storage, "", buf);

    if (ferror(backup))
        errx(EXIT_FAILURE, "unable to restore the backup");

    fclose(backup);
    storage_delete(storage);

    return EXIT_SUCCESS;
}
static void _roster_publish_save_item(user_t user, item_t item) {
    os_t os;
    os_object_t o;
    char filter[4096];
    int i;

    log_debug(ZONE, "saving roster item %s for %s", jid_full(item->jid), jid_user(user->jid));

    os = os_new();
    o = os_object_new(os);

    os_object_put(o, "jid", jid_full(item->jid), os_type_STRING);

    if(item->name != NULL)
        os_object_put(o, "name", item->name, os_type_STRING);

    os_object_put(o, "to", &item->to, os_type_BOOLEAN);
    os_object_put(o, "from", &item->from, os_type_BOOLEAN);
    os_object_put(o, "ask", &item->ask, os_type_INTEGER);

    snprintf(filter, 4096, "(jid=%s)", jid_full(item->jid));

    storage_replace(user->sm->st, "roster-items", jid_user(user->jid), filter, os);

    os_free(os);

    snprintf(filter, 4096, "(jid=%s)", jid_full(item->jid));

    if(item->ngroups == 0) {
        storage_delete(user->sm->st, "roster-groups", jid_user(user->jid), filter);
        return;
    }

    os = os_new();

    for(i = 0; i < item->ngroups; i++) {
        o = os_object_new(os);

        os_object_put(o, "jid", jid_full(item->jid), os_type_STRING);
        os_object_put(o, "group", item->groups[i], os_type_STRING);
    }

    storage_replace(user->sm->st, "roster-groups", jid_user(user->jid), filter, os);

    os_free(os);
}
Beispiel #6
0
int cmd_delete(int argc, char *argv[])
{
  storage_t storage;
  char *backup_name;
  char *unlink_path;

  if (!(argc == 3 || (argc == 2 && options_get()->interactive)))
  {
    int help_argc = 2;
    char *help_argv[] = { "help_err", "delete", NULL };
    return cmd_help_err(help_argc, help_argv);
  }

  if ((storage = storage_new(argv[1], false, false)) == NULL)
    logger(LOG_ERROR, "unable to open storage: %s", argv[1]);

  if (argc == 3)
  {
    backup_name = estrdup(argv[2]);
  }
  else
  {
    printf("Available backups:\n");
    if (cmd_list(argc, argv) == EXIT_FAILURE)
      return EXIT_FAILURE;
    backup_name = readline("Enter the backup name to delete: ");
    /* Cleanly exit if the user did not enter any backup to delete. */
    if (backup_name == NULL || strlen(backup_name) == 0)
      return EXIT_SUCCESS;
  }

  unlink_path = path_concat("backups", backup_name);
  free(backup_name);
  if (!storage_unlink(storage, unlink_path))
    logger(LOG_ERROR, "unable to delete the backup");
  free(unlink_path);

  storage_delete(storage);

  return EXIT_SUCCESS;
}
Beispiel #7
0
/*
   Request:
      MUST NOT have extras.
      MUST have key.
      MUST have value.
   Ignore CAS.
*/
ST_RES *cmd_qlist_del(ST_REQ *req, ST_RES *res) {
	if(req->extras_sz || !req->key_sz || !req->value_sz)
		return(set_error_code(res, MEMCACHE_STATUS_INVALID_ARGUMENTS));
	
	MC_METADATA md;
	memset(&md, 0, sizeof(md));

	uint8_t *qla = buf_a;
	int qla_sz = sizeof(buf_a);
	uint8_t *qlb = (uint8_t *)req->value;
	uint8_t *qlc = buf_b;
	int qlc_sz = sizeof(buf_b);

	int r = storage_get(&md, (char*)qla, qla_sz, req->key, req->key_sz);
	if(r < 0)
		goto exit_ok;
		
	if( (md.flags & FLAG_QLIST) == 0) {
		set_error_code(res, MEMCACHE_STATUS_ITEM_NOT_STORED);
		goto exit;
	}
	
	r = qlist_andnot(qlc, qlc_sz, qla, qlb);
	
	if(r == EMPTY_QLIST_SIZE) {
		storage_delete(req->key, req->key_sz);
	}else{
		md.cas = (md.cas+1) || (md.cas+2);
		r = storage_set(&md, (char*)qlc, r, req->key, req->key_sz);
		if(r < 0) {
			set_error_code(res, MEMCACHE_STATUS_ITEM_NOT_STORED);
			goto exit;
		}
	}

exit_ok:
	res->status = MEMCACHE_STATUS_OK;
	res->cas = md.cas;
exit:
	return(res);
}
Beispiel #8
0
/*==========================================
 * カプラ倉庫データの受信
 *------------------------------------------
 */
int storage_storageload(int account_id, struct storage *s)
{
	struct map_session_data *sd;
	struct storage *stor;

	nullpo_retr(1, s);

	sd = map_id2sd(account_id);
	if(sd == NULL || sd->state.waitingdisconnect) {
		if(battle_config.error_log && sd == NULL)
			printf("storage_storageload: user not found %d\n", account_id);
		storage_delete(account_id);
		return 1;
	}

	// 既に倉庫を開いてないかチェック
	if(sd->state.storage_flag == 1)
		return 0;
	if(sd->state.storage_flag == 2)
		storage_guild_storageclose(sd);

	stor = account2storage(account_id);

	if(battle_config.save_log)
		printf("storageload: %d\n", account_id);

	memcpy(stor, s, sizeof(struct storage));
	storage_sortitem(stor->store_item, MAX_STORAGE, &stor->sortkey, battle_config.personal_storage_sort);
	stor->storage_status   = 1;
	sd->state.storage_flag = 1;
	clif_storageitemlist(sd,stor);
	clif_storageequiplist(sd,stor);
	clif_updatestorageamount(sd,stor);

	return 0;
}
Beispiel #9
0
static void _iq_private_user_delete(mod_instance_t mi, jid_t jid) {
    log_debug(ZONE, "deleting private xml storage for %s", jid_user(jid));

    storage_delete(mi->sm->st, "private", jid_user(jid), NULL);
}
Beispiel #10
0
static mod_ret_t _vacation_in_sess(mod_instance_t mi, sess_t sess, pkt_t pkt) {
    module_t mod = mi->mod;
    vacation_t v = sess->user->module_data[mod->index];
    int ns, start, end, msg;
    char dt[30];
    pkt_t res;
    os_t os;
    os_object_t o;

    /* we only want to play with vacation iq packets */
    if((pkt->type != pkt_IQ && pkt->type != pkt_IQ_SET) || pkt->ns != ns_VACATION)
        return mod_PASS;

    /* if it has a to, throw it out */
    if(pkt->to != NULL)
        return -stanza_err_BAD_REQUEST;

    /* get */
    if(pkt->type == pkt_IQ) {
        if(v->msg == NULL) {
            res = pkt_create(mod->mm->sm, "iq", "result", NULL, NULL);
            pkt_id(pkt, res);
            pkt_free(pkt);

            pkt_sess(res, sess);

            return mod_HANDLED;
        }

        ns = nad_find_scoped_namespace(pkt->nad, uri_VACATION, NULL);

        if(v->start != 0) {
            datetime_out(v->start, dt_DATETIME, dt, 30);
            nad_insert_elem(pkt->nad, 2, ns, "start", dt);
        } else
            nad_insert_elem(pkt->nad, 2, ns, "start", NULL);

        if(v->end != 0) {
            datetime_out(v->end, dt_DATETIME, dt, 30);
            nad_insert_elem(pkt->nad, 2, ns, "end", dt);
        } else
            nad_insert_elem(pkt->nad, 2, ns, "end", NULL);

        nad_insert_elem(pkt->nad, 2, ns, "message", v->msg);

        pkt_tofrom(pkt);
        nad_set_attr(pkt->nad, 1, -1, "type", "result", 6);
            
        pkt_sess(pkt, sess);

        return mod_HANDLED;
    }

    /* set */
    ns = nad_find_scoped_namespace(pkt->nad, uri_VACATION, NULL);

    start = nad_find_elem(pkt->nad, 2, ns, "start", 1);
    end = nad_find_elem(pkt->nad, 2, ns, "end", 1);
    msg = nad_find_elem(pkt->nad, 2, ns, "message", 1);

    if(start < 0 || end < 0 || msg < 0) {
        /* forget */
        if(v->msg != NULL) {
            free(v->msg);
            v->msg = NULL;
        }
        v->start = 0;
        v->end = 0;

        storage_delete(mi->sm->st, "vacation-settings", jid_user(sess->jid), NULL);

        res = pkt_create(mod->mm->sm, "iq", "result", NULL, NULL);
        pkt_id(pkt, res);
        pkt_free(pkt);

        pkt_sess(res, sess);

        return mod_HANDLED;
    }

    if(NAD_CDATA_L(pkt->nad, start) > 0) {
        strncpy(dt, NAD_CDATA(pkt->nad, start), (30 < NAD_CDATA_L(pkt->nad, start) ? 30 : NAD_CDATA_L(pkt->nad, start)));
        v->start = datetime_in(dt);
    } else
        v->start = 0;

    if(NAD_CDATA_L(pkt->nad, end) > 0) {
        strncpy(dt, NAD_CDATA(pkt->nad, end), (30 < NAD_CDATA_L(pkt->nad, end) ? 30 : NAD_CDATA_L(pkt->nad, end)));
        v->end = datetime_in(dt);
    } else
        v->end = 0;

    v->msg = (char *) malloc(sizeof(char) * (NAD_CDATA_L(pkt->nad, msg) + 1));
    strncpy(v->msg, NAD_CDATA(pkt->nad, msg), NAD_CDATA_L(pkt->nad, msg));
    v->msg[NAD_CDATA_L(pkt->nad, msg)] = '\0';

    os = os_new();
    o = os_object_new(os);
    os_object_put(o, "start", &v->start, os_type_INTEGER);
    os_object_put(o, "end", &v->end, os_type_INTEGER);
    os_object_put(o, "message", v->msg, os_type_STRING);

    if(storage_replace(mod->mm->sm->st, "vacation-settings", jid_user(sess->user->jid), NULL, os) != st_SUCCESS) {
        free(v->msg);
        v->msg = NULL;
        v->start = 0;
        v->end = 0;
        return -stanza_err_INTERNAL_SERVER_ERROR;
    }
    
    res = pkt_create(mod->mm->sm, "iq", "result", NULL, NULL);
    pkt_id(pkt, res);
    pkt_free(pkt);

    pkt_sess(res, sess);

    return mod_HANDLED;
}
Beispiel #11
0
static void _vacation_user_delete(mod_instance_t mi, jid_t jid) {
    log_debug(ZONE, "deleting vacations settings for %s", jid_user(jid));

    storage_delete(mi->sm->st, "vacation-settings", jid_user(jid), NULL);
}
Beispiel #12
0
static mod_ret_t _offline_in_sess(mod_instance_t mi, sess_t sess, pkt_t pkt) {
    st_ret_t ret;
    os_t os;
    os_object_t o;
    nad_t nad;
    pkt_t queued;
    int ns, elem, attr;
    char cttl[15], cstamp[18];
    time_t ttl, stamp;

    /* if they're becoming available for the first time */
    if(pkt->type == pkt_PRESENCE && pkt->to == NULL && sess->user->top == NULL) {

        ret = storage_get(pkt->sm->st, "queue", jid_user(sess->jid), NULL, &os);
        if(ret != st_SUCCESS) {
            log_debug(ZONE, "storage_get returned %d", ret);
            return mod_PASS;
        }

        if(os_iter_first(os))
            do {
                o = os_iter_object(os);

                if(os_object_get_nad(os, o, "xml", &nad)) {
                    queued = pkt_new(pkt->sm, nad_copy(nad));
                    if(queued == NULL) {
                        log_debug(ZONE, "invalid queued packet, not delivering");
                    } else {
                        /* check expiry as necessary */
                        if((ns = nad_find_scoped_namespace(queued->nad, uri_EXPIRE, NULL)) >= 0 &&
                                (elem = nad_find_elem(queued->nad, 1, ns, "x", 1)) >= 0 &&
                                (attr = nad_find_attr(queued->nad, elem, -1, "seconds", NULL)) >= 0) {
                            snprintf(cttl, 15, "%.*s", NAD_AVAL_L(queued->nad, attr), NAD_AVAL(queued->nad, attr));
                            ttl = atoi(cttl);

                            /* it should have a x:delay stamp, because we stamp everything we store */
                            if((ns = nad_find_scoped_namespace(queued->nad, uri_DELAY, NULL)) >= 0 &&
                                    (elem = nad_find_elem(queued->nad, 1, ns, "x", 1)) >= 0 &&
                                    (attr = nad_find_attr(queued->nad, elem, -1, "stamp", NULL)) >= 0) {
                                snprintf(cstamp, 18, "%.*s", NAD_AVAL_L(queued->nad, attr), NAD_AVAL(queued->nad, attr));
                                stamp = datetime_in(cstamp);

                                if(stamp + ttl <= time(NULL)) {
                                    log_debug(ZONE, "queued packet has expired, dropping");
                                    pkt_free(queued);
                                    continue;
                                }
                            }
                        }

                        log_debug(ZONE, "delivering queued packet to %s", jid_full(sess->jid));
                        pkt_sess(queued, sess);
                    }
                }
            } while(os_iter_next(os));

        os_free(os);

        /* drop the spool */
        storage_delete(pkt->sm->st, "queue", jid_user(sess->jid), NULL);
    }

    /* pass it so that other modules and mod_presence can get it */
    return mod_PASS;
}
Beispiel #13
0
static void _active_user_delete(mod_instance_t mi, jid_t jid) {
    log_debug(ZONE, "deactivating user %s", jid_user(jid));

    storage_delete(mi->sm->st, "active", jid_user(jid), NULL);
}
Beispiel #14
0
/** Handles iq messages */
mod_ret_t archive_iq_in_sess(mod_instance_t mi, sess_t sess, pkt_t pkt) {
    int prefs, type;
    int section, ptr;
    os_t os;
    os_object_t o;
    char* owner;
    char buff[2048];
    log_debug(ZONE, "In session");

    // we only want to play IQs
    if((!((pkt->type & pkt_IQ) || (pkt->type & pkt_IQ_SET))) || (pkt->ns != ns_ARCHIVE))
        return mod_PASS;
    log_debug(ZONE, "Passed through packet checks");

    // if it has a to, throw it out
    if(pkt->to != NULL)
        return -stanza_err_BAD_REQUEST;

    // Who are we?
    owner=jid_user(sess->jid);

    // Check for no type or get to send current settings
    if((type = (nad_find_attr(pkt->nad, 2, -1, "type", NULL)<0)) ||
       ((NAD_AVAL_L(pkt->nad, type ) == 3) && strncmp("get", NAD_AVAL(pkt->nad, type), 3))) {
        log_debug(ZONE, "Somebody is asking about settings");
        send_arch_prefs(mi, sess, pkt);
        return mod_HANDLED;
    }

    // We are setting stuff
    if(pkt->type == pkt_IQ_SET) {
        // Prepare to store them
        log_debug(ZONE, "Setting archiving preferences...");
        os = os_new();
        if(os == NULL) return mod_PASS;
        o = os_object_new(os);
        if(o  == NULL) return mod_PASS;

        // Get rid of old settings
        storage_delete(pkt->sm->st, tbl_name "_settings", owner, NULL);
        log_debug(ZONE, "Got rid of old preferences...");

        // Find if there is an default option
        if(!((prefs=nad_find_elem(pkt->nad, 1, -1, "prefs", 1))>0))
            return mod_PASS;
        ptr=nad_find_attr(pkt->nad, prefs, -1, "default", NULL);

        if(ptr>0) {
            // Defaults
            log_debug(ZONE, "Saving defaults...");
            os_object_put(o, "jid", owner, os_type_STRING);
            if     (strncmp("roster",NAD_AVAL(pkt->nad, ptr), NAD_AVAL_L(pkt->nad, ptr))==0)
                prefs=A_ROSTER;
            else if(strncmp("always",NAD_AVAL(pkt->nad, ptr), NAD_AVAL_L(pkt->nad, ptr))==0)
                prefs=A_ALWAYS;
            else
                prefs=A_NEVER;
            os_object_put(o, "setting", &prefs,  os_type_INTEGER);
            log_debug(ZONE, "Setting default to %d...", prefs);

            // What to save always
            log_debug(ZONE, "Saving what to save always...");
            if(((section = nad_find_elem(pkt->nad, prefs, -1, "always", 1))>0)) {
                log_debug(ZONE, "Found always section %d...", section);
                prefs=A_ALWAYS;
                for(ptr = nad_find_elem(pkt->nad, section, -1, "jid", 1); ptr > 0;
                    ptr = nad_find_elem(pkt->nad, ptr,     -1, "jid", 0)) {
                        o = os_object_new(os);
                        strncpy(buff, NAD_CDATA(pkt->nad, ptr), min(2047,NAD_CDATA_L(pkt->nad, ptr)));
                        buff[min(2047,NAD_CDATA_L(pkt->nad, ptr))]=0;
                        os_object_put(o, "jid",      buff,  os_type_STRING);
                        os_object_put(o, "setting", &prefs, os_type_INTEGER);
                        log_debug(ZONE, "Always archiving %s...", buff);
                }
            }

            // What to never save
            log_debug(ZONE, "Saving what never save...");
            if(((section = nad_find_elem(pkt->nad, 2, -1, "never",  1))>0)) {
                log_debug(ZONE, "Found never section %d...", section);
                prefs=A_NEVER;
                for(ptr = nad_find_elem(pkt->nad, section, -1, "jid", 1); ptr > 0;
                    ptr = nad_find_elem(pkt->nad, ptr,     -1, "jid", 0)) {
                        o = os_object_new(os);
                        strncpy(buff, NAD_CDATA(pkt->nad, ptr), min(2047,NAD_CDATA_L(pkt->nad, ptr)));
                        buff[min(2047,NAD_CDATA_L(pkt->nad, ptr))]=0;
                        os_object_put(o, "jid",      buff,  os_type_STRING);
                        os_object_put(o, "setting", &prefs, os_type_INTEGER);
                        log_debug(ZONE, "Never archiving %s...", buff);
                }
            }

            // Save everything
            storage_put(pkt->sm->st, tbl_name "_settings", owner, os);
        }

        // Send current settings
        send_arch_prefs(mi, sess, pkt);
        return mod_HANDLED;
    }
    return mod_PASS;
}