/* 
 * $Id: irrd_prototypes.h,v 1.27 1999/10/18 06:30:17 labovit Exp $
 * originally Id: irrd_prototypes.h,v 1.46 1998/08/03 17:29:08 gerald Exp 
 */

char *my_fgets (irr_database_t *db, FILE *fd);


/* update */
int add_irr_object (irr_database_t *database, irr_object_t *irr_object);
int delete_irr_object (irr_database_t *database, irr_object_t *irr_object,
                       u_long *db_offset);
void mark_deleted_irr_object (irr_database_t *database, u_long offset);


/* configuration */
int config_irr_database_clean (uii_connection_t *uii, char *name, int seconds);
int config_irr_database_no_clean (uii_connection_t *uii, char *name);
int config_tmp_directory (uii_connection_t *uii, char *dir);
int config_irr_database_export (uii_connection_t *uii, char *name, int interval, int n, char *filename);
int config_export_directory (uii_connection_t *uii, char *dir);
int config_debug_submission_syslog (uii_connection_t *uii);
int config_debug_submission_maxsize (uii_connection_t *uii, int size);
int config_debug_submission_verbose (uii_connection_t *uii);
int config_debug_server_verbose (uii_connection_t *uii);
int config_debug_server_file (uii_connection_t *uii, char *filename);
int no_config_debug_server (uii_connection_t *uii);
int config_debug_submission_file (uii_connection_t *uii, char *filename);
int no_config_debug_submission (uii_connection_t *uii);
int config_debug_server_size (uii_connection_t *uii, int bytes);
void get_config_irr_port ();
int config_override (uii_connection_t *uii, char *override);
int config_pgpdir (uii_connection_t *uii, char *pgpdir);
int config_irr_host (uii_connection_t *uii, char *host);
int config_irr_directory (uii_connection_t *uii, char *directory);
int config_irr_database_mirror (uii_connection_t *uii, char *name,
				char *host, int port);
int config_dbadmin (uii_connection_t *uii, char *email);
int config_debug_server_syslog (uii_connection_t *uii);
int config_irr_database (uii_connection_t *uii, char *name);
int config_irr_database_authoritative (uii_connection_t *uii, char *name);
int no_config_irr_database_authoritative (uii_connection_t *uii, char *name);
int no_config_irr_database (uii_connection_t *uii, char *name);
int config_irr_max_con (uii_connection_t *uii, int max);
void config_create_default ();
void get_config_irr_directory ();
int config_irr_database_access_write (uii_connection_t *uii, char *name, int num);
int config_irr_database_mirror_access (uii_connection_t *uii, char *name, int num);
int config_irr_database_access (uii_connection_t *uii, char *name, int num);
int no_config_irr_dbclean (uii_connection_t *uii);
int config_irr_dbclean (uii_connection_t *uii);
int invoke_syntax_checker (irr_connection_t *irr);
int config_irr_database_filter (uii_connection_t *uii, char *name, char *object);
int config_db_ignore (uii_connection_t *uii, char *str);
int config_response_footer (uii_connection_t *uii, char *line);

/* uii */
int uii_delete_route (uii_connection_t *uii, char *database, prefix_t *prefix, int as);
void config_irr_mirror_interval (uii_connection_t *uii, int interval);
void uii_irr_reload (uii_connection_t *uii, char *name);
void uii_irr_mirror (uii_connection_t *uii, char *name, int serial);
void uii_irr_mirror_last (uii_connection_t *uii, char *name);
void uii_irr_mirror_serial (uii_connection_t *uii, char *name, int serial);
void uii_set_serial (uii_connection_t *uii, char *name, int serial);
void show_database (uii_connection_t *uii);
void uii_show_ip (uii_connection_t *uii, prefix_t *prefix, int num, char *lessmore);
void uii_irr_sync (uii_connection_t *uii, char *name);
void config_irr_port (uii_connection_t *uii, int port);
void uii_export_database (uii_connection_t *uii, char *name);
int uii_read_update_file (uii_connection_t *uii, char *file, char *name);

