inline Output copy_escaping(Input in, Input in_end, Output out, SpecialChar is_special, char escape_char='\\') { or_true_for_char<SpecialChar> need_quote(escape_char, is_special); for (; in!=in_end; ++in) { char c=*in; if (need_quote(c)) *out++=escape_char; *out = c; ++out; } return out; }
void cell(const Char *buf, size_t len) { assert(row_is_open); if (col != 0) { ++pending_seps; } ++col; if (!buf || len == 0) { return; } while (pending_seps > 0) { out(&sep,1); --pending_seps; } if ( (qchar == 0) || ((smart_quote)&&(!need_quote(buf,len)))) { out(buf,len); } else { out(&qchar,1); const Char *pos=buf; while (len>0) { if (*pos==qchar) { out(buf, pos-buf+1); // first qchar buf=pos; // qchar still there! (second one) } pos++; len--; } out(buf, pos-buf); out(&qchar,1); } }
static krb5_error_code escape_value(krb5_context context, const unsigned char *unquoted, char **quoted) { size_t i, len; for (i = 0, len = 0; unquoted[i] != '\0'; i++, len++) { if (need_quote((unsigned char)unquoted[i])) len += 2; } *quoted = malloc(len + 1); if (*quoted == NULL) { krb5_set_error_message(context, ENOMEM, "malloc: out of memory"); return ENOMEM; } for (i = 0; unquoted[0] ; unquoted++) { if (need_quote((unsigned char *)unquoted[0])) { (*quoted)[i++] = '\\'; (*quoted)[i++] = hexchar[(unquoted[0] >> 4) & 0xf]; (*quoted)[i++] = hexchar[(unquoted[0] ) & 0xf]; } else
gboolean wpa_flush_to_file (const char *config_file) { GIOChannel *channel; GError **error = NULL; gpointer key, value, ssid, security; GHashTableIter iter, iter_security; gchar *out_line; gsize bytes_written; gboolean result = FALSE; if (!wpa_parser_data_changed) return TRUE; if (!wsec_table || !wsec_global_table) return FALSE; backup_file (config_file); channel = g_io_channel_new_file (config_file, "w", NULL); if (!channel) { nm_log_warn (LOGD_SETTINGS, "Can't open file %s for writing", config_file); return FALSE; } g_hash_table_iter_init (&iter, wsec_global_table); nm_log_info (LOGD_SETTINGS, "Writing to %s", config_file); g_io_channel_write_chars (channel, "#Generated by NetworkManager\n" "###### Global Configuration ######\n", -1, &bytes_written, error); /* Writing global information */ while (g_hash_table_iter_next (&iter, &key, &value)) { out_line = g_strdup_printf ("%s=%s\n", (gchar *) key, (gchar *) value); g_io_channel_write_chars (channel, out_line, -1, &bytes_written, error); if (bytes_written == 0 || (error && *error)) break; g_free (out_line); } if (error && *error) { nm_log_warn (LOGD_SETTINGS, "Found error: %s", (*error)->message); goto done; } g_io_channel_write_chars (channel, "\n###### Security Configuration ######\n", -1, &bytes_written, error); g_hash_table_iter_init (&iter, wsec_table); /* Writing security */ while (g_hash_table_iter_next (&iter, &ssid, &security)) { g_hash_table_iter_init (&iter_security, (GHashTable *) security); g_io_channel_write_chars (channel, "network={\n", -1, &bytes_written, error); while (g_hash_table_iter_next (&iter_security, &key, &value)) { out_line = g_strdup_printf (need_quote ((gchar *) key) ? "\t%s=\"%s\"\n" : "\t%s=%s\n", (gchar *) key, (gchar *) value); g_io_channel_write_chars (channel, out_line, -1, &bytes_written, error); if (bytes_written == 0 || (error && *error)) break; g_free (out_line); } g_io_channel_write_chars (channel, "}\n\n", -1, &bytes_written, error); } if (error && *error) { nm_log_warn (LOGD_SETTINGS, "Found error: %s", (*error)->message); goto done; } g_io_channel_flush (channel, error); if (error && *error) { nm_log_warn (LOGD_SETTINGS, "Found error: %s", (*error)->message); goto done; } wpa_parser_data_changed = FALSE; result = TRUE; done: g_io_channel_shutdown (channel, FALSE, NULL); g_io_channel_unref (channel); return result; }