예제 #1
0
void p2p_cron_announce(ITEM * ti)
{
	ITEM *item = NULL;
	ITEM *t_new = NULL;
	int j = 0;
	TID *tid = list_value(ti);
	LOOKUP *l = tid->lookup;
	NODE_L *n = NULL;

	info(_log, NULL, "Start announcing after querying %lu nodes",
	     list_size(l->list));

	item = list_start(l->list);
	while (item != NULL && j < 8) {
		n = list_value(item);

		if (n->token_size != 0) {
			t_new = tdb_put(P2P_ANNOUNCE_ENGAGE);
			send_announce_request(&n->c_addr, tdb_tid(t_new),
					      l->target, n->token,
					      n->token_size);
			j++;
		}

		item = list_next(item);
	}
}
예제 #2
0
void p2p_cron_find(UCHAR * target)
{
	ITEM *item_b = NULL;
	BUCK *b = NULL;
	ITEM *item_n = NULL;
	UDP_NODE *n = NULL;
	unsigned long int j = 0;
	ITEM *ti = NULL;

	if ((item_b = bckt_find_any_match(_main->nbhd->bucket, target)) == NULL) {
		return;
	} else {
		b = list_value(item_b);
	}

	j = 0;
	item_n = list_start(b->nodes);
	while (item_n != NULL && j < 8) {
		n = list_value(item_n);

		if (_main->p2p->time_now.tv_sec > n->time_find) {

			ti = tdb_put(P2P_FIND_NODE);
			send_find_node_request(&n->c_addr, target, tdb_tid(ti));
			time_add_5_min_approx(&n->time_find);
		}

		item_n = list_next(item_n);
		j++;
	}
}
예제 #3
0
LIST *
builtin_luafile(
        PARSE    *parse,
        LOL        *args,
        int        *jmp)
{
    int top;
    int ret;
    LISTITEM *l2;
    int index = 0;

    LIST *l = lol_get(args, 0);
    if (!list_first(l)) {
        printf("jam: No argument passed to LuaFile\n");
        exit(EXITBAD);
    }
    ls_lua_init();
    top = ls_lua_gettop(L);
    ls_lua_newtable(L);
    for (l2 = list_first(lol_get(args, 1)); l2; l2 = list_next(l2)) {
        ls_lua_pushstring(L, list_value(l2));
        ls_lua_rawseti(L, -2, ++index);
    }
    ls_lua_setglobal(L, "arg");
    ret = ls_luaL_loadfile(L, list_value(list_first(l)));
    return ls_lua_callhelper(top, ret);
}
예제 #4
0
파일: hcache.c 프로젝트: r1chi3x/jamplus
/*
 * Get a filename in cache for given md5sum.
 */