/* telnet */
int irr_add_answer_fast (irr_connection_t *irr, char *buf);
void irr_send_answer (irr_connection_t * irr);
int irr_add_answer (irr_connection_t *irr, char *format, ...);
void irr_write_error (irr_connection_t *irr);
void irr_send_okay (irr_connection_t * irr);
void irr_send_error (irr_connection_t * irr, char *);
void irr_build_answer (irr_connection_t *irr, FILE *fd, enum IRR_OBJECTS type,
		       u_long offset, u_long len, char * blob, enum DB_SYNTAX syntax);
void send_dbobjs_answer (irr_connection_t * irr, enum INDEX_T index,
			 enum ANSWER_T answer_type, int mode);
void irr_unlock (irr_database_t *database);
int listen_telnet (u_short port);
int irr_send_data (irr_connection_t * irr,...);
int irr_destroy_connection (irr_connection_t * connection);
void irr_build_key_answer (irr_connection_t *irr, FILE *fd, char *dbname,
                           enum IRR_OBJECTS type, u_long offset,
                           u_short origin);
void show_connections (uii_connection_t *uii);
void irr_write  (irr_connection_t *irr, int fd, char *buf, int len);

/* database */
void irr_load_data ();
int irr_copy_file (char *infile, char *outfile, int add_eof_flag);
void database_clear (irr_database_t *db);
enum DB_SYNTAX get_database_syntax (FILE *fp);
int irr_reload_database(char *names, uii_connection_t *uii);
int irr_database_sync (irr_database_t *database);
int irr_database_export (irr_database_t *database);
void irr_export_timer (mtimer_t *timer, irr_database_t *db);

/* journaling */
void journal_maybe_rollover (irr_database_t *database);
void journal_log_serial_number (irr_database_t *database);
void journal_irr_update (irr_database_t *db, irr_object_t *object,
                         int mode, u_long db_offset, int del_obj);
int find_oldest_serial (char *dbname, int journal_ext, u_long *oldestserial);
int get_current_serial (char *dbname, u_long *currserial);
void make_journal_name (char * dbname, int journal_ext, char * journal_name);

/* util */
void nice_time (long seconds, char *buf);
void IRRD_Delete_Node (radix_node_t *node);
long copy_irr_object (FILE *src_fd, long offset, irr_database_t *database,
		      u_long obj_length);
void Delete_RT_Object (irr_route_object_t *attr);
void irr_unlock_all (irr_connection_t *irr);
void irr_lock_all (irr_connection_t *irr);
int irr_comp (char *s1, char *s2);
void irr_unlock (irr_database_t *database);
void irr_lock (irr_database_t *database);
irr_database_t *find_database (char *name);
irr_object_t *New_IRR_Object (char *buffer, u_long position, u_long mode);
void init_key (char *buf, int curr_f, irr_object_t *object, enum DB_SYNTAX syntax);
void Delete_IRR_Object (irr_object_t *object);
void Delete_Ref_keys (reference_key_t *ref_item);
void lookup_object_references (irr_connection_t *irr);
void lookup_route_exact (irr_connection_t *irr, char *key);
int get_prefix_from_disk (FILE *fd, u_long offset, char *buffer);
int convert_to_lu (char *strval, u_long *uval);
irr_hash_string_t *new_irr_hash_string (char *str);
void delete_irr_hash_string (irr_hash_string_t *str);
int parse_ripe_flags (irr_connection_t *irr, char **cp);
int ripe_set_source (irr_connection_t *irr, char **cp);
int ripe_obj_type (irr_connection_t *irr, char **cp);
radix_str_t *new_radix_str (radix_node_t *node);
void delete_radix_str (radix_str_t *str);
char *prefix_tobitstring (prefix_t *prefix);

/* mirroring */
void irr_mirror_timer (mtimer_t *timer, irr_database_t *db);
void irr_sync_timer (mtimer_t *timer, irr_database_t *db);
int irr_service_mirror_request (irr_connection_t *irr, char *command);
int request_mirror (irr_database_t *db, uii_connection_t *uii, int last);

/* commands.c */
void irr_process_command (irr_connection_t * irr);

/* scan */
char *scan_irr_file (irr_database_t *database, char *extension, 
		   int update_flag, FILE *fd);
void *scan_irr_file_main (FILE *fd, irr_database_t *database,
                                  int update_flag, enum SCAN_T scan_scope);
