コード例 #1
0
ファイル: repl5_agmtlist.c プロジェクト: ohamada/389ds
/*
 * Note: when we add the new object, we have a reference to it. We hold
 * on to this reference until the agreement is deleted (or until the
 * server is shut down).
 */
int
add_new_agreement(Slapi_Entry *e)
{
    int rc = 0;
    Repl_Agmt *ra = agmt_new_from_entry(e);
    Slapi_DN *replarea_sdn = NULL;
    Replica *replica = NULL;
    Object *repl_obj = NULL;
    Object *ro = NULL;

    /* tell search result handler callback this entry was not sent */
    if (ra == NULL)
        return 1;

    ro = object_new((void *)ra, agmt_delete);
    objset_add_obj(agmt_set, ro);
    object_release(ro); /* Object now owned by objset */

    /* get the replica for this agreement */
    replarea_sdn = agmt_get_replarea(ra);
    repl_obj = replica_get_replica_from_dn(replarea_sdn);
    slapi_sdn_free(&replarea_sdn);
    if (repl_obj) {
        replica = (Replica*)object_get_data (repl_obj);
    }

    rc = replica_start_agreement(replica, ra);

    if (repl_obj) object_release(repl_obj);

    return rc;
}
コード例 #2
0
ファイル: main_arp_request.c プロジェクト: te-bachi/mypcap
bool
do_simulation(config_t *config)
{
    netif_t                         netif;
    raw_packet_t                    raw_packet;
    packet_t                       *packet;
    uint32_t                        i;
    //uint32_t                        k;
    
    if (config->netif_size < 1 || config->netif[0].vlan_size < 1 || 
        !config->netif[0].vlan[0].ntp_configured || config->netif[0].vlan[0].ntp.client_size < 1) {
        LOG_PRINTLN(LOG_SIM, LOG_ERROR, ("No ARP config in configuration file! Abort"));
        return false;
    }
    
    if (!netif_init(&netif, config->netif[0].name)) {
        return false;
    }
    
    raw_packet_init(&raw_packet);
    
    LOG_PRINTLN(LOG_SIM, LOG_INFO, ("Create ARP request"));
    packet = create_arp_request(&netif,
                                config->netif[0].vlan[0].vid,
                                &(config->netif[0].vlan[0].ntp.client[0].mac_address),
                                &(config->netif[0].vlan[0].ntp.client[0].ipv4_address));
    
    LOG_PACKET(LOG_SIM, LOG_INFO, packet, ("TX packet"));
    
    /* encode */
    LOG_PRINTLN(LOG_SIM, LOG_INFO, ("Encode packet"));
    if (packet_encode(&netif, packet, &raw_packet)) {
        LOG_PRINTLN(LOG_SIM, LOG_INFO, ("Successfully encoded packet"));
    } else {
        LOG_PRINTLN(LOG_SIM, LOG_ERROR, ("Error encoding packet"));
        object_release(packet);
        return false;
    }
    for (i = 0; i < 0xff; i++) {
        raw_packet.data[raw_packet.len] = i;
        raw_packet.len++;
        LOG_RAW_PACKET(LOG_SIM, LOG_INFO, &raw_packet, ("TX raw"));
        
        /* send */
        netif_frame_send(&netif, &raw_packet);
        usleep(50000);
    }
    object_release(packet);
    
    return true;
}
コード例 #3
0
ファイル: objset.c プロジェクト: Firstyear/ds
/*
 * Return the next object in an object set, or NULL if there are
 * no more objects.
 * The returned object is referenced, therefore
 * the caller must either release the object, or
 * pass it to an objset_next_ob call, which will
 * implicitly release the object.
 */
