1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
string DBHost, DBName, DBUser, DBPass, DBType = "mysql";
int ParseDBAddr(const char *addr)
{
int len = strlen(addr) + 1;
char *specific = new char[len] ;
char *hostinfo = new char[len];
char *hostname = new char[len];
char *auth = new char[len];
char *dbtype = new char[len];
char *dbname = new char[len];
char *dbhost = new char[len];
char *dbuser = new char[len];
char *dbpass = new char[len];
dbtype[0]=0;
auth[0] = 0;
specific[0]=0;
hostinfo[0]=0;
hostname[0]=0;
dbname[0]=0;
dbuser[0]=0;
dbpass[0]=0;
dbhost[0]=0;
if(sscanf(addr,"%[^:]:%s", dbtype , specific) == 2)
{
switch (sscanf(specific, "//%[^/]/%s", hostinfo, dbname))
{
case 1: break;
case 2:
char *ch;
if ((ch = strrchr(dbname, '/')))
*ch = '\0';
break;
default: return 1;
}
switch (sscanf(hostinfo, "%[^@]@%s", auth, hostname))
{
case 1:
strcpy(hostname, auth);
break;
case 2:
sscanf(auth, "%[^:]:%s", dbuser, dbpass);
break;
default: break;
}
sscanf(hostname, "%[^:]:%d", dbhost, &DBPort);
}
if(dbtype[0])
DBType = dbtype;
if(dbname[0])
DBName = dbname;
if(dbuser[0])
DBUser = dbuser;
if(dbpass[0])
DBPass = dbpass;
if(dbhost[0])
DBHost = dbhost;
delete dbname;
delete dbhost;
delete dbuser;
delete dbpass;
delete dbtype;
delete auth;
delete specific;
delete hostinfo;
delete hostname;
return 0;
} |
Partager