const char *filecache_getpath(TARGET *t)
{
	char buffer[1024];
	LIST *filecache;
	const char *cachedir = NULL;
	LIST *cachevar;

	pushsettings( t->settings );
	filecache = var_get( "FILECACHE" );
	if ( !list_first(filecache) ) {
		popsettings( t->settings );
		return NULL;
	}

	/* get directory where objcache should reside */
	strcpy( buffer, list_value(list_first(filecache)) );
	strcat( buffer, ".PATH" );
	cachevar = var_get( buffer );
	if( list_first(cachevar) ) {
		TARGET *t = bindtarget(list_value(list_first(cachevar)));
		t->boundname = search( t->name, &t->time );
		cachedir = copystr( t->boundname );
	}

	popsettings( t->settings );

	return cachedir;
}
예제 #5
0
파일: hcache.c 프로젝트: caryhaynie/jamplus
void
	hcache_writefile(HCACHEFILE *file)
{
	FILE	*f;
	HCACHEDATA	*c;
	int		header_count = 0;
	int		maxage;

	if( !file  ||  !file->dirty  ||  !file->cachefilename )
		return;

	file_mkdir(file->cachefilename);

	if( ! (f = fopen( file->cachefilename, "wb" ) ) )
		return;

	maxage = cache_maxage();

	/* print out the version */
	fprintf( f, "@%s@\n", CACHE_FILE_VERSION );

	for( c = file->hcachelist; c; c = c->next ) {
		LISTITEM	*l;

		if( maxage == 0 )
			c->age = 0;
		else if( c->age > maxage )
			continue;

		write_string( f, c->boundname );
		write_int( f, (int)c->time );
		write_int( f, c->age );

#ifdef OPT_BUILTIN_MD5CACHE_EXT
		write_md5sum( f, c->rulemd5sum );
#endif

		write_int( f, list_length( c->includes ) );
		for( l = list_first(c->includes); l; l = list_next( l ) ) {
			write_string( f, list_value(l) );
		}

		write_int( f, list_length( c->hdrscan ) );
		for( l = list_first(c->hdrscan); l; l = list_next( l ) ) {
			write_string( f, list_value(l) );
		}

		fputc( '!', f );
		fputc( '\n', f );
		++header_count;
	}

	if( DEBUG_HEADER )
		printf( "hcache written to %s.	 %d dependencies, %.0f%% hit rate\n",
		file->cachefilename, header_count,
		queries ? 100.0 * hits / queries : 0 );

	fclose( f );
}
예제 #6
0
파일: headers.c 프로젝트: arventwei/jamplus
LIST *
headers1(
	const char *file,
	LIST *hdrscan )
{
	FILE	*f;
	LIST	*result = 0;
	LIST    *hdrpipe;
	LIST	*hdrpipefile;

	if ( list_first(hdrpipe = var_get( "HDRPIPE" )) )
	{
		LOL args;
		BUFFER buff;
		lol_init( &args );
		lol_add( &args, list_append( L0, file, 0 ) );
		buffer_init( &buff );
		if ( var_string( list_value(list_first(hdrpipe)), &buff, 0, &args, ' ') < 0 )  {
		    printf( "Cannot expand HDRPIPE '%s' !\n", list_value(list_first(hdrpipe)) );
		    exit( EXITBAD );
		}
		buffer_addchar( &buff, 0 );
		if ( !( f = file_popen( (const char*)buffer_ptr( &buff ), "r" ) ) ) {
		    buffer_free( &buff );
		    return result;
		}
		buffer_free( &buff );
		lol_free( &args );
	}
	else
	{
		if( !( f = fopen( file, "r" ) ) )
		    return result;
	}

	result = headers1helper( f, hdrscan );

	if ( list_first(hdrpipe) )
		file_pclose( f );
	else
		fclose( f );

	if ( list_first(hdrpipefile = var_get( "HDRPIPEFILE" )) )
	{
		if( !( f = fopen( list_value(list_first(hdrpipefile)), "r" ) ) )
		    return result;
		result = headers1helper( f, hdrscan );
		fclose( f );
	}

	return result;
}
예제 #7
0
void p2p_error(BEN * packet, IP * from)
{
	BEN *e = NULL;
	BEN *code = NULL;
	BEN *msg = NULL;
	ITEM *i = NULL;

#if 0
	BEN *t = NULL;
	/* Transaction ID */
	t = ben_dict_search_str(packet, "t");
	if (!ben_is_str(t)) {
		info(_log, from, "Missing transaction ID from");
		return;
	}
	if (ben_str_i(t) != TID_SIZE) {
		info(_log, from, "Broken transaction ID from");
		return;
	}
#endif

	/* The error */
	e = ben_dict_search_str(packet, "e");
	if (!ben_is_list(e)) {
		info(_log, from, "Missing or broken error message from");
		return;
	}

	/* Error code */
	i = list_start(e->v.l);
	code = list_value(i);
	if (!ben_is_int(code)) {
		info(_log, from, "Broken error code from");
		return;
	}

	/* Error message */
	i = list_stop(e->v.l);
	msg = list_value(i);
	if (!ben_is_str(msg)) {
		info(_log, from, "Broken error message from");
		return;
	}
	if (ben_str_i(msg) > 100) {
		info(_log, from, "Error message too big from");
		return;
	}

	/* Notification */
	info(_log, from, "ERROR %li: \"%s\" from", code->v.i, ben_str_s(msg));
}
예제 #8
0
LIST *
compile_switch(
	PARSE	*parse,
	LOL	*args,
	int	*jmp )
{
	LIST	*nt = (*parse->left->func)( parse->left, args, jmp );
	LIST	*result = 0;

	if( DEBUG_COMPILE )
	{
	    debug_compile( 0, "switch" );
	    list_print( nt );
	    printf( "\n" );
	}

	/* Step through cases */

	for( parse = parse->right; parse; parse = parse->right )
	{
	    if( !glob( parse->left->string, list_first(nt) ? list_value(list_first(nt)) : "" ) )
	    {
		/* Get & exec parse tree for this case */
		parse = parse->left->left;
		result = (*parse->func)( parse, args, jmp );
		break;
	    }
	}

	list_free( nt );

	return result;
}
예제 #9
0
int LS_jam_expand(ls_lua_State *L)
{
    LIST *list = L0;
    LISTITEM* item;
    int index;

    int numParams = ls_lua_gettop(L);
    if (numParams < 1  ||  numParams > 1)
        return 0;

    if (!ls_lua_isstring(L, 1))
        return 0;

    {
        LOL lol;
        const char* src = ls_lua_tostring(L, 1);
        lol_init(&lol);
        list = var_expand(L0, src, src + strlen(src), &lol, 0);
    }

    ls_lua_newtable(L);
    index = 1;
    for (item = list_first(list); item; item = list_next(item), ++index)
    {
        ls_lua_pushnumber(L, index);
        ls_lua_pushstring(L, list_value(item));
        ls_lua_settable(L, -3);
    }

    return 1;
}
예제 #10
0
파일: list.c 프로젝트: ral99/ral99lib
void list_full_filter(ADTList list, int (*filter)(void *), void (*release)(void *)) {
    for (ADTListItem it = list_head(list), next; it; it = next) {
        next = list_next(it);
        if (filter(list_value(it)) == 0)
            list_remove_full_item(list, it, release);
    }
}
예제 #11
0
LIST *
compile_rule(
	PARSE	*parse,
	LOL	*args,
	int	*jmp )
{
	LOL	nargs[1];
	LIST	*result = 0;
	LIST	*ll;
	LISTITEM *l;
	PARSE	*p;

	/* list of rules to run -- normally 1! */

	ll = (*parse->left->func)( parse->left, args, jmp );

	/* Build up the list of arg lists */

	lol_init( nargs );

	for( p = parse->right; p; p = p->left )
	    lol_add( nargs, (*p->right->func)( p->right, args, jmp ) );

	/* Run rules, appending results from each */

	for( l = list_first(ll); l; l = list_next( l ) ) {
	    list_free(result); /* Keep only last result */
	    result = evaluate_rule( list_value(l), nargs, result );
	}

	list_free( ll );
	lol_free( nargs );

	return result;
}
예제 #12
0
LIST *
compile_set(
	PARSE	*parse,
	LOL	*args,
	int	*jmp )
{
	LIST	*nt = (*parse->left->func)( parse->left, args, jmp );
	LIST	*ns = (*parse->right->func)( parse->right, args, jmp );
	LISTITEM	*l;

	if( DEBUG_COMPILE )
	{
	    debug_compile( 0, "set" );
	    list_print( nt );
	    printf( " %s ", set_names[ parse->num ] );
	    list_print( ns );
	    printf( "\n" );
	}

	/* Call var_set to set variable */
	/* var_set keeps ns, so need to copy it */

	for( l = list_first(nt); l; l = list_next( l ) )
	    var_set( list_value(l), list_copy( L0, ns ), parse->num );

	list_free( nt );

	return ns;
}
예제 #13
0
void filter_legal(list_t * list, const board_t * board) {

   int pos;
   int i, move, value;

   ASSERT(list_is_ok(list));
   ASSERT(board_is_ok(board));

   pos = 0;

   for (i = 0; i < list_size(list); i++) {

      ASSERT(pos>=0&&pos<=i);

      move = list_move(list,i);
      value = list_value(list,i);

      if (pseudo_is_legal(move,board)) {
         list->move[pos] = move;
         list->value[pos] = value;
         pos++;
      }
   }

   ASSERT(pos>=0&&pos<=list_size(list));
   list->size = pos;
}
예제 #14
0
파일: hcache.c 프로젝트: r1chi3x/jamplus
void filecache_disable(TARGET *t)
{
	BUFFER buff;
	LIST *filecache;
	char const* filecacheStr;
	pushsettings( t->settings );
	filecache = var_get( "FILECACHE" );
	if ( !list_first(filecache) ) {
		popsettings( t->settings );
		return;
	}

	filecacheStr = list_value(list_first(filecache));

	buffer_init(&buff);
	buffer_addstring(&buff, filecacheStr, strlen(filecacheStr));
	buffer_addstring(&buff, ".USE", 4);
	buffer_addchar(&buff, 0);
	var_set(buffer_ptr(&buff), list_append(L0, "0", 0), VAR_SET);
	buffer_free(&buff);

	buffer_init(&buff);
	buffer_addstring(&buff, filecacheStr, strlen(filecacheStr));
	buffer_addstring(&buff, ".GENERATE", 9);
	buffer_addchar(&buff, 0);
	var_set(buffer_ptr(&buff), list_append(L0, "0", 0), VAR_SET);
	buffer_free(&buff);
}
예제 #15
0
파일: list.c 프로젝트: ral99/ral99lib
int list_min(ADTList list, int (*func)(void *)) {
    int min = INT_MAX;
    for (ADTListItem it = list_head(list); it; it = list_next(it)) {
        int value = func(list_value(it));
        min = (value < min) ? value : min;
    }
    return min;
}
예제 #16
0
파일: list.c 프로젝트: ral99/ral99lib
int list_max(ADTList list, int (*func)(void *)) {
    int max = INT_MIN;
    for (ADTListItem it = list_head(list); it; it = list_next(it)) {
        int value = func(list_value(it));
        max = (value > max) ? value : max;
    }
    return max;
}
예제 #17
0
CACHE *cache_find( UCHAR *target ) {
	ITEM *item = NULL;

	if( ( item = hash_get( _main->cache->hash, target, SHA1_SIZE ) ) == NULL ) {
		return NULL;
	}

	return list_value( item );
}
예제 #18
0
파일: list.c 프로젝트: ral99/ral99lib
void *list_pop_random(ADTList list) {
    ADTListItem item = list_random_item(list);
    if (item) {
        void *value = list_value(item);
        list_remove_item(list, item);
        return value;
    }
    return NULL;
}
예제 #19
0
파일: list.c 프로젝트: ral99/ral99lib
char *list_to_str(ADTList list, char *(*to_str)(void *)) {
    ADTList str_list = list_new();
    for (ADTListItem it = list_head(list); it; it = list_next(it)) {
        char *str = to_str(list_value(it));
        list_append(str_list, str_escape(str, (char *) ","));
        free(str);
    }
    char *str = str_join(str_list, (char *) ",");
    list_full_release(str_list, free);
    return str;
}
예제 #20
0
LIST *
compile_settings(
	PARSE	*parse,
	LOL	*args,
	int	*jmp )
{
	LIST	*nt = (*parse->left->func)( parse->left, args, jmp );
	LIST	*ns = (*parse->third->func)( parse->third, args, jmp );
	LIST	*targets = (*parse->right->func)( parse->right, args, jmp );
	LISTITEM	*ts;

	if( DEBUG_COMPILE )
	{
	    debug_compile( 0, "set" );
	    list_print( nt );
	    printf( "on " );
	    list_print( targets );
	    printf( " %s ", set_names[ parse->num ] );
	    list_print( ns );
	    printf( "\n" );
	}

	/* Call addsettings to save variable setting */
	/* addsettings keeps ns, so need to copy it */
	/* Pass append flag to addsettings() */

	for( ts = list_first(targets); ts; ts = list_next( ts ) )
	{
	    TARGET 	*t = bindtarget( list_value(ts) );
	    LISTITEM	*l;

	    for( l = list_first(nt); l; l = list_next( l ) )
		t->settings = addsettings( t->settings, parse->num,
				list_value(l), list_copy( NULL, ns ) );
	}

	list_free( nt );
	list_free( targets );

	return ns;
}
예제 #21
0
static int
lcmp( LIST *t, LIST *s )
{
	int status = 0;

	LISTITEM* ti = list_first(t);
	LISTITEM* si = list_first(s);

	while( !status && ( ti || si ) )
	{
	    const char *st = ti ? list_value(ti) : "";
	    const char *ss = si ? list_value(si) : "";

	    status = strcmp( st, ss );

	    ti = ti ? list_next( ti ) : ti;
	    si = si ? list_next( si ) : si;
	}

	return status;
}
예제 #22
0
void tcp_output( ITEM *i ) {
	TCP_NODE *n = list_value( i );

	switch( n->pipeline ) {
		case NODE_SEND_INIT:
		case NODE_SEND_DATA:
		case NODE_SEND_STOP:
			/* Send file */
			send_tcp( n );
			break;
	}
}
예제 #23
0
void p2p_cron_ping(void)
{
	ITEM *item_b = NULL;
	BUCK *b = NULL;
	ITEM *item_n = NULL;
	UDP_NODE *n = NULL;
	ITEM *ti = NULL;
	unsigned long int j = 0;

	/* Cycle through all the buckets */
	item_b = list_start(_main->nbhd->bucket);
	while (item_b != NULL) {
		b = list_value(item_b);

		/* Cycle through all the nodes */
		j = 0;
		item_n = list_start(b->nodes);
		while (item_n != NULL) {
			n = list_value(item_n);

			/* It's time for pinging */
			if (_main->p2p->time_now.tv_sec > n->time_ping) {

				/* Ping the first 8 nodes. Ignore the rest. */
				if (j < 8) {
					ti = tdb_put(P2P_PING);
					send_ping(&n->c_addr, tdb_tid(ti));
					nbhd_pinged(n->id);
				} else {
					nbhd_pinged(n->id);
				}
			}

			item_n = list_next(item_n);
			j++;
		}

		item_b = list_next(item_b);
	}
}
예제 #24
0
파일: hcache.c 프로젝트: caryhaynie/jamplus
const char *checksums_filename() {
	LIST *var;
	if ( checksumsfilename ) {
		return checksumsfilename;
	}

	var = var_get( "JAM_CHECKSUMS_FILE" );
	if ( list_first( var ) ) {
		const char *value = list_value( list_first( var ) );
		TARGET *t = bindtarget( value );
		checksumsfilename = copystr( search_using_target_settings( t, t->name, &t->time ) );
	}

	if ( !checksumsfilename ) {
		PATHNAME f[1];
		char buf[ MAXJPATH ];

		var = var_get( "ALL_LOCATE_TARGET" );
		if ( !var ) {
			var = var_get( "CWD" );
		}

		path_parse( ".jamchecksums", f );

		f->f_grist.ptr = 0;
		f->f_grist.len = 0;

		if ( var ) {
			f->f_root.ptr = list_value( list_first( var ) );
			f->f_root.len = (int)( strlen( f->f_root.ptr ) );
		}

		path_build( f, buf, 1, 1 );
		checksumsfilename = newstr( buf );
	}

	return checksumsfilename;
}
예제 #25
0
파일: hcache.c 프로젝트: r1chi3x/jamplus
/*
 * Return the maximum age a cache entry can have before it is purged
 * from the cache.
 *
 * A maxage of 0 indicates that the cache entries should never be
 * purged, in effect disabling the aging of cache entries.
 */