void write_irr_serial (irr_database_t *database);
void write_irr_serial_export (u_long serial, irr_database_t *database);
int scan_irr_serial (irr_database_t *database);
/*
void pick_off_secondary_fields (char *buffer, int curr_f, int state, 
				irr_object_t *irr_object);
				*/
int get_state (char *buf, char *cp, int state);
int pick_off_mirror_hdr (FILE *fd, char *buf, int buf_size, int state, 
			 u_long *mode, u_long *position, u_long *offset,
			 irr_database_t *db);
int get_curr_f (int db_syntax, char *buf, int state, int curr_f);
/*
void add_field_items (char *buf, int curr_f, int state, 
		      int db_syntax, LINKED_LIST **ll);
		      */

/* RPSL */
void irr_as_set_expand (irr_connection_t *irr, char *name);

/* indicies */
int irr_database_find_matches (irr_connection_t *irr, char *key, 
				   int p_or_s,
				   int match_behavior,
				   enum IRR_OBJECTS type,
                                   u_long *ret_offset, u_long *ret_len); 
int irr_database_store (irr_database_t *database, char *key, u_short p_or_s,
			enum IRR_OBJECTS type, u_long offset, u_long len);
int irr_database_remove (irr_database_t *database, char *key, u_short p_or_s,
			 enum IRR_OBJECTS type, u_long offset, u_long len);
int irr_database_load_object_seek (irr_database_t *database, char *key, 
				   enum IRR_OBJECTS type,
				   irr_object_t *irr_object);
void make_spec_key (char *new_key, char *maint, char *set_name);
void make_gas_key (char *gas_key, char *origin);
void make_comm_key (char *new_key, char *community);
void make_setobj_key (char *new_key, char *obj_name);
void add_comm_list_answer (irr_database_t *db, char *prefix,
                           LINKED_LIST *ll_comm, int withdrawn,
			   int mode, enum SPEC_KEYS id);
int irr_hash_destroy (hash_item_t *hash_item);
hash_item_t *irr_database_fetch (irr_database_t *database, char *key);
void store_hash_spec (irr_database_t *database, hash_spec_t *hash_item);
hash_spec_t *fetch_hash_spec (irr_database_t *database, char *key,
                              enum FETCH_T mode); 
int find_object_offset_len (irr_database_t *db, char *key,
                            enum IRR_OBJECTS type, u_long *offset, u_long *len);
void Delete_hash_spec (hash_spec_t *hash_item); 
void commit_spec_hash (irr_database_t *db);
int memory_hash_spec_remove (irr_database_t *db, char *key, enum SPEC_KEYS id,
                             char *blob_item); 
int memory_hash_spec_store (irr_database_t *db, char *key, enum SPEC_KEYS id,
                            LINKED_LIST *ll_1, LINKED_LIST *ll_2,
                            char *blob_item);

/* route */
void route_search_more_specific (irr_connection_t *irr, 
				 irr_database_t *database, prefix_t *prefix);
void add_irr_route (irr_database_t *database, char *prefix_key, 
		    irr_object_t *object);
int delete_irr_route (irr_database_t *database, char *key, irr_object_t *object);
int seek_route_object (irr_database_t *database, char *key, 
		       u_short origin, u_long *offset, u_long *len, int ignore_wd);
radix_node_t *route_search_exact (irr_database_t *database, radix_tree_t *radix, prefix_t *prefix);
radix_node_t *route_search_best (irr_database_t *database, radix_tree_t *radix, prefix_t *prefix);


#ifdef USE_GDBM
/* dbm support prototypes */
GDBM_FILE irr_initialize_dbm_file (char *name);
int irr_dbm_store (GDBM_FILE db, u_char *key, u_char *value, int len, 
                   char *name);
int irr_dbm_delete (GDBM_FILE db, char *key, char *name);
hash_item_t *irr_dbm_fetch (GDBM_FILE db, char *key);
int irr_open_dbm_file (irr_database_t *database);
#endif

#ifdef USE_DB1
DB *irr_initialize_dbm_file (char *name);
int irr_dbm_delete (DB *db, char *key, char *name);
hash_item_t *irr_dbm_fetch (DB *db, char *key);
int irr_dbm_store (DB *db, u_char *key, u_char *value, int len,
                   char *name);
#endif
int dbm_slow (irr_database_t *database);
int dbm_fast (irr_database_t *database);


/* other */
void convert_toupper(char *p);