Object *
objset_next_obj(Objset *set, Object *previous)
{
	Object *return_object = NULL;
	objset_object *p;

	PR_ASSERT(NULL != set);
	PR_Lock(set->lock);

	/* First, find the current object */
	p = set->head;
	while (NULL != p && p->obj != previous)
	{
		p = p->next;
	}
	/* Find the next object */
	if (NULL != p && NULL != p->next)
	{
		return_object = p->next->obj;
		object_acquire(return_object);
	}
	PR_Unlock(set->lock);
	object_release(previous); /* Release the previous object */
	return return_object;
}
コード例 #4
0
ファイル: repl5_agmtlist.c プロジェクト: ohamada/389ds
static int
agmtlist_delete_callback(Slapi_PBlock *pb, Slapi_Entry *e, Slapi_Entry *entryAfter,
	int *returncode, char *returntext, void *arg)
{
	Repl_Agmt *ra;
	Object *ro;

	slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "agmt_delete: begin\n");
	ro = objset_find(agmt_set, agmt_dn_cmp, (const void *)slapi_entry_get_sdn_const(e));
	ra = (NULL == ro) ? NULL : (Repl_Agmt *)object_get_data(ro);
	if (NULL == ra)
	{
		slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name, "agmtlist_delete: "
			"Tried to delete replication agreement \"%s\", but no such "
			"agreement was configured.\n", slapi_sdn_get_dn(slapi_entry_get_sdn_const(e)));
	}
	else
	{
		agmt_stop(ra);
		object_release(ro); /* Release ref acquired in objset_find */
		objset_remove_obj(agmt_set, ro); /* Releases a reference (should be final reference */
	}
	*returncode = LDAP_SUCCESS;
	return SLAPI_DSE_CALLBACK_OK;
}
コード例 #5
0
ファイル: objset.c プロジェクト: Firstyear/ds
/*
 * Delete an object set. All references to contained objects
 * are released, and the objset is deleted.
 */
