Exemplo n.º 1
0
Arquivo: m_ipt.c Projeto: NieHao/R7000
/* 
 * we may need to check for version mismatch
*/
int
build_st(struct iptables_target *target, struct ipt_entry_target *t)
{
	unsigned int nfcache = 0;

	if (target) {
		size_t size;

		size =
		    IPT_ALIGN(sizeof (struct ipt_entry_target)) + target->size;

		if (NULL == t) {
			target->t = fw_calloc(1, size);
			target->t->u.target_size = size;

			if (target->init != NULL)
				target->init(target->t, &nfcache);
			set_revision(target->t->u.user.name, target->revision);
		} else {
			target->t = t;
		}
		strcpy(target->t->u.user.name, target->name);
		return 0;
	}

	return -1;
}
Exemplo n.º 2
0
/*
 * we may need to check for version mismatch
*/
int
build_st(struct xtables_target *target, struct xt_entry_target *t)
{

	size_t size =
		    XT_ALIGN(sizeof(struct xt_entry_target)) + target->size;

	if (t == NULL) {
		target->t = fw_calloc(1, size);
		target->t->u.target_size = size;
		strcpy(target->t->u.user.name, target->name);
		set_revision(target->t->u.user.name, target->revision);

		if (target->init != NULL)
			target->init(target->t);
	} else {
		target->t = t;
	}
	return 0;

}
static EContact *
do_create (EBookBackendVCF  *bvcf,
	  const gchar     *vcard_req,
	  gboolean        dirty_the_file)
{
	gchar           *id;
	EContact       *contact;
	gchar           *vcard;
	const gchar     *rev;

	/* at the very least we need the unique_id generation to be
	   protected by the lock, even if the actual vcard parsing
	   isn't. */
	g_mutex_lock (bvcf->priv->mutex);
	id = e_book_backend_vcf_create_unique_id ();

	contact = e_contact_new_from_vcard (vcard_req);
	e_contact_set (contact, E_CONTACT_UID, id);
	g_free (id);

	rev = e_contact_get_const (contact,  E_CONTACT_REV);
	if (!(rev && *rev))
		set_revision (contact);

	vcard = e_vcard_to_string (E_VCARD (contact), EVC_FORMAT_VCARD_30);

	insert_contact (bvcf, vcard);

	if (dirty_the_file) {
		bvcf->priv->dirty = TRUE;

		if (!bvcf->priv->flush_timeout_tag)
			bvcf->priv->flush_timeout_tag = g_timeout_add (FILE_FLUSH_TIMEOUT,
								       vcf_flush_file, bvcf);
	}

	g_mutex_unlock (bvcf->priv->mutex);

	return contact;
}
Exemplo n.º 4
0
bool Blockchain::AssignAddress(
    const Identifier& nymID,
    const Identifier& accountID,
    const std::uint32_t index,
    const Identifier& contactID,
    const BIP44Chain chain) const
{
    LOCK_ACCOUNT()

    const std::string sNymID = nymID.str();
    const std::string sAccountID = accountID.str();
    const std::string sContactID = contactID.str();
    auto account = load_account(accountLock, sNymID, sAccountID);

    if (false == bool(account)) {
        otErr << OT_METHOD << __FUNCTION__ << ": Account does not exist."
              << std::endl;

        return false;
    }

    const auto& type = account->type();
    const auto allocatedIndex =
        chain ? account->internalindex() : account->externalindex();

    if (index > allocatedIndex) {
        otErr << OT_METHOD << __FUNCTION__
              << ": Address has not been allocated." << std::endl;

        return false;
    }

    auto& address = find_address(index, chain, *account);
    const auto& existing = address.contact();

    if (false == existing.empty()) {
        move_transactions(nymID, address, existing, sContactID);
    }

    address.set_contact(sContactID);
    account->set_revision(account->revision() + 1);

    // check: does the activity thread exist between nym and contact?
    bool threadExists = false;
    const auto threadList = api_.Storage().ThreadList(sNymID, false);
    for (const auto it : threadList) {
        const auto& id = it.first;

        if (id == sContactID) { threadExists = true; }
    }

    if (threadExists) {
        // check: does every incoming transaction exist as an activity
        std::shared_ptr<proto::StorageThread> thread =
            activity_.Thread(nymID, contactID);
        OT_ASSERT(thread);
        for (const std::string& txID : address.incoming()) {
            bool exists = false;
            for (const auto activity : thread->item())
                if (txID.compare(activity.id()) == 0) exists = true;

            // add: transaction to the thread
            if (!exists) {
                activity_.AddBlockchainTransaction(
                    nymID,
                    contactID,
                    StorageBox::INCOMINGBLOCKCHAIN,
                    *Transaction(txID));
            }
        }
    } else {
        // create the thread and add the transactions
        for (const auto txID : address.incoming()) {
            activity_.AddBlockchainTransaction(
                nymID,
                contactID,
                StorageBox::INCOMINGBLOCKCHAIN,
                *Transaction(txID));
        }
    }

    return api_.Storage().Store(sNymID, type, *account);
}