MCPcopy Create free account
hub / github.com/3proxy/3proxy / init_sql

Function init_sql

src/auth.c:1253–1318  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1251time_t attempt_time = 0;
1252
1253int init_sql(char * s){
1254 SQLRETURN retcode;
1255 char * datasource;
1256 char * username;
1257 char * password;
1258 char * string;
1259
1260 if(!s) return 0;
1261 if(!sqlstring || strcmp(sqlstring, s)){
1262 string = sqlstring;
1263 sqlstring=mystrdup(s);
1264 if(string)myfree(string);
1265 }
1266
1267 if(hstmt || hdbc || henv) close_sql();
1268 attempt++;
1269 attempt_time = time(0);
1270 if(!henv){
1271 retcode = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv);
1272 if (!henv || (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO)){
1273 henv = NULL;
1274 return 0;
1275 }
1276 retcode = SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (void*)SQL_OV_ODBC3, 0);
1277
1278 if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO) {
1279 return 0;
1280 }
1281 }
1282 if(!hdbc){
1283 retcode = SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc);
1284 if (!hdbc || (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO)) {
1285 hdbc = NULL;
1286 SQLFreeHandle(SQL_HANDLE_ENV, henv);
1287 henv = NULL;
1288 return 0;
1289 }
1290 SQLSetConnectAttr(hdbc, SQL_LOGIN_TIMEOUT, (void*)15, 0);
1291 }
1292 string = mystrdup(sqlstring);
1293 if(!string) return 0;
1294 datasource = strtok(string, ",");
1295 username = strtok(NULL, ",");
1296 password = strtok(NULL, ",");
1297
1298
1299 /* Connect to data source */
1300 retcode = SQLConnect(hdbc, (SQLCHAR*) datasource, (SQLSMALLINT)strlen(datasource),
1301 (SQLCHAR*) username, (SQLSMALLINT)((username)?strlen(username):0),
1302 (SQLCHAR*) password, (SQLSMALLINT)((password)?strlen(password):0));
1303
1304 myfree(string);
1305 if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO){
1306 SQLFreeHandle(SQL_HANDLE_DBC, hdbc);
1307 hdbc = NULL;
1308 SQLFreeHandle(SQL_HANDLE_ENV, henv);
1309 henv = NULL;
1310 return 0;

Callers 2

logsqlFunction · 0.85
ifFunction · 0.85

Calls 3

mystrdupFunction · 0.85
myfreeFunction · 0.85
close_sqlFunction · 0.85

Tested by

no test coverage detected