void
objset_delete(Objset **setp)
{
	objset_object *o, *o_next;
	Objset *set;

	PR_ASSERT(NULL != setp);
	set = *setp;
	PR_ASSERT(NULL != set);
	PR_Lock(set->lock);
	o = set->head;
	while (NULL != o)
	{
		o_next = o->next;
		object_release(o->obj); /* release our reference */
		slapi_ch_free((void **)&o); /* Free wrapper */
		o = o_next;
	}
	PR_Unlock(set->lock);
	PR_DestroyLock(set->lock);
	if (NULL != set->destructor)
	{
		set->destructor((void **)setp);
	}
	slapi_ch_free((void **)setp);
}
コード例 #6
0
ファイル: dacpclient.c プロジェクト: shazron/AirFloat
void _dacp_client_web_connection_connect_failed_callback(web_client_connection_p connection, void* ctx) {
    
    struct dacp_client_t* dc = (struct dacp_client_t*)ctx;
    
    object_release(dc->web_connection);
    dc->web_connection = NULL;
    
}
コード例 #7
0
ファイル: repl5_agmtlist.c プロジェクト: ohamada/389ds
void
agmtlist_release_agmt(Repl_Agmt *ra)
{
	Object *ro;

	PR_ASSERT(NULL != agmt_set);
	PR_ASSERT(NULL != ra);

	ro = objset_find(agmt_set, agmt_ptr_cmp, (const void *)ra);
	if (NULL != ro)
	{
		/*
		 * Release twice - once for the reference we got when finding
		 * it, and once for the reference we got when we called
		 * agmtlist_get_*().
		 */
		object_release(ro);
		object_release(ro);
	}
}
コード例 #8
0
ファイル: repl_connext.c プロジェクト: leto/389-ds
/* consumer connection extension destructor */
void consumer_connection_extension_destructor (void *ext, void *object, void *parent)
{
	PRUint64 connid = 0;
	if (ext)
	{
		/* Check to see if this replication session has acquired
		 * a replica. If so, release it here.
		 */
		consumer_connection_extension *connext = (consumer_connection_extension *)ext;
		if (NULL != connext->replica_acquired)
		{
            Replica *r = object_get_data ((Object*)connext->replica_acquired);
			/* If a total update was in progress, abort it */
			if (REPL_PROTOCOL_50_TOTALUPDATE == connext->repl_protocol_version)
			{
				Slapi_PBlock *pb = slapi_pblock_new();
				const Slapi_DN *repl_root_sdn = replica_get_root(r);
				PR_ASSERT(NULL != repl_root_sdn);
				if (NULL != repl_root_sdn)
				{
					slapi_pblock_set(pb, SLAPI_CONNECTION, connext->connection);
					slapi_pblock_set(pb, SLAPI_TARGET_SDN, (void*)repl_root_sdn);
					slapi_pblock_get(pb, SLAPI_CONN_ID, &connid);
					slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name,
									"Aborting total update in progress for replicated "
									"area %s connid=%" NSPRIu64 "\n", slapi_sdn_get_dn(repl_root_sdn),
									connid);
					slapi_stop_bulk_import(pb);
				}
				else
				{
					slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
						"consumer_connection_extension_destructor: can't determine root "
						"of replicated area.\n");
				}
				slapi_pblock_destroy(pb);

				/* allow reaping again */
				replica_set_tombstone_reap_stop(r, PR_FALSE);
			}
			replica_relinquish_exclusive_access(r, connid, -1);
            object_release ((Object*)connext->replica_acquired);
			connext->replica_acquired = NULL;
		}

        if (connext->supplier_ruv)
        {
            ruv_destroy ((RUV **)&connext->supplier_ruv);
        }
		connext->connection = NULL;
		slapi_ch_free((void **)&ext);	
	}
}
コード例 #9
0
ファイル: dacpclient.c プロジェクト: shazron/AirFloat
void _dacp_client_destroy(void* object) {
    
    struct dacp_client_t* dc = (struct dacp_client_t*)object;
    
    object_release(dc->endpoint);
    
    dc->is_destroyed = true;
    
    if (dc->dacp_discover != NULL) {
        object_release(dc->dacp_discover);
        dc->dacp_discover = NULL;
    }
    
    if (dc->web_connection != NULL) {
        object_release(dc->web_connection);
        dc->web_connection = NULL;
    }
    
    free(dc->identifier);
    free(dc->active_remove);
    
}
コード例 #10
0
ファイル: main_arp_reply.c プロジェクト: te-bachi/mypcap
int
main(int argc, char *argv[])
{
    netif_t                         netif;
    raw_packet_t                    raw_packet;
    packet_t                       *packet;
    //header_t                       *header;
    mac_address_t                   mac = { .addr = { 0x00, 0x01, 0x20, 0x00, 0x00, 0x01 } };
    mac_address_t                   mac2;
    uint8_t                         mac_str[STR_MAC_ADDRESS_MAX_LEN];
    
    uint32_t                        num;
    uint8_t                         str[20] = "12345678";
    hexstr2num(&num, str, 8);
    printf("decimal = %" PRIu32 " hex = 0x%" PRIx32 "\n", num, num);
    
    
    if (mac_address_convert_to_string(&mac, mac_str)) {
        printf("tostring: true: %s\n", mac_str);
    } else {
        printf("tostring: false\n");
    }

    if (mac_address_convert_from_string(&mac2, mac_str)) {
        printf("fromstring: true: %02" PRIx8 ":%02" PRIx8 ":%02" PRIx8 ":%02" PRIx8 ":%02" PRIx8 ":%02" PRIx8 "\n",
                mac2.addr[0], mac2.addr[1], mac2.addr[2],
                mac2.addr[3], mac2.addr[4], mac2.addr[5]);
    } else {
        printf("fromstring: false\n");
    }
    
    return 0;
    
    if (argc != 3) {
        printf("usage: %s ifname ip-address mac-address\n", argv[0]);
        return -1;
    }

    if (!netif_init(&netif, argv[1])) {
        return false;
    }

    raw_packet_init(&raw_packet);
    //packet = create_ptp2_signaling_req( &slave_mac, &slave_ipv4);


    object_release(packet);

    return 0;
}
コード例 #11
0
ファイル: instance.c プロジェクト: Firstyear/ds
/* find the instance in the objset and remove it */
int
ldbm_instance_destroy(ldbm_instance *inst)
{
    Object *object = NULL;
    struct ldbminfo *li = inst->inst_li;

    object = objset_find(li->li_instance_set, ldbm_instance_comparator, inst);
    if (object == NULL) {
        return -1;
    }
    /* decref from objset_find */
    object_release(object);

    /* now remove from the instance set */
    objset_remove_obj(li->li_instance_set, object);
    return 0;
}
コード例 #12
0
ファイル: dacpclient.c プロジェクト: shazron/AirFloat
void _dacp_client_web_connection_disconnected_callback(web_client_connection_p connection, void* ctx) {
    
    struct dacp_client_t* dc = (struct dacp_client_t*)ctx;
    
    if (dc->web_connection != NULL) {
        
        if (dc->callbacks.controls_became_unavailable != NULL)
            dc->callbacks.controls_became_unavailable(dc, dc->callbacks.ctx.controls_became_unavailable);
        
        if (!dc->is_destroyed) {
            object_release(dc->web_connection);
            dc->web_connection = NULL;
        }
        
    }
    
}
コード例 #13
0
ファイル: instance.c プロジェクト: Firstyear/ds
/* Currently this function doesn't bump
 * the ref count of the instance returned.
 */
