Exemplo n.º 1
0
char *test_tst_collect()
{
    list_t *found = tst_collect(node, "TE", 2, NULL);
    debug("collect found %d values", (int)list_count(found));

    mu_assert(list_count(found) == 3, "Didn't find 2 with prefix TE.");
    list_destroy_nodes(found);
    list_destroy(found);

    found = tst_collect(node, "T", 1, NULL);
    debug("collect found %d values", (int)list_count(found));
    mu_assert(list_count(found) == 4, "Didn't find 4 with prefix T.");
    list_destroy_nodes(found);
    list_destroy(found);

    found = tst_collect(node, "TEST2", 5, NULL);
    debug("collect found %d values", (int)list_count(found));
    mu_assert(list_count(found) == 1, "Didn't find 1 with prefix TEST2.");
    list_destroy_nodes(found);
    list_destroy(found);

    found = tst_collect(node, "XNOT", 4, NULL);
    mu_assert(list_count(found) == 0, "Should not find any with prefix XNOT.");
    list_destroy_nodes(found);
    list_destroy(found);

    return NULL;
}
Exemplo n.º 2
0
void CDlpFile_Destructor(CDlpObject* __this)
{
	GET_THIS_VIRTUAL(CDlpFile);
	{
	/*{{CGEN_DONECODE */

  /* free list of filetypes */
  if(_this->m_lpFtypes)
  {
  list_process(_this->m_lpFtypes,NULL,CDlpFile_FreeFTypeList);
  list_destroy_nodes(_this->m_lpFtypes);
  list_destroy(_this->m_lpFtypes);
  _this->m_lpFtypes = NULL;
  }

  DONE;

	/*}}CGEN_DONECODE */
	}

#ifndef __cplusplus

	/* Destroy base instance */
	CDlpObject_Destructor(_this->m_lpBaseInstance);
	dlp_free(_this->m_lpBaseInstance);
	_this->m_lpBaseInstance = NULL;

#endif /* #ifndef __cplusplus */
}
Exemplo n.º 3
0
void destroy_queue(queue_t *q)
{
    //note, list_destroy never calls free(node->data)
    list_destroy_nodes(q->list);
    list_destroy(q->list);
    q->list = NULL;
    pthread_cond_destroy(&q->notfull);
    pthread_cond_destroy(&q->notempty);
    pthread_mutex_destroy(&q->lock);
}
Exemplo n.º 4
0
static int AST_destroy_list(list_t *data)
{
    lnode_t *n = NULL;

    for(n = list_first(data); n != NULL; n = list_next(data, n)) {
        AST_destroy_value((Value *)lnode_get(n));
    }

    list_destroy_nodes(data);
    list_destroy(data);
    return 0;
}
Exemplo n.º 5
0
/*
 * Destroy all nodes in list and free associated data pointer.
 */
