std::wstring Utils::widenString(const std::string& s) { // Set LC_CTYPE according to the environnement variable, for mbsrtowcs(). system::TemporaryLocale locale(LC_CTYPE, ""); const char * src = s.c_str(); // Call mbsrtowcs() once to find out the length of the converted string. size_t length = mbsrtowcs(NULL, &src, 0, NULL); if (length == size_t(-1)) { int error = errno; msg_warning("Utils::widenString()") << strerror(error); return L""; } // Call mbsrtowcs() again with a correctly sized buffer to actually do the conversion. wchar_t * buffer = new wchar_t[length + 1]; length = mbsrtowcs(buffer, &src, length + 1, NULL); if (length == size_t(-1)) { int error = errno; msg_warning("Utils::widenString()") << strerror(error); delete[] buffer; return L""; } if (src != NULL) { msg_warning("Utils::widenString()") << "Conversion failed (\"" << s << "\")"; delete[] buffer; return L""; } std::wstring result(buffer); delete[] buffer; return result; }
/* GPattern only works with utf8 strings, if the input is not utf8, we risk * a crash */ static gboolean log_matcher_glob_match(LogMatcher *s, LogMessage *msg, gint value_handle, const gchar *value, gssize value_len) { LogMatcherGlob *self = (LogMatcherGlob *) s; if (G_LIKELY((msg->flags & LF_UTF8) || g_utf8_validate(value, value_len, NULL))) { static gboolean warned = FALSE; gchar *buf; if (G_UNLIKELY(!warned && (msg->flags & LF_UTF8) == 0)) { msg_warning("Input is valid utf8, but the log message is not tagged as such, this performs worse than enabling validate-utf8 flag on input", evt_tag_printf("value", "%.*s", (gint) value_len, value), NULL); warned = TRUE; } APPEND_ZERO(buf, value, value_len); return g_pattern_match(self->pattern, value_len, buf, NULL); } else { msg_warning("Input is not valid utf8, glob match requires utf8 input, thus it never matches in this case", evt_tag_printf("value", "%.*s", (gint) value_len, value), NULL); } return FALSE; }
std::string Utils::narrowString(const std::wstring& ws) { // Set LC_CTYPE according to the environnement variable, for wcstombs(). system::TemporaryLocale locale(LC_CTYPE, ""); const wchar_t * src = ws.c_str(); // Call wcstombs() once to find out the length of the converted string. size_t length = wcstombs(NULL, src, 0); if (length == size_t(-1)) { msg_warning("Utils::narrowString()") << "Conversion failed"; return ""; } // Call wcstombs() again with a correctly sized buffer to actually do the conversion. char * buffer = new char[length + 1]; length = wcstombs(buffer, src, length + 1); if (length == size_t(-1)) { msg_warning("Utils::narrowString()") << "Conversion failed"; delete[] buffer; return ""; } std::string result(buffer); delete[] buffer; return result; }
gboolean socket_options_setup_socket_method(SocketOptions *self, gint fd, GSockAddr *bind_addr, AFSocketDirection dir) { gint rc; if (dir & AFSOCKET_DIR_RECV) { if (self->so_rcvbuf) { gint so_rcvbuf_set = 0; socklen_t sz = sizeof(so_rcvbuf_set); rc = setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &self->so_rcvbuf, sizeof(self->so_rcvbuf)); if (rc < 0 || getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &so_rcvbuf_set, &sz) < 0 || sz != sizeof(so_rcvbuf_set) || so_rcvbuf_set < self->so_rcvbuf) { msg_warning("The kernel refused to set the receive buffer (SO_RCVBUF) to the requested size, you probably need to adjust buffer related kernel parameters", evt_tag_int("so_rcvbuf", self->so_rcvbuf), evt_tag_int("so_rcvbuf_set", so_rcvbuf_set), NULL); } } } if (dir & AFSOCKET_DIR_SEND) { if (self->so_sndbuf) { gint so_sndbuf_set = 0; socklen_t sz = sizeof(so_sndbuf_set); rc = setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &self->so_sndbuf, sizeof(self->so_sndbuf)); if (rc < 0 || getsockopt(fd, SOL_SOCKET, SO_SNDBUF, &so_sndbuf_set, &sz) < 0 || sz != sizeof(so_sndbuf_set) || so_sndbuf_set < self->so_sndbuf) { msg_warning("The kernel refused to set the send buffer (SO_SNDBUF) to the requested size, you probably need to adjust buffer related kernel parameters", evt_tag_int("so_sndbuf", self->so_sndbuf), evt_tag_int("so_sndbuf_set", so_sndbuf_set), NULL); } } if (self->so_broadcast) setsockopt(fd, SOL_SOCKET, SO_BROADCAST, &self->so_broadcast, sizeof(self->so_broadcast)); } setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &self->so_keepalive, sizeof(self->so_keepalive)); return TRUE; }
gboolean http_dd_init(LogPipe *s) { HTTPDestinationDriver *self = (HTTPDestinationDriver *)s; GlobalConfig *cfg = log_pipe_get_config(s); if (self->load_balancer->num_targets == 0) http_load_balancer_add_target(self->load_balancer, HTTP_DEFAULT_URL); if (self->load_balancer->num_targets > 1 && s->persist_name == NULL) { msg_warning("WARNING: your http() driver instance uses multiple urls without persist-name(). " "It is recommended that you set persist-name() in this case as syslog-ng will be " "using the first URL in urls() to register persistent data, such as the disk queue " "name, which might change", evt_tag_str("url", self->load_balancer->targets[0].url)); } /* we need to set up url before we call the inherited init method, so our stats key is correct */ self->url = self->load_balancer->targets[0].url; if (!_setup_auth_header(s)) return FALSE; if (!log_threaded_dest_driver_init_method(s)) return FALSE; log_template_options_init(&self->template_options, cfg); http_load_balancer_set_recovery_timeout(self->load_balancer, self->super.time_reopen); return log_threaded_dest_driver_start_workers(&self->super); }
/* * calcbdist - calculate binding distance for each variable */ void calcbdist_r(Cellidx ci, int depth) { int i; switch (Ctype(ci)) { case VAR: /* search the binding lambda */ for (i = depth - 1; i >= 0; i--) if (Cvar(ci) == boundvars[i]) break; if (i < 0) /* free variable */ Cbdist(ci) = -(depth + 1); /* +1 to reserve 0 */ else { /* bound variable */ Cbdist(ci) = depth - i; } return; case ABST: if (depth < MAXABSTDEPTH) { boundvars[depth] = Cbv(ci); calcbdist_r(Cbody(ci), depth + 1); } else { msg_warning("calcbdist: MAXABSTDEPTH reached; ignoring the subtree\n"); } return; case APPL: calcbdist_r(Cleft(ci), depth); calcbdist_r(Cright(ci), depth); return; default: fatal("calcbdist: invalid cell type %d\n", Ctype(ci)); /*NOTREACHED*/ } }
static int arraynodes_r(Cellidx ci, int curlev, int a[], int asize) { int lev1, lev2; if (curlev >= asize) { msg_warning("arraynodes_r: array size (%d) reached; ignoring the subtree\n", asize); return asize; } a[curlev]++; curlev++; switch (Ctype(ci)) { case VAR: return curlev; case ABST: return arraynodes_r(Cbody(ci), curlev, a, asize); case APPL: lev1 = arraynodes_r(Cleft(ci), curlev, a, asize); lev2 = arraynodes_r(Cright(ci), curlev, a, asize); return max(lev1, lev2); default: fatal("arraynodes_r: unexpected cell type %d\n", Ctype(ci)); } /*NOTREACHED*/ return curlev; }
/** * Tag entry point. */ void tag_TFSFOpenFaces(FILE * fp) { static int first = 1; if(!first) // Ensures uniqness of the call. msg_warning(mf_here, "tag [TFSF: open faces] is used twice."); first = 0; const char *word = NULL; msg_send("tag_TFSFOpenFaces: "); while(cfg_isOption(fp)) // Gets all options. { word = cfg_readOptWord(fp); int f = 0; for(; f < 6; ++f) if(!strcmp(faces[f].name, word)) break; if(f >= 6) error("tag_TFSFOpenFaces: word '%s' is not a valid option here.", word); faces[f].opened = 1; msg_send(" - removing face %s ...", faces[f].name); } if(!word) msg_send(" Tag is called but no faces marked to open."); if(cpu_here) // Master will update all files. return; FILE *file = cfg_open(".TFSF/openFaces.cfg", "wt", __func__); for(int f = 0; f < 6; ++f) fprintf(file, "@ %d state of %s (0 - engaged, 1 - opened/removed)\n", faces[f].opened, faces[f].name); fprintf(file, "\n\n This file is automatically generated by setup.out (tag [TFSF: open faces]).\n"); fclose(file); }
static gboolean afunix_sd_acquire_socket(AFSocketSourceDriver *s, gint *result_fd) { AFUnixSourceDriver *self = (AFUnixSourceDriver *) s; gboolean fd_ok; GlobalConfig *cfg = log_pipe_get_config(&s->super.super.super); fd_ok = afunix_sd_acquire_named_socket(s, result_fd, self->filename); if (fd_ok && (*result_fd == -1) && (strcmp(self->filename, "/dev/log") == 0)) { fd_ok = afunix_sd_acquire_named_socket(s, result_fd, "/run/systemd/journal/syslog"); if (fd_ok && *result_fd > -1) { if (cfg_is_config_version_older(cfg, 0x0304)) { msg_warning("WARNING: systemd detected while using /dev/log; migrating automatically to /run/systemd/journal/syslog. Please update your configuration to use the system() source.", evt_tag_str("id", self->super.super.super.id), NULL); g_free(self->filename); self->filename = g_strdup("/run/systemd/journal/syslog"); return TRUE; } } } if (!fd_ok) msg_debug("Failed to acquire systemd socket, trying to open ourselves", evt_tag_str("filename", self->filename), NULL); return fd_ok; }
void AssocContainCanvas::remove(bool from_model) { if (!from_model) { if (the_canvas()->must_draw_all_relations()) { const AssocContainCanvas * a = this; while (a->begin->type() == UmlArrowPoint) { a = (AssocContainCanvas *) ((ArrowPointCanvas *) a->begin)->get_other(a); if (a == 0) break; } if (a && !a->begin->isSelected() && !a->begin->get_bn()->deletedp()) { a = this; while (a->end->type() == UmlArrowPoint) { a = (AssocContainCanvas *) ((ArrowPointCanvas *) a->end)->get_other(a); if (a == 0) break; } if (a && !a->end->isSelected() && !a->end->get_bn()->deletedp()) { msg_warning("Bouml", TR("<i>Draw all relations</i> forced to <i>no</i>")); the_canvas()->dont_draw_all_relations(); } } } delete_it(); } else get_start()->unassociate(get_end()); // line will be deleted }
static gboolean systemd_syslog_sd_init_method(LogPipe *s) { SystemDSyslogSourceDriver *self = (SystemDSyslogSourceDriver*) s; if (service_management_get_type() != SMT_SYSTEMD) { msg_error("Error initializing systemd-syslog() source", evt_tag_str("systemd_status", "not-running"), NULL); return FALSE; } if (self->from_unix_source) { msg_warning("systemd-syslog() source ignores configuration options. " "Please, do not set anything on it", NULL); socket_options_free(self->super.socket_options); self->super.socket_options = socket_options_new(); socket_options_init_instance(self->super.socket_options); } return afsocket_sd_init_method((LogPipe*) &self->super); }
void journal_reader_options_init(JournalReaderOptions *options, GlobalConfig *cfg, const gchar *group_name) { if (options->initialized) return; log_source_options_init(&options->super, cfg, group_name); if (cfg->threaded) options->flags |= JR_THREADED; if (options->recv_time_zone == NULL) options->recv_time_zone = g_strdup(cfg->recv_time_zone); if (options->recv_time_zone_info == NULL) options->recv_time_zone_info = time_zone_info_new(options->recv_time_zone); gchar *value = ".journald."; if (options->prefix == NULL && cfg_is_config_version_older(cfg, VERSION_VALUE_3_8)) { msg_warning("WARNING: Default value changed for the prefix() option of systemd-journal source in " VERSION_3_8, evt_tag_str("old_value", ""), evt_tag_str("new_value", value)); } else if (!cfg_is_config_version_older(cfg, VERSION_VALUE_3_8)) { options->prefix = g_strdup(value); } options->initialized = TRUE; }
static gboolean afinet_dd_setup_addresses(AFSocketDestDriver *s) { AFInetDestDriver *self = (AFInetDestDriver *) s; if (!afsocket_dd_setup_addresses_method(s)) return FALSE; g_sockaddr_unref(self->super.bind_addr); g_sockaddr_unref(self->super.dest_addr); if (!resolve_hostname_to_sockaddr(&self->super.bind_addr, self->super.transport_mapper->address_family, self->bind_ip)) return FALSE; if (self->bind_port) g_sockaddr_set_port(self->super.bind_addr, afinet_lookup_service(self->super.transport_mapper, self->bind_port)); if (!resolve_hostname_to_sockaddr(&self->super.dest_addr, self->super.transport_mapper->address_family, self->hostname)) return FALSE; if (!self->dest_port) { const gchar *port_change_warning = transport_mapper_inet_get_port_change_warning(self->super.transport_mapper); if (port_change_warning) { msg_warning(port_change_warning, evt_tag_str("id", self->super.super.super.id)); } } g_sockaddr_set_port(self->super.dest_addr, _determine_port(self)); return TRUE; }
static void system_sysblock_add_linux_kmsg(GString *sysblock) { gchar *kmsg = "/proc/kmsg"; int fd; gchar *format = NULL; if ((fd = open("/dev/kmsg", O_RDONLY)) != -1) { if ((lseek (fd, 0, SEEK_END) != -1) && _is_fd_pollable(fd)) { kmsg = "/dev/kmsg"; format = "linux-kmsg"; } close (fd); } if (access(kmsg, R_OK) == -1) { msg_warning("system(): The kernel message buffer is not readable, " "please check permissions if this is unintentional.", evt_tag_str("device", kmsg), evt_tag_errno("error", errno), NULL); } else system_sysblock_add_file(sysblock, kmsg, -1, "kernel", "kernel", format); }
static void propose_lang() { // note : QFile fp(QDir::home().absFilePath(".boumlrc")) doesn't work // if the path contains non latin1 characters, for instance cyrillic ! QString s = homeDir().absFilePath(".boumlrc"); FILE * fp = fopen((const char *) s, "a"); if (fp != 0) { QString lang = lang_file(); if (! lang.isEmpty()) { FILE * fp2 = fopen((const char *) lang, "r"); if (fp2 != 0) { fclose(fp2); fprintf(fp, "LANG %s\n", (const char *) lang); fclose(fp); set_lang((const char *) lang); msg_warning(TR("language"), TR("the used language for menus and dialogs was set automatically,\n" "you can change it through the environment dialog")); } } else fclose(fp); } }
void BaseObject::parse( BaseObjectDescription* arg ) { if (arg->getAttribute("src")) { std::string valueString(arg->getAttribute("src")); if (valueString[0] != '@') { msg_error() <<"'src' attribute value should be a link using '@'"; } else { if(valueString.size() == 1) // ignore '@' alone { msg_warning() << "'src=@' does nothing."; } else { std::vector< std::string > attributeList; arg->getAttributeList(attributeList); setSrc(valueString, &attributeList); } } arg->removeAttribute("src"); } Base::parse(arg); }
EXPORT void CALL ProcessDList(void) { if (!warn_hle) { msg_warning("Please disable 'Graphic HLE' in the plugin settings."); warn_hle = true; } }
static FilterStore * _filter_store_order_by_selectors(FilterStore *self, GList *ordered_selectors) { FilterStore *fs_ordered = _filter_store_new(); GList *name_it, *filter_it, *selector_it; gboolean inserted; for(selector_it = ordered_selectors; selector_it != NULL; selector_it = selector_it->next) { inserted = FALSE; for (filter_it = self->filters, name_it = self->filter_names; filter_it != NULL && name_it != NULL; filter_it = filter_it->next, name_it = name_it->next) { if (g_strcmp0((const gchar *)selector_it->data, (const gchar *)name_it->data) == 0) { inserted = TRUE; _filter_store_prepend(fs_ordered, name_it->data, filter_it->data); self->filters = g_list_delete_link(self->filters, filter_it); self->filter_names = g_list_delete_link(self->filter_names, name_it); break; } } if (!inserted) msg_warning("A filter referenced by the database is not found in the filters file", evt_tag_str("filter", selector_it->data)); } fs_ordered->filters = g_list_reverse(fs_ordered->filters); fs_ordered->filter_names = g_list_reverse(fs_ordered->filter_names); _filter_store_free(self); return fs_ordered; }
void SimpleRelationCanvas::remove(bool from_model) { if (! from_model) { if (the_canvas()->must_draw_all_relations()) { const SimpleRelationCanvas * a = this; while (a->begin->type() == UmlArrowPoint) { a = (SimpleRelationCanvas *)((ArrowPointCanvas *) a->begin)->get_other(a); if (a == 0) break; } if (a && !a->begin->isSelected() && !a->begin->get_bn()->deletedp()) { a = this; while (a->end->type() == UmlArrowPoint) { a = (SimpleRelationCanvas *)((ArrowPointCanvas *) a->end)->get_other(a); if (a == 0) break; } if (a && !a->end->isSelected() && !a->end->get_bn()->deletedp()) { msg_warning("Douml", "<i>Draw all relations</i> forced to <i>no</i>"); the_canvas()->dont_draw_all_relations(); } } } delete_it(); } else data->delete_it(); // will remove canvas }
DataFile * af_load_wave_file (UserData *ud) { DataFile *wdata = NULL; if ( ! ud->listFiles) { return NULL; } GSList *list = ud->listFiles; while (list) { GSList *next = list->next; char *filename = (char *) list->data; if (file_exists (filename)) { wdata = datafile_new( ud, af_mk_label(filename) ); datafile_set_file(wdata, filename, ud->format); ap_load_wave ( wdata ); } else { msg_warning(_("file '%s' do not exist."), filename ); } list = next; } return wdata; }
static gboolean afsocket_sd_setup_reader_options(AFSocketSourceDriver *self) { GlobalConfig *cfg = log_pipe_get_config(&self->super.super.super); if (self->transport_mapper->sock_type == SOCK_STREAM && !self->window_size_initialized) { /* distribute the window evenly between each of our possible * connections. This is quite pessimistic and can result in very low * window sizes. Increase that but warn the user at the same time */ self->reader_options.super.init_window_size /= self->max_connections; if (self->reader_options.super.init_window_size < 100) { msg_warning("WARNING: window sizing for tcp sources were changed in " VERSION_3_3 ", the configuration value was divided by the value of max-connections(). The result was too small, clamping to 100 entries. Ensure you have a proper log_fifo_size setting to avoid message loss.", evt_tag_int("orig_log_iw_size", self->reader_options.super.init_window_size), evt_tag_int("new_log_iw_size", 100), evt_tag_int("min_log_fifo_size", 100 * self->max_connections), NULL); self->reader_options.super.init_window_size = 100; } self->window_size_initialized = TRUE; } log_reader_options_init(&self->reader_options, cfg, self->super.super.group); return TRUE; }
void http_dd_set_ssl_version(LogDriver *d, const gchar *value) { HTTPDestinationDriver *self = (HTTPDestinationDriver *) d; if (strcmp(value, "default") == 0) { /* * Negotiate the version based on what the remote server supports. * SSLv2 is disabled by default as of libcurl 7.18.1. * SSLv3 is disabled by default as of libcurl 7.39.0. */ self->ssl_version = CURL_SSLVERSION_DEFAULT; } else if (strcmp(value, "tlsv1") == 0) { /* TLS 1.x */ self->ssl_version = CURL_SSLVERSION_TLSv1; } else if (strcmp(value, "sslv2") == 0) { /* SSL 2 only */ self->ssl_version = CURL_SSLVERSION_SSLv2; } else if (strcmp(value, "sslv3") == 0) { /* SSL 3 only */ self->ssl_version = CURL_SSLVERSION_SSLv3; } #ifdef CURL_SSLVERSION_TLSv1_0 else if (strcmp(value, "tlsv1_0") == 0) { /* TLS 1.0 only */ self->ssl_version = CURL_SSLVERSION_TLSv1_0; } #endif #ifdef CURL_SSLVERSION_TLSv1_1 else if (strcmp(value, "tlsv1_1") == 0) { /* TLS 1.1 only */ self->ssl_version = CURL_SSLVERSION_TLSv1_1; } #endif #ifdef CURL_SSLVERSION_TLSv1_2 else if (strcmp(value, "tlsv1_2") == 0) { /* TLS 1.2 only */ self->ssl_version = CURL_SSLVERSION_TLSv1_2; } #endif else { msg_warning("curl: unsupported SSL version", evt_tag_str("ssl_version", value)); } }
static gboolean afmongodb_dd_connect(MongoDBDestDriver *self, gboolean reconnect) { GList *l; if (reconnect && self->conn) return TRUE; self->conn = mongo_sync_connect(self->host, self->port, FALSE); if (!self->conn) { msg_error ("Error connecting to MongoDB", NULL); return FALSE; } mongo_sync_conn_set_safe_mode(self->conn, self->safe_mode); l = self->servers; while ((l = g_list_next(l)) != NULL) { gchar *host = NULL; gint port = 27017; if (!mongo_util_parse_addr(l->data, &host, &port)) { msg_warning("Cannot parse MongoDB server address, ignoring", evt_tag_str("address", l->data), NULL); continue; } mongo_sync_conn_seed_add (self->conn, host, port); msg_verbose("Added MongoDB server seed", evt_tag_str("host", host), evt_tag_int("port", port), NULL); g_free(host); } /* if (self->user || self->password) { if (!self->user || !self->password) { msg_error("Neither the username, nor the password can be empty", NULL); return FALSE; } if (mongo_cmd_authenticate(&self->mongo_conn, self->db, self->user, self->password) != 1) { msg_error("MongoDB authentication failed", NULL); return FALSE; } } */ return TRUE; }
void BaseObject::init() { for(VecData::const_iterator iData = this->m_vecData.begin(); iData != this->m_vecData.end(); ++iData) { if ((*iData)->isRequired() && !(*iData)->isSet()) { msg_warning() << "Required data \"" << (*iData)->getName() << "\" has not been set. (Current value is " << (*iData)->getValueString() << ")" ; } } }
const char* GUIManager::GetValidGUIName() { const char* name; std::string lastGuiFilename = BaseGUI::getConfigDirectoryPath() + "/lastUsedGUI.ini"; if (guiCreators.empty()) { msg_error("GUIManager") << "ERROR(SofaGUI): No GUI registered."; return nullptr; } else { //Check the config file for the last used GUI type if(FileSystem::exists(lastGuiFilename)) { std::string lastGuiName; std::ifstream lastGuiStream(lastGuiFilename.c_str()); std::getline(lastGuiStream,lastGuiName); lastGuiStream.close(); const char* lastGuiNameChar = lastGuiName.c_str(); // const char* lastGuiNameChar = "qt"; std::list<GUICreator>::iterator it1 = guiCreators.begin(); std::list<GUICreator>::iterator itend1 = guiCreators.end(); while(++it1 != itend1) { if( strcmp(lastGuiNameChar, it1->name) == 0 ) { return it1->name; } } msg_warning("GUIManager") << "WARNING(SofaGUI): Previously used GUI not registered. Using default GUI."; } else { msg_info("GUIManager") << "INFO(SofaGUI): lastUsedGUI.ini not found; using default GUI."; } std::list<GUICreator>::iterator it =guiCreators.begin(); std::list<GUICreator>::iterator itend =guiCreators.end(); name = it->name; int prio = it->priority; while (++it != itend) { if (it->priority > prio) { name = it->name; prio = it->priority; } } } return name; }
static inline void _validate_file_type(const gchar *name, FileOpenOptions *open_opts) { struct stat st; if (stat(name, &st) >= 0) { if (open_opts->is_pipe && !S_ISFIFO(st.st_mode)) { msg_warning("WARNING: you are using the pipe driver, underlying file is not a FIFO, it should be used by file()", evt_tag_str("filename", name), NULL); } else if (!open_opts->is_pipe && S_ISFIFO(st.st_mode)) { msg_warning("WARNING: you are using the file driver, underlying file is a FIFO, it should be used by pipe()", evt_tag_str("filename", name), NULL); } } }
static void _init_options(HostResolveOptions *options) { if (options->use_dns == 0) { if (options->use_dns_cache != 0) { msg_warning("WARNING: With use-dns(no), dns-cache() will be forced to 'no' too!"); } options->use_dns_cache = 0; } }
/** * afsql_dd_create_index: * * This function creates an index for the column specified and returns * TRUE to indicate success. * * NOTE: This function can only be called from the database thread. **/ static gboolean afsql_dd_create_index(AFSqlDestDriver *self, gchar *table, gchar *column) { GString *query_string; gboolean success = TRUE; query_string = g_string_sized_new(64); if (strcmp(self->type, s_oracle) == 0) { /* NOTE: oracle index indentifier length is max 30 characters * so we use the first 30 characters of the table_column md5 hash */ if ((strlen(table) + strlen(column)) > 25) { #if ENABLE_SSL guchar hash[MD5_DIGEST_LENGTH]; gchar hash_str[31]; gchar *cat = g_strjoin("_", table, column, NULL); MD5((guchar *)cat, strlen(cat), hash); g_free(cat); format_hex_string(hash, sizeof(hash), hash_str, sizeof(hash_str)); hash_str[0] = 'i'; g_string_printf(query_string, "CREATE INDEX %s ON %s (%s)", hash_str, table, column); #else msg_warning("The name of the index would be too long for Oracle to handle and OpenSSL was not detected which would be used to generate a shorter name. Please enable SSL support in order to use this combination.", evt_tag_str("table", table), evt_tag_str("column", column), NULL); #endif } else g_string_printf(query_string, "CREATE INDEX %s_%s_idx ON %s (%s)", table, column, table, column); } else g_string_printf(query_string, "CREATE INDEX %s_%s_idx ON %s (%s)", table, column, table, column); if (!afsql_dd_run_query(self, query_string->str, FALSE, NULL)) { msg_error("Error adding missing index", evt_tag_str("table", table), evt_tag_str("column", column), NULL); success = FALSE; } g_string_free(query_string, TRUE); return success; }
static gboolean afinet_dd_setup_addresses(AFSocketDestDriver *s) { AFInetDestDriver *self = (AFInetDestDriver *) s; if (!afsocket_dd_setup_addresses_method(s)) return FALSE; g_sockaddr_unref(self->super.bind_addr); g_sockaddr_unref(self->super.dest_addr); if (self->super.transport_mapper->address_family == AF_INET) { self->super.bind_addr = g_sockaddr_inet_new("0.0.0.0", 0); self->super.dest_addr = g_sockaddr_inet_new("0.0.0.0", 0); } #if ENABLE_IPV6 else if (self->super.transport_mapper->address_family == AF_INET6) { self->super.bind_addr = g_sockaddr_inet6_new("::", 0); self->super.dest_addr = g_sockaddr_inet6_new("::", 0); } #endif else { /* address family not known */ g_assert_not_reached(); } if ((self->bind_ip && !resolve_hostname(&self->super.bind_addr, self->bind_ip))) return FALSE; if (!resolve_hostname(&self->super.dest_addr, self->hostname)) return FALSE; if (!self->dest_port) { const gchar *port_change_warning = transport_mapper_inet_get_port_change_warning(self->super.transport_mapper); if (port_change_warning) { msg_warning(port_change_warning, evt_tag_str("id", self->super.super.super.id), NULL); } g_sockaddr_set_port(self->super.dest_addr, transport_mapper_inet_get_server_port(self->super.transport_mapper)); } else g_sockaddr_set_port(self->super.dest_addr, afinet_lookup_service(self->super.transport_mapper, self->dest_port)); return TRUE; }
static void vi_screenshot_write(char* path, int32_t* buffer, int width, int height, int output_width, int output_height) { msg_debug("screen: writing screenshot to '%s'", path); // prepare bitmap headers struct bitmap_info_header ihdr = {0}; ihdr.size = sizeof(ihdr); ihdr.width = output_width; ihdr.height = output_height; ihdr.planes = 1; ihdr.bit_count = 32; ihdr.size_image = output_width * output_height * sizeof(int32_t); struct bitmap_file_header fhdr = {0}; fhdr.type = 'B' | ('M' << 8); fhdr.off_bits = sizeof(fhdr) + sizeof(ihdr) + 10; fhdr.size = ihdr.size_image + fhdr.off_bits; FILE* fp = fopen(path, "wb"); if (!fp) { msg_warning("Can't open screenshot file %s!", path); return; } // write bitmap headers fwrite(&fhdr, sizeof(fhdr), 1, fp); fwrite(&ihdr, sizeof(ihdr), 1, fp); // write bitmap contents fseek(fp, fhdr.off_bits, SEEK_SET); // check if interpolation is required if (width != output_width || height != output_height) { // nearest-neighbor mode, copy pixel by pixel for (int32_t y = output_height - 1; y >= 0; y--) { for (int32_t x = 0; x < output_width; x++) { int ix = (int)roundf((float)x * width / output_width); int iy = (int)roundf((float)y * height / output_height); fwrite(buffer + width * iy + ix, sizeof(int32_t), 1, fp); } } } else { // direct mode, copy line by line in reverse order for (int32_t y = height - 1; y >= 0; y--) { fwrite(buffer + width * y, width * sizeof(int32_t), 1, fp); } } fclose(fp); }