ldbm_instance *
ldbm_instance_find_by_name(struct ldbminfo *li, char *name)
{
    Object *inst_obj;
    ldbm_instance *inst;

    inst_obj = objset_first_obj(li->li_instance_set);
    while (inst_obj != NULL)  {
        inst = (ldbm_instance *) object_get_data(inst_obj);
        if (!strcasecmp(inst->inst_name, name)) {
            /* Currently we release the object here.  There is no
             * function for callers of this function to call to
             * release the object.
             */
            object_release(inst_obj);
            return inst;
        }
        inst_obj = objset_next_obj(li->li_instance_set, inst_obj);
    }
    return NULL;
}
コード例 #14
0
ファイル: dacpclient.c プロジェクト: shazron/AirFloat
void _dacp_client_send_request(struct dacp_client_t* dc, const char* request_name) {
    
    if (dacp_client_is_available(dc)) {
        
        web_request_p request = web_request_create();
        
        char path[strlen(request_name) + 13];
        sprintf(path, "/ctrl-int/1/%s", request_name);
        
        web_request_set_method(request, "GET");
        web_request_set_path(request, path);
        web_request_set_protocol(request, "HTTP/1.1");
        
        web_headers_set_value(web_request_get_headers(request), "Active-Remote", dc->active_remove);
        
        web_client_connection_send_request(dc->web_connection, request);
        
        object_release(request);
        
    }
    
}
コード例 #15
0
ファイル: misc.c プロジェクト: leto/389-ds
int
is_anyinstance_busy(struct ldbminfo *li)
{
    ldbm_instance *inst;
    Object *inst_obj;
    int rval = 0;

    /* server is up -- mark all backends busy */
    for (inst_obj = objset_first_obj(li->li_instance_set); inst_obj;
        inst_obj = objset_next_obj(li->li_instance_set, inst_obj)) {
        inst = (ldbm_instance *)object_get_data(inst_obj);
        PR_Lock(inst->inst_config_mutex);
        rval = inst->inst_flags & INST_FLAG_BUSY;
        PR_Unlock(inst->inst_config_mutex);
        if (0 != rval) {
            break;
        }
    }
    if (inst_obj)
        object_release(inst_obj);
    return rval;
}
コード例 #16
0
ファイル: dacpclient.c プロジェクト: shazron/AirFloat
void _dacp_client_web_connection_response_received_callback(web_client_connection_p connection, web_request_p request, web_response_p response, void* ctx) {
    
    struct dacp_client_t* dc = (struct dacp_client_t*)ctx;
    
    if (web_response_get_status(response) == 200 && dc->callbacks.playback_state_changed != NULL) {
        
        web_headers_p headers = web_response_get_headers(response);
        
        size_t content_length;
        const char* s_content_type = web_headers_value(headers, "Content-Type");
        
        if (s_content_type != NULL && strcmp(s_content_type, "application/x-dmap-tagged") == 0 && (content_length = web_response_get_content(response, NULL, 0)) > 0) {
            
            char data[content_length];
            
            web_response_get_content(response, data, content_length);
            
            dmap_p dmap = dmap_create();
            dmap_parse(dmap, data, content_length);
            
            dmap_p container = dmap_container_for_atom_identifer(dmap, "com.airfloat.nowplayingcontainer");
            
            if (container != NULL) {
                
                char now_playing = dmap_char_for_atom_identifer(container, "com.airfloat.nowplayingstatus");
                dc->playback_state = now_playing;
                dc->callbacks.playback_state_changed(dc, dc->playback_state, dc->callbacks.ctx.playback_state_changed);
                
            }
            
            object_release(dmap);
            
        }
        
    }
    
}
コード例 #17
0
ファイル: objset.c プロジェクト: Firstyear/ds
/*
 * Remove an object from an objset.
 * Returns OBJSET_SUCCESS if the object was found and removed, or
 * OBJSET_NO_SUCH_OBJECT if the object was not found in the list.
 */
