/************************************************************************************ ** Database API dbCon_h.h ** ** ** ** definitions/declarations for database routines ** ** ** ** Purpose : to provide database access and functionality for ** ** the URL Statistic Server ** ************************************************************************************* */ //#include #include // provides strcat() #include // provides printf() #include // print out positioning #include #include //#include "msql/include/msql.h" //access to msql Niels Brock using namespace std; #define HOST NULL // localhost #define DB "urlDB" // database name #define USR "171256NN" // username #define PSW "171256NN" // password #define MAX 300 int sock; // socket (public) /****************************************************************************************************/ /* function 1 : returns the contents of html for the specified url precondition : urlDB running on localhost, url exists. postcondition : returns char* if url exixts otherwise returns null */ char* getHtml(char *url); /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ /****************************************************************************************************/ /* function 2 : runs a query, tests if query is valid precondition : database exists, on localhost, with selected user and password, takes a query as parameter. postcondition : runs query returns sucess or failure */ int runQuery(char *myQuery); /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ /****************************************************************************************************/ /* function 3 : creates and checks connection to host and checks database precondition : database exists, on localhost, with selected user and password postcondition : connection success or failure */ void myDBconnect(); /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ /****************************************************************************************************/ /* function 5 : closes a connection to selected database precondition : a connection is opened postcondition : connection closed */ void myDBconClose(); /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ /****************************************************************************************************/ /* function 6 : checks to see if url exixts in dB, if not, inserts params precondition : validated url not found in tbl_url postcondition : inserted url */ void insert_Url(char* url, int cache, char* expires); /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-/ /****************************************************************************************************/ /* function 7 :file status checks whether a file is in or out of top 10 and updates the html table accordingly precondition :accepts url in or out of top 10 postcondition :updated html table */ void checkFileStatus(char* url); /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-/ /****************************************************************************************************/ /* function 8 : add one to the selected url precondition : a valid url that exists in table postcondition : updated table, setting antal = antal +1 */ void updateUrlAmount(char* url); /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-/ /****************************************************************************************************/ /* function 9 : checks where cache period has expired precondition : a valid url that exists in table postcondition : updated table, setting filename_id = 0 if url cache date is expired. */ void checkUrlExpires(); /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-/ /****************************************************************************************************/ /* function 10 : searches for a url in tbl_url returns success or failure. precondition : takes a url as a parameter postcondition : returns -1 for nothing | >0 is the number of rows */ int findUrl(char* url); /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ /*****************************************************************************************************/ /* function 11 : printTopTen() precondition : none postcondition : prints the top ten rows measured on the amounts of 'hits'. */ void printTopTen(); /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ /*****************************************************************************************************/ /* function 11 : printStat prints the complete ordered url table precondition : none postcondition : prints the all rows measured on the amounts of 'hits'. */ void printStat(); /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ //#endif