Added documentation to some functions;
Fixed possible memory leak.
This commit is contained in:
parent
fda15157c2
commit
0c32025590
|
@ -24,8 +24,20 @@
|
||||||
|
|
||||||
typedef struct dbConnection dbConnection;
|
typedef struct dbConnection dbConnection;
|
||||||
|
|
||||||
int db_open (dbConnection **, char *cStr);
|
/**
|
||||||
int db_close (dbConnection *);
|
* Opens a database connection.
|
||||||
|
* @param pdb Pointer to database instance.
|
||||||
|
* @param cStr Connection string for the active driver.
|
||||||
|
* @return 0 on success; otherwise non-zero.
|
||||||
|
*/
|
||||||
|
int db_open (dbConnection **pdb, char *cStr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes the database connection.
|
||||||
|
* @param db Database instance.
|
||||||
|
* @return 0 on success; otherwise non-zero.
|
||||||
|
*/
|
||||||
|
int db_close (dbConnection *db);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t *peer_id;
|
uint8_t *peer_id;
|
||||||
|
@ -37,22 +49,50 @@ typedef struct {
|
||||||
uint16_t port;
|
uint16_t port;
|
||||||
} db_peerEntry;
|
} db_peerEntry;
|
||||||
|
|
||||||
// adds a peer to the torrent's list.
|
/**
|
||||||
int db_add_peer (dbConnection *, uint8_t [20], db_peerEntry*);
|
* Adds/Updates the list of peers.
|
||||||
|
* @param db The database's instance.
|
||||||
/*
|
* @param hash The info_hash of the torrent.
|
||||||
* lst: pointer to an array whose maximum size is passed to sZ.
|
* @param pE Peer's information.
|
||||||
* sZ returns the amount of peers returned.
|
* @return 0 on success; otherwise non-zero.
|
||||||
*/
|
*/
|
||||||
int db_load_peers (dbConnection *, uint8_t [20], db_peerEntry *lst, int *sZ);
|
int db_add_peer (dbConnection *db, uint8_t hash[20], db_peerEntry *pE);
|
||||||
|
|
||||||
int db_get_stats (dbConnection *, uint8_t [20], int32_t *seeders, int32_t *leechers, int32_t *completed);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates Stats, Removes expired data.
|
* Loads peers for the requested torrent.
|
||||||
|
* @param db Database instance.
|
||||||
|
* @param hash The info_hash of the requested torrent.
|
||||||
|
* @param lst A allocated array to store results in.
|
||||||
|
* @param sZ in: The maximum amount of entries to load. out: Amount of loaded entries.
|
||||||
|
* @return 0 on success; otherwise non-zero.
|
||||||
*/
|
*/
|
||||||
int db_cleanup (dbConnection *);
|
int db_load_peers (dbConnection *db, uint8_t hash[20], db_peerEntry *lst, int *sZ);
|
||||||
|
|
||||||
int db_remove_peer (dbConnection *, uint8_t hash [20], db_peerEntry *);
|
/**
|
||||||
|
* Gets stats for the requested torrent.
|
||||||
|
* @param db The Database connection
|
||||||
|
* @param hash info_hash of the torrent.
|
||||||
|
* @param seeders Returns the Seeders for the requested torrent.
|
||||||
|
* @param leechers Returns the Leechers for the requested torrent.
|
||||||
|
* @param completed Returns the count of completed downloaded reported.
|
||||||
|
* @return 0 on success, otherwise non-zero.
|
||||||
|
*/
|
||||||
|
int db_get_stats (dbConnection *db, uint8_t hash[20], int32_t *seeders, int32_t *leechers, int32_t *completed);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maintenance routine, Calculates stats & releases space from old entries.
|
||||||
|
* @param db The database connection.
|
||||||
|
* @return 0 on success; otherwise non-zero.
|
||||||
|
*/
|
||||||
|
int db_cleanup (dbConnection *db);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a peer from the database.
|
||||||
|
* @param db Database connection
|
||||||
|
* @param hash info_hash of the torrent.
|
||||||
|
* @param pE The peer's information.
|
||||||
|
* @return 0 on success; otherwise non-zero.
|
||||||
|
*/
|
||||||
|
int db_remove_peer (dbConnection *db, uint8_t hash [20], db_peerEntry *pE);
|
||||||
|
|
||||||
#endif /* DATABASE_H_ */
|
#endif /* DATABASE_H_ */
|
||||||
|
|
|
@ -21,7 +21,6 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "multiplatform.h"
|
#include "multiplatform.h"
|
||||||
|
|
||||||
#include "udpTracker.h"
|
#include "udpTracker.h"
|
||||||
#include "tools.h"
|
#include "tools.h"
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
@ -73,14 +72,16 @@ int main(int argc, char *argv[])
|
||||||
printf ("Unknown Error\n");
|
printf ("Unknown Error\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return 1;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Press Any key to exit.\n");
|
printf("Press Any key to exit.\n");
|
||||||
|
|
||||||
getchar ();
|
getchar ();
|
||||||
|
|
||||||
|
cleanup:
|
||||||
printf("\nGoodbye.\n");
|
printf("\nGoodbye.\n");
|
||||||
|
|
||||||
UDPTracker_destroy(&usi);
|
UDPTracker_destroy(&usi);
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
|
|
|
@ -40,14 +40,48 @@ typedef struct {
|
||||||
char *buffer;
|
char *buffer;
|
||||||
} Settings;
|
} Settings;
|
||||||
|
|
||||||
void settings_init (Settings *, char *filename);
|
/**
|
||||||
|
* Initializes the settings type.
|
||||||
|
* @param s Pointer to settings to initialize.
|
||||||
|
* @param filename the settings filename.
|
||||||
|
*/
|
||||||
|
void settings_init (Settings *s, char *filename);
|
||||||
|
|
||||||
int settings_load (Settings *);
|
/**
|
||||||
|
* Loads settings from file
|
||||||
|
* @param s pointer to settings type
|
||||||
|
* @return 0 on success, otherwise non-zero.
|
||||||
|
*/
|
||||||
|
int settings_load (Settings *s);
|
||||||
|
|
||||||
int settings_save (Settings *);
|
/**
|
||||||
|
* Saves settings to file.
|
||||||
|
* @param s Pointer to settings.
|
||||||
|
* @return 0 on success; otherwise non-zero.
|
||||||
|
*/
|
||||||
|
int settings_save (Settings *s);
|
||||||
|
|
||||||
void settings_destroy (Settings *);
|
/**
|
||||||
|
* Destroys the settings "object"
|
||||||
|
* @param s Pointer to settings.
|
||||||
|
*/
|
||||||
|
void settings_destroy (Settings *s);
|
||||||
|
|
||||||
char* settings_get (Settings *, char *class, char *name);
|
/**
|
||||||
|
* Gets a setting from a Settings type.
|
||||||
|
* @param s Pointer to a setting type.
|
||||||
|
* @param class The class of the requested setting.
|
||||||
|
* @param name The name of the requested setting.
|
||||||
|
* @return The value for the requested setting, NULL if not available.
|
||||||
|
*/
|
||||||
|
char* settings_get (Settings *s, char *class, char *name);
|
||||||
|
|
||||||
int settings_set (Settings *, char *class, char *name, char *value);
|
/**
|
||||||
|
* Sets a setting in a settings type.
|
||||||
|
* @param s Pointer to settings type.
|
||||||
|
* @param class The class of the setting.
|
||||||
|
* @param name The name of the setting.
|
||||||
|
* @param value The value to set for the setting.
|
||||||
|
* @return 0 on success, otherwise non-zero.
|
||||||
|
*/
|
||||||
|
int settings_set (Settings *s, char *class, char *name, char *value);
|
||||||
|
|
|
@ -112,9 +112,25 @@ typedef struct udp_scrape_request ScrapeRequest;
|
||||||
typedef struct udp_scrape_response ScrapeResponse;
|
typedef struct udp_scrape_response ScrapeResponse;
|
||||||
typedef struct udp_error_response ErrorResponse;
|
typedef struct udp_error_response ErrorResponse;
|
||||||
|
|
||||||
void UDPTracker_init (udpServerInstance *, uint16_t port, uint8_t threads);
|
/**
|
||||||
void UDPTracker_destroy (udpServerInstance *);
|
* Initializes the UDP Tracker.
|
||||||
|
* @param usi The Instancfe to initialize.
|
||||||
|
* @param port The port to bind the server to
|
||||||
|
* @param threads Amount of threads to start the server with.
|
||||||
|
*/
|
||||||
|
void UDPTracker_init (udpServerInstance *usi, uint16_t port, uint8_t threads);
|
||||||
|
|
||||||
int UDPTracker_start (udpServerInstance *);
|
/**
|
||||||
|
* Destroys resources that were created by UDPTracker_init.
|
||||||
|
* @param usi Instance to destroy.
|
||||||
|
*/
|
||||||
|
void UDPTracker_destroy (udpServerInstance *usi);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts the Initialized instance.
|
||||||
|
* @param usi Instance to start
|
||||||
|
* @return 0 on success, otherwise non-zero.
|
||||||
|
*/
|
||||||
|
int UDPTracker_start (udpServerInstance *usi);
|
||||||
|
|
||||||
#endif /* UDPTRACKER_H_ */
|
#endif /* UDPTRACKER_H_ */
|
||||||
|
|
Loading…
Reference in a new issue