static void fst_giftcb_destroy (Protocol *proto)
{
	FST_DBG ("shutting down");

	if (!FST_PLUGIN)
		return;

	/* free push list */
	fst_pushlist_free (FST_PLUGIN->pushlist);

	/* shutdown http server */
	fst_http_server_free (FST_PLUGIN->server);

	/* free udp discovery */
	fst_udp_discover_free (FST_PLUGIN->discover);

	/* put currently used supernode at the front of the node cache */
	if (FST_PLUGIN->session && FST_PLUGIN->session->state == SessEstablished)
	{
		fst_nodecache_move (FST_PLUGIN->nodecache, 
		                    FST_PLUGIN->session->node,
		                    NodeInsertFront);

		FST_DBG_2 ("added current supernode %s:%d back into node cache",
		           FST_PLUGIN->session->node->host,
		           FST_PLUGIN->session->node->port);
	}

	/* free session */
	fst_session_free (FST_PLUGIN->session);
	FST_PLUGIN->sessions = list_foreach_remove (FST_PLUGIN->sessions,
	                                            (ListForeachFunc)free_additional_session,
	                                            NULL);

	/* free peer dataset */
	dataset_clear (FST_PLUGIN->peers);

	/* free stats */
	fst_stats_free (FST_PLUGIN->stats);

	/* free searches */
	fst_searchlist_free (FST_PLUGIN->searches);

	/* free list of banned ips */
	fst_ipset_free (FST_PLUGIN->banlist);

	/* save and free nodes */
	save_nodes ();
	fst_nodecache_free (FST_PLUGIN->nodecache);

	/* free cached user name */
	free (FST_PLUGIN->username);

	/* free config */
	config_free (FST_PLUGIN->conf);

	timer_remove (FST_PLUGIN->retry_timer);

#if 0
	/* remove algo hack */
	hash_algo_unregister (proto, FST_KZHASH_NAME);
	hash_algo_unregister (proto, FST_FTHASH_NAME);
#endif

	free (FST_PLUGIN);
}
Exemple #2
0
int
cmd_input_program (struct lexer *lexer, struct dataset *ds)
{
  struct input_program_pgm *inp;
  bool saw_END_CASE = false;

  dataset_clear (ds);
  if (!lex_match (lexer, T_ENDCMD))
    return lex_end_of_command (lexer);

  inp = xmalloc (sizeof *inp);
  inp->trns_chain = NULL;
  inp->init = NULL;
  inp->proto = NULL;

  inside_input_program = true;
  while (!lex_match_phrase (lexer, "END INPUT PROGRAM"))
    {
      enum cmd_result result;

      result = cmd_parse_in_state (lexer, ds, CMD_STATE_INPUT_PROGRAM);
      if (result == CMD_END_CASE)
        {
          emit_END_CASE (ds, inp);
          saw_END_CASE = true;
        }
      else if (cmd_result_is_failure (result) && result != CMD_FAILURE)
        {
          if (result == CMD_EOF)
            msg (SE, _("Unexpected end-of-file within INPUT PROGRAM."));
          inside_input_program = false;
          dataset_clear (ds);
          destroy_input_program (inp);
          return result;
        }
    }
  if (!saw_END_CASE)
    emit_END_CASE (ds, inp);
  inside_input_program = false;

  if (dict_get_next_value_idx (dataset_dict (ds)) == 0)
    {
      msg (SE, _("Input program did not create any variables."));
      dataset_clear (ds);
      destroy_input_program (inp);
      return CMD_FAILURE;
    }

  inp->trns_chain = proc_capture_transformations (ds);
  trns_chain_finalize (inp->trns_chain);

  inp->restart = TRNS_CONTINUE;

  /* Figure out how to initialize each input case. */
  inp->init = caseinit_create ();
  caseinit_mark_for_init (inp->init, dataset_dict (ds));
  inp->proto = caseproto_ref (dict_get_proto (dataset_dict (ds)));

  dataset_set_source (
    ds, casereader_create_sequential (NULL, inp->proto, CASENUMBER_MAX,
                                      &input_program_casereader_class, inp));

  return CMD_SUCCESS;
}