int fb_affected_rows(rlm_sql_firebird_conn_t *conn) { static char count_info[] = {isc_info_sql_records}; char info_buffer[128]; char *p ; int affected_rows = -1; if (!conn->stmt) return -1; isc_dsql_sql_info(conn->status, &conn->stmt, sizeof (count_info), count_info, sizeof (info_buffer), info_buffer); if (IS_ISC_ERROR(conn->status)) { return fb_error(conn); } p = info_buffer + 3; while (*p != isc_info_end) { p++; short len = (short)isc_vax_integer(p, 2); p += 2; affected_rows = isc_vax_integer(p, len); if (affected_rows > 0) { break; } p += len; } return affected_rows; }
static int _sql_socket_destructor(rlm_sql_firebird_conn_t *conn) { int i; DEBUG2("rlm_sql_firebird: socket destructor called, closing socket"); fb_commit(conn); if (conn->dbh) { fb_free_statement(conn); isc_detach_database(conn->status, &(conn->dbh)); if (fb_error(conn)) { WDEBUG("rlm_sql_firebird: Got error " "when closing socket: %s", conn->error); } } #ifdef _PTHREAD_H pthread_mutex_destroy (&conn->mut); #endif for (i=0; i < conn->row_fcount; i++) { free(conn->row[i]); } free(conn->row); free(conn->row_sizes); fb_free_sqlda(conn->sqlda_out); free(conn->sqlda_out); free(conn->tpb); free(conn->dpb); return 0; }
int fb_sql_query(rlm_sql_firebird_conn_t *conn, char const *query) { if (fb_prepare(conn, query)) { return fb_error(conn); } switch (conn->statement_type) { case isc_info_sql_stmt_exec_procedure: isc_dsql_execute2(conn->status, &conn->trh, &conn->stmt, SQL_DIALECT_V6, 0, conn->sqlda_out); break; default: isc_dsql_execute(conn->status, &conn->trh, &conn->stmt, SQL_DIALECT_V6, 0); break; } return fb_error(conn); }
int fb_connect(rlm_sql_firebird_conn_t * conn, rlm_sql_config_t *config) { char *p; char *database; conn->dpb_len = 4; if (config->sql_login) { conn->dpb_len+= strlen(config->sql_login) + 2; } if (config->sql_password) { conn->dpb_len += strlen(config->sql_password) + 2; } conn->dpb = (char *) malloc(conn->dpb_len); p = conn->dpb; *conn->dpb++= isc_dpb_version1; *conn->dpb++= isc_dpb_num_buffers; *conn->dpb++= 1; *conn->dpb++= 90; fb_dpb_add_str(&conn->dpb, isc_dpb_user_name, config->sql_login); fb_dpb_add_str(&conn->dpb, isc_dpb_password, config->sql_password); conn->dpb = p; /* * Check if database and server in the form of server:database. * If config->sql_server contains ':', then config->sql_db * parameter ignored. */ if (strchr(config->sql_server, ':')) { database = strdup(config->sql_server); } else { /* * Make database and server to be in the form * of server:database */ int ls = strlen(config->sql_server); int ld = strlen(config->sql_db); database = (char *) calloc(ls + ld + 2, 1); strcpy(database, config->sql_server); database[ls] = ':'; memmove(database + ls + 1, config->sql_db, ld); } isc_attach_database(conn->status, 0, database, &conn->dbh, conn->dpb_len, conn->dpb); free(database); return fb_error(conn); }
int fb_rollback(rlm_sql_firebird_conn_t *conn) { conn->sql_code = 0; if (conn->trh) { isc_rollback_transaction(conn->status, &conn->trh); // conn->in_use = 0; pthread_mutex_unlock(&conn->mut); if (IS_ISC_ERROR(conn->status)) { return fb_error(conn); } } return conn->sql_code; }
int fb_commit(rlm_sql_firebird_conn_t *conn) { conn->sql_code = 0; if (conn->trh) { isc_commit_transaction(conn->status, &conn->trh); if (IS_ISC_ERROR(conn->status)) { fb_error(conn); ERROR("Fail to commit. Error: %s. Try to rollback.", conn->error); return fb_rollback(conn); } } // conn->in_use = 0; pthread_mutex_unlock(&conn->mut); return conn->sql_code; }
int fb_fetch(rlm_sql_firebird_conn_t *conn) { long fetch_stat; if (conn->statement_type!= isc_info_sql_stmt_select) { return 100; } fetch_stat = isc_dsql_fetch(conn->status, &conn->stmt, SQL_DIALECT_V6, conn->sqlda_out); if (fetch_stat) { if (fetch_stat!= 100L) { fb_error(conn); } else { conn->sql_code = 0; } } return fetch_stat; }
int fb_close_cursor(rlm_sql_firebird_conn_t *conn) { isc_dsql_free_statement(conn->status, &conn->stmt, DSQL_close); return fb_error(conn); }
/* * Init framebuffer */ void fb_init() { const uint8_t *in, *cdata; uint8_t *out, *jpg_out_data; int font_size; int jpg_height, jpg_width, jpg_image_size; int i; uint32_t gray; /* Init framebuffer */ framebuffer = *framebuffer_ptr; framebuffer_size = *framebuffer_size_ptr; /* Init font */ font_size = FONT_WIDTH * FONT_HEIGHT * NUM_CHARS; jpg_out_data = malloc(font_size * sizeof(struct color)); if (jpg_out_data != NULL) { /* The font is in RGB format */ if (!jpeg_load_rgbx(jpg_out_data, font_size * sizeof(struct color), &jpg_width, &jpg_height, &jpg_image_size, (const uint8_t*) FONT_OFFSET, FONT_SIZE_LIMIT)) { font_data = malloc(font_size); if ((jpg_width != FONT_WIDTH * NUM_CHARS) || (jpg_height != FONT_HEIGHT)) fb_error("Font jpg image size is not valid (must be 960x80)."); /* Convert it to grayscale and store it */ in = jpg_out_data; out = font_data; for (i = 0; i < font_size; i++) { gray = 299*in[0] + 587*in[1] + 114*in[2]; out[i] = (char)(gray / 1000); in += 4; } } else fb_error("Failed to load jpg image."); free(jpg_out_data); jpg_out_data = NULL; } else fb_error("Failed to initialize font."); /* Init background */ background = malloc(SCREEN_HEIGHT * SCREEN_WIDTH * sizeof(struct color)); if (background != NULL) { if (!jpeg_load_rgbx(background, SCREEN_HEIGHT * SCREEN_WIDTH * sizeof(struct color), &jpg_width, &jpg_height, &jpg_image_size, (const uint8_t*) BOOTLOGO_OFFSET, BOOTLOGO_SIZE_LIMIT)) { if ((jpg_width != SCREEN_WIDTH) || (jpg_height != SCREEN_HEIGHT)) { /* Discard - invalid size */ free(background); background = NULL; } } else { free(background); background = NULL; } } /* Init colors */ cdata = (const uint8_t*)(CUSTOM_COLORS_OFFSET); if (!memcmp(cdata, CUSTOM_COLORS_ID, strlen(CUSTOM_COLORS_ID))) { /* We have custom colors */ cdata += strlen(CUSTOM_COLORS_ID); /* Title */ title_color.R = *cdata++; title_color.G = *cdata++; title_color.B = *cdata++; title_color.X = *cdata++; /* Text */ text_color.R = *cdata++; text_color.G = *cdata++; text_color.B = *cdata++; text_color.X = *cdata++; /* Error text */ error_text_color.R = *cdata++; error_text_color.G = *cdata++; error_text_color.B = *cdata++; error_text_color.X = *cdata++; /* Highlighting color */ highlight_color.R = *cdata++; highlight_color.G = *cdata++; highlight_color.B = *cdata++; highlight_color.X = *cdata++; /* Highlighted text */ highlight_text_color.R = *cdata++; highlight_text_color.G = *cdata++; highlight_text_color.B = *cdata++; highlight_text_color.X = *cdata++; } text_cur_x = 0; text_cur_y = 0; /* Reset texts */ title[0] = '\0'; status[0] = '\0'; text[0][0] = '\0'; /* Clear framebuffer */ builder = framebuffer + (SCREEN_HEIGHT * SCREEN_WIDTH * sizeof(struct color)); memset(framebuffer, 0, framebuffer_size); }