initial mysql support

git-svn-id: file:///home/ps/projects/distributor/trunk@3 4c72226d-0938-4c61-bee9-4ad40ed711b9
This commit is contained in:
ps 2011-08-18 18:09:36 +00:00
parent 660f52decc
commit 9c6e1c9230
2 changed files with 24 additions and 10 deletions

33
dist.c
View file

@ -21,20 +21,33 @@ struct serverinfo
unsigned port; unsigned port;
}; };
char *domains[]={"fakehermes.org","iteisa.net",NULL};
struct serverinfo servers[]={
{"mail.gutierrezdequevedo.com",2525},
{"94.23.193.98",25}
};
unsigned long connid=0; unsigned long connid=0;
struct serverinfo *get_server(char *domain) struct serverinfo *get_server(char *domain)
{ {
int i; char buffer[1024];
for(i=0;domains[i];i++) unsigned long *longs;
if(!cmp(domain,domains[i]))
return &servers[i]; /* connect to mysql and get values */
db=mysql_init(NULL);
if(NULL==mysql_real_connect(db,DBHOST,DBUSER,DBPASS,DBNAME,0,NULL,0)) { fprintf(stderr,"%s\n",mysql_error(db)); mysql_close(db); return NULL; }
/* clean string */
escape(db,domain);
/* generate sql */
snprintf(buffer,sizeof buffer,"SELECT `host`,`port` FROM `domains` WHERE `domain`=\"%s\" ORDER BY RAND();",domain);
/* query! */
if(mysql_query(db,buffer)) { fprintf(stderr,"%s\n",mysql_error(db)); mysql_close(db); return NULL; }
for(i=0;row=mysql_fetch_row(db);i++)
{
longs=mysql_fetch_lengths(row);
}
mysql_close(db);
return NULL; return NULL;
} }

View file

@ -138,6 +138,7 @@ int create_connected_socket(char *address,unsigned int port)
addr.sin_addr.s_addr=resolve(address); addr.sin_addr.s_addr=resolve(address);
addr.sin_port=htons(port); addr.sin_port=htons(port);
if(0==addr.sin_addr.s_addr) return -1; /* error resolving name */
/* connect to remote host */ /* connect to remote host */
snprintf(m_buffer,sizeof(m_buffer),"Connecting to %s:%d",address,port); snprintf(m_buffer,sizeof(m_buffer),"Connecting to %s:%d",address,port);
debug(m_buffer); debug(m_buffer);