Changeset - 479a5c9e3a02
[Not reviewed]
default
0 5 0
Nathan Brink (binki) - 15 years ago 2010-06-07 20:47:38
ohnobinki@ohnopublishing.net
Move mysql connectino configuration to distrendaemon.conf
5 files changed with 52 insertions and 15 deletions:
0 comments (0 inline, 0 general)
etc/distrendaemon.conf.in
Show inline comments
 
@@ -6,6 +6,11 @@ daemon
 
  datadir = "@LOCALSTATEDIR@/@PACKAGE@"
 
  render_types = {"povray", "blender", "inkscape", "imagemagick", "dcraw"}
 

	
 
  mysql_user = "distren"
 
  mysql_pass = "HwLxuBqTvJ6J7FWj"
 
  mysql_host = "localhost"
 
  mysql_database = "distren"
 

	
 
  listen {
 
         type = "unix"
 
         path = "@RUNSTATEDIR@/@PACKAGE@d.sock"
src/server/distrend.c
Show inline comments
 
@@ -83,6 +83,7 @@ struct general_info
 
int distrend_do();
 
int distrend_do_config(int argc, char *argv[], struct distrend_config **config);
 
int distrend_config_free(struct distrend_config *config);
 
int distrend_handle_request(struct distren_request *req, void *reqdata, struct general_info *geninfo);
 

	
 
/* **************XML Functions**************** */
 
void update_general_info(struct general_info *geninfo);
 
@@ -136,7 +137,11 @@ int main(int argc, char *argv[])
 

	
 
  /** MySQL Connection */
 
  fprintf(stderr,"Connecting to mysql...\n");
 
  if(mysqlConnect(&general_info.conn))
 
  if(mysqlConnect(&general_info.conn,
 
		  general_info.config->mysql_user,
 
		  general_info.config->mysql_host,
 
		  general_info.config->mysql_pass,
 
		  general_info.config->mysql_database) )
 
    {
 
      fprintf(stderr, "%s:%d: mysqlConnect() failed\n", __FILE__, __LINE__);
 
      fprintf(stderr, "don't test mysql stuff\n");
 
@@ -148,7 +153,11 @@ int main(int argc, char *argv[])
 
  /** Execute test function */
 
  interactiveTest(test, &general_info);
 

	
 
  distrend_listen(general_info.config, &clients);
 
  if(distrend_listen(general_info.config, &clients))
 
    {
 
      fprintf(stderr, "error listening\n");
 
      return 1;
 
    }
 

	
 
  int slaveKey = 0; // Remotio should set me on a per-slave basis
 
  /* Main Loop */
 
@@ -156,7 +165,7 @@ int main(int argc, char *argv[])
 
    {
 
      int clientrequest = 0; /*< temporary example variable, will be replaced when we can handle messages */
 

	
 
      distrend_accept(general_info.config, clients);
 
      distrend_accept(general_info.config, clients, (distrend_handle_request_t)&distrend_handle_request, (void *)&general_info);
 

	
 
      /* Run the watchdog, @TODO: like every 10 mins or something */
 
      frame_watchdog(general_info.conn);
 
@@ -198,6 +207,13 @@ int main(int argc, char *argv[])
 

	
 
/* ********************** Functions ************************* */
 

	
 
int distrend_handle_request(struct distren_request *req, void *reqdata, struct general_info *geninfo)
 
{
 
  fprintf(stderr, "I can haz data %d bytes long\n", req->len);
 

	
 
  return 0;
 
}
 

	
 
/**
 
   Performs command stored in a client's request. @TODO: Fill stub
 
*/
 
@@ -207,7 +223,7 @@ int distrend_do()
 
}
 

	
 
/* Grabs config info from confs */
 
int distrend_do_csonfig(int argc, char *argv[], struct distrend_config **config)
 
int distrend_do_config(int argc, char *argv[], struct distrend_config **config)
 
{
 
  unsigned int counter;
 

	
 
@@ -225,6 +241,10 @@ int distrend_do_csonfig(int argc, char *
 
          CFGF_MULTI),
 
      CFG_SIMPLE_STR("datadir", NULL),
 
      CFG_STR_LIST("render_types", NULL, CFGF_NONE),
 
      CFG_SIMPLE_STR("mysql_user", NULL),
 
      CFG_SIMPLE_STR("mysql_host", NULL),
 
      CFG_SIMPLE_STR("mysql_pass", NULL),
 
      CFG_SIMPLE_STR("mysql_database", NULL),
 
      CFG_END()
 
    };
 

	
 
@@ -233,6 +253,10 @@ int distrend_do_csonfig(int argc, char *
 
  fprintf(stderr, "%s:%d: running config\n", __FILE__, __LINE__);
 
  *config = malloc(sizeof(struct distrend_config));
 
  myopts[1].simple_value = &(*config)->datadir;
 
  myopts[3].simple_value = &(*config)->mysql_user;
 
  myopts[4].simple_value = &(*config)->mysql_host;
 
  myopts[5].simple_value = &(*config)->mysql_pass;
 
  myopts[6].simple_value = &(*config)->mysql_database;
 

	
 
  if(options_init(argc, argv, &(*config)->mycfg, myopts, "daemon", &(*config)->options))
 
    return 1;
 
@@ -489,10 +513,14 @@ int interactiveTest(int test, struct gen
 
       break;
 

	
 
     case 5:
 
       distrend_listen(geninfo->config, &clients);
 
       if(distrend_listen(geninfo->config, &clients))
 
	 {
 
	   fprintf(stderr, "error listening\n");
 
	   return 1;
 
	 }
 
       while(1)
 
	 {
 
	   distrend_accept(geninfo->config, clients);
 
	   distrend_accept(geninfo->config, clients, (distrend_handle_request_t)&distrend_handle_request, (void *)geninfo);
 
	   /*
 
	     code for reading data from clients either goes here or in distrend_accept().
 
	     it might make sense for us to just pass the distrend_accept() function a
src/server/distrend.h
Show inline comments
 
@@ -35,6 +35,11 @@ struct distrend_config
 
  char *datadir;
 

	
 
  int die;
 

	
 
  char *mysql_user;
 
  char *mysql_host;
 
  char *mysql_pass;
 
  char *mysql_database;
 
};
 

	
 
#endif
src/server/mysql.c
Show inline comments
 
@@ -84,20 +84,15 @@ struct distrend_mysql_result
 
    funcs
 
 */
 

	
 
int mysqlConnect(distrend_mysql_conn_t *conn)
 
int mysqlConnect(distrend_mysql_conn_t *conn, const char *user, const char *host, const char *pass, const char *database)
 
{
 
  MYSQL *mysqlconn;
 

	
 
  char *server = "zserver1";
 
  char *user = "distren";
 
  char *password = "HwLxuBqTvJ6J7FWj";
 
  char *database = "distren";
 

	
 
  my_bool mybool;
 

	
 
  mysqlconn = mysql_init(NULL);
 

	
 
  if(!mysql_real_connect(mysqlconn, server, user, password, database, 0, NULL, CLIENT_MULTI_STATEMENTS))
 
  if(!mysql_real_connect(mysqlconn, host, user, pass, database, 0, NULL, CLIENT_MULTI_STATEMENTS))
 
    {
 
      fprintf(stderr, "%s\n", mysql_error(mysqlconn));
 
      return 1;
src/server/mysql.h
Show inline comments
 
@@ -34,10 +34,14 @@ typedef struct distrend_mysql_result *di
 

	
 
/**
 
   initiates a MySQL connection
 
   @param conn, pointer will be set to the struct
 
   @param conn pointer will be set to the struct
 
   @param user the mysql username
 
   @param host the hostname of the mysql server
 
   @param pass the password for the mysql account
 
   @param database the database on the mysql server to use
 
   @return 0 on success
 
 */
 
int mysqlConnect(distrend_mysql_conn_t *conn);
 
int mysqlConnect(distrend_mysql_conn_t *conn, const char *user, const char *host, const char *pass, const char *database);
 

	
 
/**
 
   cleans and disconnects MySQL connection
0 comments (0 inline, 0 general)