void dotest (char *font, int size, double incr, int w, int h, char *string, const char *filename) { gdImagePtr im; FILE *out; int bg; int fc; #if 0 int lc; #endif int xc = w / 2; int yc = h / 2; im = gdImageCreate (w, h); bg = gdImageColorAllocate (im, 0, 0, 0); gdImageFilledRectangle (im, 1, 1, w - 1, h - 1, bg); fc = gdImageColorAllocate (im, 255, 192, 192); #if 0 lc = gdImageColorAllocate (im, 192, 255, 255); #endif out = fopen (filename, "wb"); dowheel (im, fc, font, size, incr, xc, yc, 20, string); #if 0 dolines (im, lc, incr, xc, yc, 20, 120); #endif #if defined(HAVE_LIBPNG) gdImagePng (im, out); #elif defined(HAVE_LIBJPEG) gdImageJpeg (im, out, -1); #endif fclose (out); }
/* * This is the main server bit * * It receives SQL statements and executes them, breaking at EOF */ void mainloop() { int sz; string *str = NULL; int complete = -1; int ans; SQLSMALLINT ncol; SQLHSTMT stmt; char format; str = new_string(); while(isloop) { signal(SIGINT, sighand); signal(SIGTERM, sighand); complete = -1; sz = message_receive(mes, str, &complete, MES_CLIENT_TO_SERVER); if(sz < 0) { /* * End of file */ isloop = 0; break; } else if(sz <= 1) continue; format = *(string_s(str)); ans = SQLAllocHandle(SQL_HANDLE_STMT, (SQLHANDLE) hdbc, (SQLHANDLE *)stmt); if((ans != SQL_SUCCESS) && ( ans != SQL_SUCCESS_WITH_INFO)) { message_status(mes, 127, "ODBC: Cannot allocate statement handle\n", MES_SERVER_TO_CLIENT); return; } /* WTF: +1??? */ ans = SQLPrepare(stmt, (SQLCHAR*)string_s(str) + 1, SQL_NTS); if((ans != SQL_SUCCESS) && ( ans != SQL_SUCCESS_WITH_INFO)) { message_status(mes, 127, "ODBC: Cannot execute statement\n", MES_SERVER_TO_CLIENT); SQLFreeHandle(SQL_HANDLE_STMT, stmt); return; } ans = SQLNumResultCols(stmt, &(ncol)); if(ans != SQL_SUCCESS && ans != SQL_SUCCESS_WITH_INFO) { message_status(mes, 127, "ODBC: - cannot determine SQL type\n", MES_SERVER_TO_CLIENT); SQLFreeHandle(SQL_HANDLE_STMT, stmt); return; } if(ncol) dolines(&stmt, ncol, format); SQLFreeHandle(SQL_HANDLE_STMT, stmt); string_clear(str); message_send(mes, str, -1, MES_SERVER_TO_CLIENT); } string_delete(str); }
/* * This is the main server bit * * It receives SQL statements and executes them, breaking at EOF */ void mainloop() { int sz; char *errmes; string *str = NULL; int complete = -1; PGresult *pgr; char format; str = new_string(); while(isloop) { signal(SIGINT, sighand); signal(SIGTERM, sighand); complete = -1; sz = message_receive(mes, str, &complete, MES_CLIENT_TO_SERVER); if(sz < 0) { /* * End of file */ isloop = 0; break; } else if(sz <= 1) continue; format = *(string_s(str)); pgr = PQexec(sqldb, string_s(str) + 1); if(pgr == NULL) { message_status(mes, 127, "Postges error - cannot allocate result\n", MES_SERVER_TO_CLIENT); string_clear(str); } else { errmes = PQresultErrorMessage(pgr); if(*errmes) { char ws[128]; snprintf(ws, 127, "postgres error: %s\n", errmes); message_status(mes, 127, ws, MES_SERVER_TO_CLIENT); string_clear(str); } else { if(PQresultStatus(pgr) == PGRES_TUPLES_OK) dolines(pgr, format); string_clear(str); message_send(mes, str, -1, MES_SERVER_TO_CLIENT); } PQclear(pgr); } } string_delete(str); }
/* * This is the main server bit * * It receives SQL statements and executes them, breaking at EOF */ void mainloop() { int sz; string *str = NULL; MYSQL_RES *res; int complete = -1; int ans; char format; str = new_string(); while(isloop) { signal(SIGINT, sighand); signal(SIGTERM, sighand); complete = -1; sz = message_receive(mes, str, &complete, MES_CLIENT_TO_SERVER); if(sz < 0) { /* * End of file */ isloop = 0; break; } else if(sz <= 1) continue; format = *(string_s(str)); ans = mysql_query(sqldb, string_s(str) + 1); string_clear(str); if(ans) { message_status(mes, 127, "cannot execute mysql query", MES_SERVER_TO_CLIENT); } else { if((res = mysql_store_result(sqldb)) == NULL) { if(mysql_field_count(sqldb)) message_status(mes, 127, "Error retrieveing mysql data", MES_SERVER_TO_CLIENT); else message_send(mes, str, -1, MES_SERVER_TO_CLIENT); /* Is a DML query */ } else { dolines(res, format); mysql_free_result(res); message_send(mes, str, -1, MES_SERVER_TO_CLIENT); /* Is a DML query */ } } } string_delete(str); }