static int
cache_maxage(void)
{
	int age = 0;
	LIST *var = var_get( "DEPCACHEMAXAGE" );

	if( list_first(var) ) {
		age = atoi( list_value(list_first(var)) );
		if( age < 0 )
			age = 0;
	}

	return age;
}
예제 #26
0
파일: queue.c 프로젝트: nirbenabu/Homework
/**
* Gets the last node from queue and remove it. Data needs to get free manually!!!
* Input: Queue* q - pointer to the queue
* Output: void* - pointer to value
**/
void* queue_dequeue(Queue* q) { /* Use the list function, backup memory before deletion,
                                !!!data should be freed manually!!! */
    if(queue_size(q)>0) {
      if(q == NULL)
        return NULL;
      Node* n = list_last(&q->l);
      int size = 4; /* 4 Bytes is the size of void* */
      void* data = (void*)malloc(size);
      memcpy(data, list_value(list_last(&q->l)), size);
      list_delete(&q->l, n);

      return data;
    } else
        return 0;
}
예제 #27
0
파일: hcache.c 프로젝트: r1chi3x/jamplus
LIST *filecache_fillvalues(TARGET *t)
{
	LIST *filecache;

	if ( !( t->flags & T_FLAG_USEFILECACHE ) )
		return 0;

	filecache = var_get( "FILECACHE" );
	if ( list_first(filecache) ) {
		LIST *l;
		BUFFER buff;
		char const* filecacheStr = list_value(list_first(filecache));

		buffer_init(&buff);
		buffer_addstring(&buff, filecacheStr, strlen(filecacheStr));
		buffer_addstring(&buff, ".USE", 4);
		buffer_addchar(&buff, 0);
		l = var_get( buffer_ptr( &buff ) );
		if ( list_first(l)  &&  atoi( list_value(list_first(l)) ) != 0) {
			t->filecache_use = 1;
		}
		buffer_free(&buff);

		buffer_init(&buff);
		buffer_addstring(&buff, filecacheStr, strlen(filecacheStr));
		buffer_addstring(&buff, ".GENERATE", 9);
		buffer_addchar(&buff, 0);
		l = var_get( buffer_ptr( &buff ) );
		if ( list_first(l)  &&  atoi(list_value(list_first(l))) != 0) {
			t->filecache_generate = 1;
		}
		buffer_free(&buff);
	}

	return filecache;
}
예제 #28
0
void tcp_newconn( void ) {
	struct epoll_event ev;
	ITEM *listItem = NULL;
	TCP_NODE *n = NULL;
	int connfd;
	IP c_addr;
	socklen_t c_addrlen = sizeof( IP );

	for( ;; ) {
		/* Prepare incoming connection */
		memset( ( char * ) &c_addr, '\0', c_addrlen );

		/* Accept */
		connfd = accept( _main->tcp->sockfd, ( struct sockaddr * ) &c_addr, &c_addrlen );
		if( connfd < 0 ) {
			if( errno == EAGAIN || errno == EWOULDBLOCK ) {
				break;
			} else {
				fail( strerror( errno ) );
			}
		}

		/* New connection: Create node object */
		if( ( listItem = node_put() ) == NULL ) {
			info( NULL, "The linked list reached its limits" );
			node_disconnect( connfd );
			break;
		}

		/* Store data */
		n = list_value( listItem );
		n->connfd = connfd;
		memcpy( &n->c_addr, &c_addr, c_addrlen );
		n->c_addrlen = c_addrlen;

		/* Non blocking */
		if( tcp_nonblocking( n->connfd ) < 0 ) {
			fail( "tcp_nonblocking() failed" );
		}

		ev.events = EPOLLET | EPOLLIN | EPOLLONESHOT;
		ev.data.ptr = listItem;
		if( epoll_ctl( _main->tcp->epollfd, EPOLL_CTL_ADD, n->connfd, &ev ) == -1 ) {
			info( NULL, strerror( errno ) );
			fail( "tcp_newconn: epoll_ctl( ) failed" );
		}
	}
}
예제 #29
0
void p2p_cron_lookup_all(void)
{
	ITEM *i = list_start(_main->identity);
	ID *identity = NULL;

	while (i != NULL) {
		identity = list_value(i);

		if (_main->p2p->time_now.tv_sec > identity->time_announce_host) {
			p2p_cron_lookup(identity->host_id, P2P_ANNOUNCE_START);
			time_add_5_min_approx(&identity->time_announce_host);
		}

		i = list_next(i);
	}
}
예제 #30
0
파일: tcp.c 프로젝트: wwttt2004/torrentkino
void tcp_output( ITEM *listItem ) {
	TCP_NODE *n = list_value( listItem );
	
	switch( n->mode ) {
		case NODE_MODE_SEND_INIT:
		case NODE_MODE_SEND_MEM:
		case NODE_MODE_SEND_FILE:
		case NODE_MODE_SEND_STOP:
			
			/* Reset timeout counter */
			node_activity( n );
			
			/* Send file */
			send_tcp( n );
			break;
	}
}