void
list_destroy_auto (list_t * list)
{
	lnode_t *ln;

	ln = list_first (list);
	while (ln) {
		void *ptr =	( void * )lnode_get (ln);
		ns_free (ptr);
		ln = list_next (list, ln);
	}
	list_destroy_nodes (list);
	list_destroy (list);
}
Exemplo n.º 6
0
static void
free_plugins(list_t * plugin_list)
{
	lnode_t *p;
    if (plugin_list == NULL) {
        return;
    }
    if (list_isempty(plugin_list)) {
        return;
    }
    p = list_first(plugin_list);
    while (p) {
         WsManPlugin *plugin = (WsManPlugin *)p->list_data;
         plugin_free(plugin);
         p = list_next(plugin_list, p);
    }
    list_destroy_nodes(plugin_list);
    list_destroy(plugin_list);
}
Exemplo n.º 7
0
static void
scan_plugins_in_directory ( WsManListenerH *listener,
                            const char *dir_name)
{
	list_t *files = scan_files_in_dir ( dir_name, select_all_files);
	lnode_t *node = list_first(files);
    listener->plugins = list_create(LISTCOUNT_T_MAX);

    while (node != NULL)
    {
        const char* entry_name;
        int retv = -1;
        entry_name = (const char*) node->list_data;
        node = list_next(files, node);

        if ((NULL != entry_name) && strlen (entry_name) > strlen(PLUGIN_EXT)
                && (0 == strcmp (&entry_name[strlen(entry_name)-strlen(PLUGIN_EXT)], PLUGIN_EXT)))
        {
            char *plugin_path = u_strdup_printf ("%s/%s", dir_name, entry_name);
            WsManPlugin *plugin = plugin_new();

            if ((NULL != plugin) && (NULL != plugin_path))
            {
                if (load_plugin(plugin, plugin_path) == 0 )
                {
                    lnode_t *plg = lnode_create (plugin);
                    list_append (listener->plugins, plg);
                    retv = 0 ;
                }
            } else {
                error("Out of memory scanning for plugins.");
            }
            if (plugin_path)
            	u_free (plugin_path);
            if (retv != 0  && (NULL != plugin))
                plugin_free(plugin);
        }
    }
    list_destroy_nodes(files);
    list_destroy(files);
    return;
}
Exemplo n.º 8
0
static void
wsman_free_method_list(list_t *list) 
{
	lnode_t *node = list_first(list);

	debug("wsman_free_method_list:");
	while (node) {
		methodarglist_t *node_val = (methodarglist_t *)node->list_data;
		selector_entry *sentry = (selector_entry *)node_val->data;
		debug("freeing list entry key: %s", node_val->key);
		switch (sentry->type) {
			case 0: u_free(sentry->entry.text); break;
			case 1: u_free(sentry->entry.eprp); break;
		}
		u_free(sentry);
		u_free(node_val->key);
		u_free(node_val);
		node->list_data = NULL; // needed to prevent double free
		node = list_next(list, node);
	}
	list_destroy_nodes(list);
	list_destroy(list);
}
Exemplo n.º 9
0
char *test_routing_match() 
{
    RouteMap *routes = RouteMap_create(NULL);
    mu_assert(routes != NULL, "Failed to make the route map.");
    char *route_data0 = "route0";
    char *route_data1 = "route1";
    char *route_data2 = "route2";
    char *route_data3 = "route3";
    char *route_data4 = "route4";
    bstring route0 = bfromcstr("/");
    bstring route1 = bfromcstr("/users/([0-9]+)");
    bstring route2 = bfromcstr("/users");
    bstring route3 = bfromcstr("/users/people/([0-9]+)$");
    bstring route4 = bfromcstr("/cars-fast/([a-z]-)$");

    Route *route = NULL;

    RouteMap_insert(routes, route0, route_data0);
    RouteMap_insert(routes, route1, route_data1);
    RouteMap_insert(routes, route2, route_data2);
    RouteMap_insert(routes, route3, route_data3);
    RouteMap_insert(routes, route4, route_data4);

    bstring path1 = bfromcstr("/users/1234/testing");
    bstring path2 = bfromcstr("/users");
    bstring path3 = bfromcstr("/users/people/1234"); 
    bstring path4 = bfromcstr("/cars-fast/cadillac");
    bstring path5 = bfromcstr("/users/1234");
    bstring path6 = bfromcstr("/");
    bstring path7 = bfromcstr("/users/people/1234/notgonnawork");

    list_t *found = RouteMap_match(routes, path5);
    mu_assert(check_routing(found, route, 1, route_data1), "Pattern match route wrong.");
    list_destroy_nodes(found);
    list_destroy(found);

    found = RouteMap_match(routes, path1);
    mu_assert(check_routing(found, route, 1, route_data1), "Past end route wrong.");
    list_destroy_nodes(found);
    list_destroy(found);

    found = RouteMap_match(routes, path2);
    mu_assert(check_routing(found, route, 1, route_data2), "No pattern route wrong.");
    list_destroy_nodes(found);
    list_destroy(found);

    found = RouteMap_match(routes, path3);
    mu_assert(check_routing(found, route, 1, route_data3), "Wrong $ terminated route.");
    list_destroy_nodes(found);
    list_destroy(found);

    found = RouteMap_match(routes, path4);
    mu_assert(check_routing(found, route, 1, route_data4), "Wrong longer route match.");
    list_destroy_nodes(found);
    list_destroy(found);

    found = RouteMap_match(routes, path5);
    mu_assert(check_routing(found, route, 1, route_data1), "Wrong route for /users/1234");
    list_destroy_nodes(found);
    list_destroy(found);

    found = RouteMap_match(routes, path6);
    mu_assert(check_routing(found, route, 2, route_data0), "Should get root / route.");
    list_destroy_nodes(found);
    list_destroy(found);

    found = RouteMap_match(routes, path7);
    mu_assert(check_routing(found, route, 0, NULL), "Should not match past end");
    list_destroy_nodes(found);
    list_destroy(found);

    bdestroy(path1);
    bdestroy(path2);
    bdestroy(path3);
    bdestroy(path4);
    bdestroy(path5);

    RouteMap_destroy(routes);

    return NULL;
}
Exemplo n.º 10
0
int main_loop( CamConfig *ccfg, Socket *picture_sock, char *picture_mem  ){
  Socket *listen_socket;
  SockSet *readset = NULL, *writeset = NULL;
  list_t *client_sockets;
  lnode_t *node;
  int cfg_listen_port, highest_fd, picture_client_ready;
  int num_sclients, num_clients;
  ClientInfo *clientinfo, *clientinfo2;

  if( (client_sockets = list_create( -1 )) == NULL)
    return -1;

  cfg_listen_port = camconfig_query_def_int( ccfg, SEC_SOCKET, 
					     "listen_port",
					     CAMCONFIG_DEF_LISTEN_PORT );

  if( (readset = sockset_new()) == NULL ||
      (writeset = sockset_new()) == NULL )
  {
    camserv_log( MODNAME, "Error allocating memory for socksets!");
    if( readset ) sockset_dest( readset );
    if( writeset ) sockset_dest( writeset );
    list_destroy( client_sockets );
    return -1;
  }

  if((listen_socket = socket_serve_tcp( NULL, cfg_listen_port, 100 )) == NULL )
  {
      camserv_log( MODNAME, "Error setting up socket on port \"%d\".  Exiting",
	       cfg_listen_port  );
      list_destroy( client_sockets );
      sockset_dest( readset );
      sockset_dest( writeset );
      return -1;
  }

  highest_fd = MAX( socket_query_fd( listen_socket ), 
		    socket_query_fd( picture_sock ));
  clientinfo = clientinfo_new( listen_socket );
  clientinfo2 = clientinfo_new( picture_sock );

  if( !clientinfo || !clientinfo2 ||
      sockset_add_fd( readset, listen_socket, clientinfo ) == -1 ||
      sockset_add_fd( readset, picture_sock, clientinfo2 ) == -1 )
  {
    camserv_log( MODNAME, "Error adding initial sockets to sockset!");
    sockset_dest( readset );
    sockset_dest( writeset );
    if( clientinfo )  clientinfo_dest( clientinfo );
    if( clientinfo2 ) clientinfo_dest( clientinfo2 );
    list_destroy( client_sockets );
    return -1;
  }

  num_clients = 0;
  num_sclients = 0;
  picture_client_ready = 1;

  setup_signals();
  Abort = 0;
  while( !Abort ){
    int sel_res, i, nset_socks;
    void **set_socks;

    /* Only need to execute this if we have a streaming client */
    if( (num_sclients > 0) && picture_client_ready == 1 ){
      send( socket_query_fd( picture_sock ), "0", sizeof( "0" ), 0 );
      picture_client_ready = 0;
    }

    sockset_reset( readset );
    sockset_reset( writeset );

    sel_res = sockset_select( highest_fd + 1, readset, writeset, NULL );
    /* Service the event */
    if( sel_res == -1 ){
      camserv_log( MODNAME, "select() failure: %s", strerror( errno ));
      break;
    } else if( sel_res == 0 ){
      camserv_log( MODNAME, "Unexpected select() fall through!" );
      continue;
    } 

    /* Readable sockets */
    set_socks = sockset_query_socks( readset );
    nset_socks = sockset_query_nsocks( readset );
    for( i=0; i< nset_socks; i++ ){
      ClientInfo *new_cinfo;

      clientinfo = set_socks[ i ];

      if( clientinfo->socket == listen_socket ) {
	/* New client */
	if( (new_cinfo = accept_client( listen_socket )) == NULL )
	  continue;

	if( (node = lnode_create( new_cinfo )) == NULL ){
	  clientinfo_dest( new_cinfo );
	  continue;
	}

	if( sockset_add_fd( readset, new_cinfo->socket, new_cinfo ) == -1 ){
	  camserv_log( MODNAME, "Failed to add socket %d to socket read set!",
		   socket_query_fd( new_cinfo->socket ));
	  clientinfo_dest( new_cinfo );
	  lnode_destroy( node );
	  continue;
	}

	if( socket_query_fd( new_cinfo->socket ) > highest_fd )
	  highest_fd = socket_query_fd( new_cinfo->socket );

	list_append( client_sockets, node );
	num_clients++;
	/* Init resource limit for this client */
	new_cinfo->create_time = time( NULL );
	new_cinfo->bytes       = 0;
	new_cinfo->frames      = 0;
	new_cinfo->max_seconds = camconfig_query_def_int( ccfg, SEC_SOCKET,
							  "max_seconds", 0 );
	new_cinfo->max_bytes   = camconfig_query_def_int( ccfg, SEC_SOCKET,
							  "max_bytes", 0 );
	new_cinfo->max_frames  = camconfig_query_def_int( ccfg, SEC_SOCKET,
							  "max_frames", 0 );

	/* Send fresh request for a picture */
	send( socket_query_fd( picture_sock ), "0", sizeof( "0" ), 0 );
	picture_client_ready = 0;
	/* Put this read socket on hold until the picture comes back */
	sockset_hold( readset, new_cinfo->socket );	

      } else {
	char cmdbuf[ 1024 ];
	int readlen;

	clientinfo = set_socks[ i ];

	/* Regular joe client, set readable */
	if( (readlen = read( socket_query_fd( clientinfo->socket), cmdbuf, 
			     sizeof( cmdbuf ) - 1)) <= 0 )
	{
	  camserv_log( MODNAME, "Closing socket: %s", 
		       socket_query_remote_name( clientinfo->socket ));

	  if (clientinfo->client_type == CLIENT_T_BROWSER ||
	      clientinfo->client_type == CLIENT_T_PROXY) {
	      num_sclients--;
	  }
	  client_remove( client_sockets, clientinfo );
	  sockset_del_fd( readset, clientinfo->socket );
	  sockset_unhold_all( writeset );
	  sockset_del_fd( writeset, clientinfo->socket );
	  clientinfo_dest( clientinfo );
	  num_clients--;
	} else {
	  if( clientinfo->socket == picture_sock ) {
	    if( dispatch_pictaker( cmdbuf, picture_mem ) == -1 )
	      camserv_log( MODNAME, "Pictaker dispatch failure!");
	    sockset_unhold_all( writeset );
	    /* Release the read hold as the picture has now been taken */
	    sockset_unhold_all( readset );
	    picture_client_ready = 1;
	  } else {
	    /* Information from a regular client */
	    cmdbuf[ readlen ] = '\0';
	    if( clientinfo->client_type == CLIENT_T_UNINIT ) {
	      char *preamble;
	      int pre_size;

	      /* Figure out what type of client we have */
	      if( !strncmp( cmdbuf, "GET", 3 )) {
		if( strstr( cmdbuf, "/singleframe" )) {
		  clientinfo->client_type = CLIENT_T_SINGLE;
		} else {
		  clientinfo->client_type = CLIENT_T_BROWSER;
		  num_sclients++;
	        }
	      } else if( !strncmp( cmdbuf, "PROXY", 5 )) {
		clientinfo->client_type = CLIENT_T_PROXY;
		/* Here we are in the same state as being done writing a pic */
		clientinfo->state       = CINFO_STATE_PICTURE;
		num_sclients++;	
		databuf_buf_set( clientinfo->writebuf, NULL, 0 ); 
	      } else 
		clientinfo->client_type = CLIENT_T_BROWSER;

	      if( clientinfo->client_type != CLIENT_T_PROXY ) {
		/* Send the initial preamble.  Only now we can decide which 
		   type of preamble to send (single vs. multi-part) */
		if( clientinfo->client_type == CLIENT_T_SINGLE )
		  preamble = get_single_preamble_text( &pre_size );
		else
		  preamble = get_multi_preamble_text( &pre_size );
		databuf_buf_set( clientinfo->writebuf, preamble, pre_size );
	      }

	      if( sockset_add_fd( writeset, clientinfo->socket, 
				  clientinfo ) == -1 )
	      {
  		  camserv_log( MODNAME, "Failed to add socket %d to write set!",
			   socket_query_fd( clientinfo->socket ));
	      }
	  } 
	} 
      } 
    } 
  } 

    if( set_socks != NULL ) free( set_socks );

    /* Writable sockets */
    set_socks = sockset_query_socks( writeset );
    nset_socks = sockset_query_nsocks( writeset );
    for( i=0; i< nset_socks; i++ ){
      ClientInfo *cinfo;

      cinfo = set_socks[ i ];
      if( cinfo->client_type == CLIENT_T_BROWSER ||
	  cinfo->client_type == CLIENT_T_SINGLE ) 
      {
	int result;

	if( (result = write_regular_client( cinfo, writeset )) != 0 ){
	  /* result: 1=close requested, -1=error detected */
	  if( result == -1 )
	    camserv_log( MODNAME, "Databuf write error on socket: %s\n",
			 socket_query_remote_name( cinfo->socket ));
	  
	  if (cinfo->client_type == CLIENT_T_BROWSER) {
	      num_sclients--;
	  }

	  client_remove( client_sockets, cinfo );
	  sockset_del_fd( readset, cinfo->socket );
	  sockset_del_fd( writeset, cinfo->socket );
	  clientinfo_dest( cinfo );
	  num_clients--;
	}
      } else {
	if( write_proxy_client( cinfo, writeset ) == -1 ){
	  camserv_log( MODNAME, "Databuf write error on socket: %d",
		   socket_query_fd( cinfo->socket ));

	  /* Should be proxy, but better check */
	  if (cinfo->client_type == CLIENT_T_PROXY) {
	      num_sclients--;
	  }
	  client_remove( client_sockets, cinfo );
	  sockset_del_fd( readset, cinfo->socket );
	  sockset_del_fd( writeset, cinfo->socket );
	  clientinfo_dest( cinfo );
	  num_clients--;
	}
      }
    }
    if( set_socks != NULL ) free( set_socks );
  }

  camserv_log( MODNAME, "Aborting.");
  sockset_dest( readset );
  sockset_dest( writeset );

  for( node = list_first( client_sockets) ; node; 
       node=list_next( client_sockets, node ))
  {
    clientinfo_dest( node->data );
  }

  /* Tell the picture taker to get out!  Get out! */
  camserv_log( MODNAME, "Closing picture taker");
  send( socket_query_fd( picture_sock ), "9", sizeof( "9" ), 0 );
  sleep( 3 );
  camserv_log( MODNAME, "done\n");

  list_destroy_nodes( client_sockets );
  list_destroy( client_sockets );
  socket_dest( listen_socket );
  return 0;
}
Exemplo n.º 11
0
char *test_routing_match() 
{
    RouteMap *routes = RouteMap_create(NULL);
    mu_assert(routes != NULL, "Failed to make the route map.");
    char *route_data1 = "route1";
    char *route_data2 = "route2";
    char *route_data3 = "route3";
    char *route_data4 = "route4";
    bstring route1 = bfromcstr("/users/([0-9]+)");
    bstring route2 = bfromcstr("/users");
    bstring route3 = bfromcstr("/users/people/([0-9]+))$");
    bstring route4 = bfromcstr("/cars/([a-z]-)$");

    Route *route = NULL;

    RouteMap_insert(routes, route1, route_data1);
    RouteMap_insert(routes, route2, route_data2);
    RouteMap_insert(routes, route3, route_data4);
    RouteMap_insert(routes, route4, route_data3);

    bstring path1 = bfromcstr("/users/1234/testing");
    bstring path2 = bfromcstr("/users");
    bstring path3 = bfromcstr("/cars/cadillac");
    bstring path4 = bfromcstr("/users/people/1234"); 
    bstring path5 = bfromcstr("/users/1234");

    list_t *found = RouteMap_match(routes, path5);
    mu_assert(check_routing(found, route, 1, route_data1), "Pattern match route wrong.");
    list_destroy_nodes(found);
    list_destroy(found);

    // must make sure that match is partial unless $ explicitly
    found = RouteMap_match(routes, path1);
    mu_assert(check_routing(found, route, 1, route_data1), "Past end route wrong.");
    list_destroy_nodes(found);
    list_destroy(found);

    found = RouteMap_match(routes, path2);
    mu_assert(check_routing(found, route, 1, route_data2), "No pattern route wrong.");
    list_destroy_nodes(found);
    list_destroy(found);

    found = RouteMap_match(routes, path3);
    mu_assert(check_routing(found, route, 1, route_data3), "Wrong $ terminated route.");
    list_destroy_nodes(found);
    list_destroy(found);

    found = RouteMap_match(routes, path4);
    mu_assert(check_routing(found, route, 1, route_data4), "Wrong longer route match.");
    list_destroy_nodes(found);
    list_destroy(found);

    bdestroy(path1);
    bdestroy(path2);
    bdestroy(path3);
    bdestroy(path4);
    bdestroy(path5);

    RouteMap_destroy(routes);

    return NULL;
}
Exemplo n.º 12
0
void termSetClosedFlag(TERM *t) {
	list_t *fvars = termFreeVars(t);
	list_destroy_nodes(fvars);
	list_destroy(fvars);
}