int
objset_remove_obj(Objset *set, Object *object) 
{
	int rc = OBJSET_SUCCESS;
	objset_object *found;

	PR_ASSERT(NULL != set);
	PR_ASSERT(NULL != object);

	PR_Lock(set->lock);
	found = set->head;
	while (NULL != found)
	{
		if (found->obj == object)
		{
			break;
		}
		found = found->next;
	}
	if (NULL == found)
	{
		rc = OBJSET_NO_SUCH_OBJECT;
	}
	else
	{
		Object *saved = found->obj;

		/* Unlink from list */
		unlinkObjsetObjectNoLock(set, found);

		/* Release reference on object */
		object_release(saved);
	}
	PR_Unlock(set->lock);
	return rc;
}
コード例 #18
0
ファイル: instance.c プロジェクト: Firstyear/ds
/* Creates and initializes a new ldbm_instance structure.
 * Also sets up some default indexes for the new instance.
 */
int ldbm_instance_create(backend *be, char *name)
{
    struct ldbminfo *li = (struct ldbminfo *) be->be_database->plg_private;
    ldbm_instance *inst = NULL;
    int rc = 0;

    /* Allocate storage for the ldbm_instance structure.  Information specific
     * to this instance of the ldbm backend will be held here. */
    inst = (ldbm_instance *) slapi_ch_calloc(1, sizeof(ldbm_instance));

    /* Record the name of this instance. */
    inst->inst_name = slapi_ch_strdup(name);

    /* initialize the entry cache */
    if (! cache_init(&(inst->inst_cache), DEFAULT_CACHE_SIZE,
                     DEFAULT_CACHE_ENTRIES, CACHE_TYPE_ENTRY)) {
        slapi_log_err(SLAPI_LOG_ERR, "ldbm_instance_create", "cache_init failed\n");
        rc = -1;
        goto error;
    }

    /*
     * initialize the dn cache 
     * We do so, regardless of the subtree-rename value.
     * It is needed when converting the db from DN to RDN format.
     */
    if (! cache_init(&(inst->inst_dncache), DEFAULT_DNCACHE_SIZE,
                     DEFAULT_DNCACHE_MAXCOUNT, CACHE_TYPE_DN)) {
        slapi_log_err(SLAPI_LOG_ERR,
                       "ldbm_instance_create", "dn cache_init failed\n");
        rc = -1;
        goto error;
    }

    /* Lock for the list of open db handles */
    inst->inst_handle_list_mutex = PR_NewLock();
    if (NULL == inst->inst_handle_list_mutex) {
        slapi_log_err(SLAPI_LOG_ERR, "ldbm_instance_create", "PR_NewLock failed\n");
        rc = -1;
        goto error;
    }

    /* Lock used to synchronize modify operations. */
    inst->inst_db_mutex = PR_NewMonitor();
    if (NULL == inst->inst_db_mutex) {
        slapi_log_err(SLAPI_LOG_ERR, "ldbm_instance_create", "PR_NewMonitor failed\n");
        rc = -1;
        goto error;
    }

    if ((inst->inst_config_mutex = PR_NewLock()) == NULL) {
        slapi_log_err(SLAPI_LOG_ERR, "ldbm_instance_create", "PR_NewLock failed\n");
        rc = -1;
        goto error;
    }

    if ((inst->inst_nextid_mutex = PR_NewLock()) == NULL) {
        slapi_log_err(SLAPI_LOG_ERR, "ldbm_instance_create", "PR_NewLock failed\n");
        rc = -1;
        goto error;
    }

    if ((inst->inst_indexer_cv = PR_NewCondVar(inst->inst_nextid_mutex)) == NULL) {
        slapi_log_err(SLAPI_LOG_ERR, "ldbm_instance_create", "PR_NewCondVar failed\n");
        rc = -1;
        goto error;
    }

    /* Keeps track of how many operations are currently using this instance */
    inst->inst_ref_count = slapi_counter_new();

    inst->inst_be = be;
    inst->inst_li = li;
    be->be_instance_info = inst;

    /* Initialize the fields with some default values. */
    ldbm_instance_config_setup_default(inst);

    /* Add this new instance to the the set of instances */
    {
        Object *instance_obj;

        instance_obj = object_new((void *) inst, &ldbm_instance_destructor);
        objset_add_obj(li->li_instance_set, instance_obj);
        object_release(instance_obj);
    }
    goto done;

error:
    slapi_ch_free_string(&inst->inst_name);
    slapi_ch_free((void**)&inst);

done:
    return rc;
}
コード例 #19
0
ファイル: queue.c プロジェクト: ccl2of4/C-Utilities
void _object_dealloc__queue (object_ref _self) {
	struct queue *self = _self;
	TYPE_CHECK(self, queue);
	object_release (self->list);
}