static GstCaps * gst_avdtp_src_getcaps (GstBaseSrc * bsrc, GstCaps * filter) { GstAvdtpSrc *avdtpsrc = GST_AVDTP_SRC (bsrc); GstCaps *caps = NULL, *ret = NULL; if (avdtpsrc->dev_caps) { const GValue *value; const char *format; int rate; GstStructure *structure = gst_caps_get_structure (avdtpsrc->dev_caps, 0); format = gst_structure_get_name (structure); if (g_str_equal (format, "audio/x-sbc")) { /* FIXME: we can return a fixed payload type once we * are in PLAYING */ caps = gst_caps_new_simple ("application/x-rtp", "media", G_TYPE_STRING, "audio", "payload", GST_TYPE_INT_RANGE, 96, 127, "encoding-name", G_TYPE_STRING, "SBC", NULL); } else if (g_str_equal (format, "audio/mpeg")) { caps = gst_caps_new_simple ("application/x-rtp", "media", G_TYPE_STRING, "audio", "payload", GST_TYPE_INT_RANGE, 96, 127, "encoding-name", G_TYPE_STRING, "MP4A-LATM", NULL); value = gst_structure_get_value (structure, "mpegversion"); if (!value || !G_VALUE_HOLDS_INT (value)) { GST_ERROR_OBJECT (avdtpsrc, "Failed to get mpegversion"); gst_caps_unref (caps); return NULL; } gst_caps_set_simple (caps, "mpegversion", G_TYPE_INT, g_value_get_int (value), NULL); value = gst_structure_get_value (structure, "channels"); if (!value || !G_VALUE_HOLDS_INT (value)) { GST_ERROR_OBJECT (avdtpsrc, "Failed to get channels"); gst_caps_unref (caps); return NULL; } gst_caps_set_simple (caps, "channels", G_TYPE_INT, g_value_get_int (value), NULL); value = gst_structure_get_value (structure, "base-profile"); if (!value || !G_VALUE_HOLDS_STRING (value)) { GST_ERROR_OBJECT (avdtpsrc, "Failed to get base-profile"); gst_caps_unref (caps); return NULL; } gst_caps_set_simple (caps, "base-profile", G_TYPE_STRING, g_value_get_string (value), NULL); } else { GST_ERROR_OBJECT (avdtpsrc, "Only SBC and MPEG-2/4 are supported at the moment"); } value = gst_structure_get_value (structure, "rate"); if (!value || !G_VALUE_HOLDS_INT (value)) { GST_ERROR_OBJECT (avdtpsrc, "Failed to get sample rate"); gst_caps_unref (caps); return NULL; } rate = g_value_get_int (value); gst_caps_set_simple (caps, "clock-rate", G_TYPE_INT, rate, NULL); if (filter) { ret = gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST); gst_caps_unref (caps); } else ret = caps; } else { GST_DEBUG_OBJECT (avdtpsrc, "device not open, using template caps"); ret = GST_BASE_SRC_CLASS (parent_class)->get_caps (bsrc, filter); } return ret; }
static gboolean set_baud(const char *baud, struct termios *ti) { speed_t speed; if (g_str_equal(baud, "300")) speed = B300; else if (g_str_equal(baud, "1200")) speed = B1200; else if (g_str_equal(baud, "2400")) speed = B2400; else if (g_str_equal(baud, "4800")) speed = B4800; else if (g_str_equal(baud, "9600")) speed = B9600; else if (g_str_equal(baud, "19200")) speed = B19200; else if (g_str_equal(baud, "38400")) speed = B38400; else if (g_str_equal(baud, "57600")) speed = B57600; else if (g_str_equal(baud, "115200")) speed = B115200; else if (g_str_equal(baud, "230400")) speed = B230400; else if (g_str_equal(baud, "460800")) speed = B460800; else if (g_str_equal(baud, "500000")) speed = B500000; else if (g_str_equal(baud, "576000")) speed = B576000; else if (g_str_equal(baud, "921600")) speed = B921600; else if (g_str_equal(baud, "1000000")) speed = B1000000; else if (g_str_equal(baud, "1152000")) speed = B1152000; else if (g_str_equal(baud, "1500000")) speed = B1500000; else if (g_str_equal(baud, "2000000")) speed = B2000000; #ifdef B2500000 else if (g_str_equal(baud, "2500000")) speed = B2500000; #endif #ifdef B3000000 else if (g_str_equal(baud, "3000000")) speed = B3000000; #endif #ifdef B3500000 else if (g_str_equal(baud, "3500000")) speed = B3500000; #endif #ifdef B4000000 else if (g_str_equal(baud, "4000000")) speed = B4000000; #endif else return FALSE; cfsetospeed(ti, speed); cfsetispeed(ti, speed); return TRUE; }
static GString *append_listing(GString *object, const char *name, gboolean pcsuite, size_t *size, int *err) { struct stat fstat, dstat; struct dirent *ep; DIR *dp; gboolean root; int ret; root = g_str_equal(name, obex_option_root_folder()); dp = opendir(name); if (dp == NULL) { if (err) *err = -ENOENT; goto failed; } if (root) object = g_string_append(object, FL_PARENT_FOLDER_ELEMENT); ret = verify_path(name); if (ret < 0) { *err = ret; goto failed; } ret = stat(name, &dstat); if (ret < 0) { if (err) *err = -errno; goto failed; } while ((ep = readdir(dp))) { char *filename; char *fullname; char *line; if (ep->d_name[0] == '.') continue; filename = g_filename_to_utf8(ep->d_name, -1, NULL, NULL, NULL); if (name == NULL) { error("g_filename_to_utf8: invalid filename"); continue; } fullname = g_build_filename(name, ep->d_name, NULL); ret = stat(fullname, &fstat); if (ret < 0) { DBG("stat: %s(%d)", strerror(errno), errno); g_free(filename); g_free(fullname); continue; } g_free(fullname); line = file_stat_line(filename, &fstat, &dstat, root, FALSE); if (line == NULL) { g_free(filename); continue; } g_free(filename); object = g_string_append(object, line); g_free(line); } closedir(dp); object = g_string_append(object, FL_BODY_END); if (size) *size = object->len; if (err) *err = 0; return object; failed: if (dp) closedir(dp); g_string_free(object, TRUE); return NULL; }
static void handle_controller_message (SnraClient * client, GstStructure * s) { const gchar *msg_type; msg_type = gst_structure_get_string (s, "msg-type"); if (msg_type == NULL || g_str_equal (msg_type, "ping")) return; if (g_str_equal (msg_type, "enrol")) handle_controller_enrol_message (client, s); else if (g_str_equal (msg_type, "player-clients-changed")) refresh_clients_array (client); else if (g_str_equal (msg_type, "client-setting")) handle_controller_client_setting_message (client, s); else if (g_str_equal (msg_type, "client-volume")) handle_controller_client_volume_message (client, s); else if (g_str_equal (msg_type, "volume")) handle_controller_volume_message (client, s); else if (g_str_equal (msg_type, "play")) handle_controller_play_message (client, s); else if (g_str_equal (msg_type, "pause")) handle_controller_pause_message (client, s); else if (g_str_equal (msg_type, "seek")) handle_controller_seek_message (client, s); else if (g_str_equal (msg_type, "set-media")) handle_controller_set_media_message (client, s); else if (g_str_equal (msg_type, "language")) handle_controller_language_message (client, s); else g_print ("Unhandled contorller event of type %s\n", msg_type); }
gboolean ostree_builtin_static_delta (int argc, char **argv, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; OstreeCommand *command = NULL; const char *cmdname = NULL; glnx_unref_object OstreeRepo *repo = NULL; int i; gboolean want_help = FALSE; for (i = 1; i < argc; i++) { if (argv[i][0] != '-') { cmdname = argv[i]; break; } else if (g_str_equal (argv[i], "--help") || g_str_equal (argv[i], "-h")) { want_help = TRUE; break; } } if (!cmdname && !want_help) { static_delta_usage (argv, TRUE); g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, "No command specified"); goto out; } if (cmdname) { command = static_delta_subcommands; while (command->name) { if (g_strcmp0 (cmdname, command->name) == 0) break; command++; } } if (want_help && command == NULL) { static_delta_usage (argv, FALSE); ret = TRUE; goto out; } if (!command->fn) { g_autofree char *msg = g_strdup_printf ("Unknown command '%s'", cmdname); static_delta_usage (argv, TRUE); g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, msg); goto out; } if (!command->fn (argc, argv, cancellable, error)) goto out; ret = TRUE; out: return ret; }
static int create_configuration(DBusMessage *msg, connection_ready_cb callback) { DBusMessage *new_msg = NULL; DBusPendingCall *call; DBusMessageIter iter, array, new_iter, new_dict; const char *type = NULL, *name = NULL; const char *host = NULL, *domain = NULL; char *ident, *me = NULL; int err = 0; dbus_bool_t result; struct connection_data *data; struct config_create_data *user_data = NULL; GSList *networks = NULL; /* * We copy the old message data into new message. We cannot * just use the old message as is because the user route * information is not in the same format in vpnd. */ new_msg = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_CALL); dbus_message_iter_init_append(new_msg, &new_iter); connman_dbus_dict_open(&new_iter, &new_dict); dbus_message_iter_init(msg, &iter); dbus_message_iter_recurse(&iter, &array); while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_DICT_ENTRY) { DBusMessageIter entry, value; void *item_value; const char *key; int value_type; dbus_message_iter_recurse(&array, &entry); dbus_message_iter_get_basic(&entry, &key); dbus_message_iter_next(&entry); dbus_message_iter_recurse(&entry, &value); value_type = dbus_message_iter_get_arg_type(&value); item_value = NULL; switch (value_type) { case DBUS_TYPE_STRING: dbus_message_iter_get_basic(&value, &item_value); if (g_str_equal(key, "Type") == TRUE) { type = (const char *)item_value; } else if (g_str_equal(key, "Name") == TRUE) { name = (const char *)item_value; } else if (g_str_equal(key, "Host") == TRUE) { host = (const char *)item_value; } else if (g_str_equal(key, "VPN.Domain") == TRUE) { domain = (const char *)item_value; } DBG("%s %s", key, (char *)item_value); if (item_value != NULL) connman_dbus_dict_append_basic(&new_dict, key, value_type, &item_value); break; case DBUS_TYPE_ARRAY: if (g_str_equal(key, "Networks") == TRUE) { networks = get_user_networks(&value); connman_dbus_dict_append_array(&new_dict, "UserRoutes", DBUS_TYPE_DICT_ENTRY, append_routes, networks); } break; } dbus_message_iter_next(&array); } connman_dbus_dict_close(&new_iter, &new_dict); DBG("VPN type %s name %s host %s domain %s networks %p", type, name, host, domain, networks); if (host == NULL || domain == NULL) { err = -EINVAL; goto done; } if (type == NULL || name == NULL) { err = -EOPNOTSUPP; goto done; } ident = g_strdup_printf("%s_%s", host, domain); set_dbus_ident(ident); DBG("ident %s", ident); data = g_hash_table_lookup(vpn_connections, ident); if (data != NULL) { if (data->call != NULL || data->cb_data != NULL) { DBG("create configuration call already pending"); err = -EINPROGRESS; goto done; } } else { char *path = g_strdup_printf("%s/connection/%s", VPN_PATH, ident); data = create_connection_data(path); g_free(path); if (data == NULL) { err = -ENOMEM; goto done; } g_hash_table_insert(vpn_connections, g_strdup(ident), data); } /* * User called net.connman.Manager.ConnectProvider if we are here. * So use the data from original message in the new msg. */ me = g_strdup(dbus_message_get_destination(msg)); dbus_message_set_interface(new_msg, VPN_MANAGER_INTERFACE); dbus_message_set_path(new_msg, "/"); dbus_message_set_destination(new_msg, VPN_SERVICE); dbus_message_set_sender(new_msg, me); dbus_message_set_member(new_msg, "Create"); user_data = g_try_new0(struct config_create_data, 1); if (user_data == NULL) { err = -ENOMEM; goto done; } user_data->callback = callback; user_data->message = dbus_message_ref(msg); user_data->path = NULL; DBG("cb %p msg %p", user_data, msg); result = dbus_connection_send_with_reply(connection, new_msg, &call, DBUS_TIMEOUT); if (result == FALSE || call == NULL) { err = -EIO; goto done; } dbus_pending_call_set_notify(call, configuration_create_reply, user_data, NULL); data->call = call; done: if (new_msg != NULL) dbus_message_unref(new_msg); if (networks != NULL) g_slist_free_full(networks, destroy_route); g_free(me); return err; }
static void add_connection(const char *path, DBusMessageIter *properties, void *user_data) { struct connection_data *data; int err; char *ident = get_ident(path); connman_bool_t found = FALSE; data = g_hash_table_lookup(vpn_connections, ident); if (data != NULL) { /* * We might have a dummy connection struct here that * was created by configuration_create_reply() so in * that case just continue. */ if (data->connect_pending == FALSE) return; found = TRUE; } else { data = create_connection_data(path); if (data == NULL) return; } DBG("data %p path %s", data, path); while (dbus_message_iter_get_arg_type(properties) == DBUS_TYPE_DICT_ENTRY) { DBusMessageIter entry, value; const char *key; char *str; dbus_message_iter_recurse(properties, &entry); dbus_message_iter_get_basic(&entry, &key); dbus_message_iter_next(&entry); dbus_message_iter_recurse(&entry, &value); if (g_str_equal(key, "State") == TRUE) { dbus_message_iter_get_basic(&value, &str); DBG("state %s -> %s", data->state, str); data->state = g_strdup(str); } else if (g_str_equal(key, "IPv4") == TRUE) { extract_ip(&value, AF_INET, data); } else if (g_str_equal(key, "IPv6") == TRUE) { extract_ip(&value, AF_INET6, data); } else if (g_str_equal(key, "Name") == TRUE) { dbus_message_iter_get_basic(&value, &str); data->name = g_strdup(str); } else if (g_str_equal(key, "Type") == TRUE) { dbus_message_iter_get_basic(&value, &str); data->type = g_strdup(str); } else if (g_str_equal(key, "Host") == TRUE) { dbus_message_iter_get_basic(&value, &str); data->host = g_strdup(str); } else if (g_str_equal(key, "Domain") == TRUE) { dbus_message_iter_get_basic(&value, &str); data->domain = g_strdup(str); } else if (g_str_equal(key, "Nameservers") == TRUE) { extract_nameservers(&value, data); } else if (g_str_equal(key, "Index") == TRUE) { dbus_message_iter_get_basic(&value, &data->index); } else { if (dbus_message_iter_get_arg_type(&value) == DBUS_TYPE_STRING) { dbus_message_iter_get_basic(&value, &str); g_hash_table_replace(data->setting_strings, g_strdup(key), g_strdup(str)); } else { DBG("unknown key %s", key); } } dbus_message_iter_next(properties); } if (found == FALSE) g_hash_table_insert(vpn_connections, g_strdup(data->ident), data); err = create_provider(data, user_data); if (err < 0) goto out; resolv_host_addr(data); if (data->connect_pending == TRUE) connect_provider(data, data->cb_data); return; out: DBG("removing %s", data->ident); g_hash_table_remove(vpn_connections, data->ident); }
static gboolean openssl_setup(liServer *srv, liPlugin* p, liValue *val, gpointer userdata) { openssl_context *ctx; GHashTableIter hti; gpointer hkey, hvalue; GString *htkey; liValue *htval; STACK_OF(X509_NAME) *client_ca_list; liValue *v; /* setup defaults */ GString *ipstr = NULL; const char *ciphers = "ECDHE-RSA-AES256-SHA384:AES256-SHA256:RC4-SHA:RC4:HIGH:!MD5:!aNULL:!EDH:!AESGCM", *pemfile = NULL, *ca_file = NULL, *client_ca_file = NULL; long options = SSL_OP_NO_SSLv2 | SSL_OP_CIPHER_SERVER_PREFERENCE #ifdef SSL_OP_NO_COMPRESSION | SSL_OP_NO_COMPRESSION #endif ; guint verify_mode = 0, verify_depth = 1; gboolean verify_any = FALSE; UNUSED(p); UNUSED(userdata); if (val->type != LI_VALUE_HASH) { ERROR(srv, "%s", "openssl expects a hash as parameter"); return FALSE; } g_hash_table_iter_init(&hti, val->data.hash); while (g_hash_table_iter_next(&hti, &hkey, &hvalue)) { htkey = hkey; htval = hvalue; if (g_str_equal(htkey->str, "listen")) { if (htval->type != LI_VALUE_STRING) { ERROR(srv, "%s", "openssl listen expects a string as parameter"); return FALSE; } ipstr = htval->data.string; } else if (g_str_equal(htkey->str, "pemfile")) { if (htval->type != LI_VALUE_STRING) { ERROR(srv, "%s", "openssl pemfile expects a string as parameter"); return FALSE; } pemfile = htval->data.string->str; } else if (g_str_equal(htkey->str, "ca-file")) { if (htval->type != LI_VALUE_STRING) { ERROR(srv, "%s", "openssl ca-file expects a string as parameter"); return FALSE; } ca_file = htval->data.string->str; } else if (g_str_equal(htkey->str, "ciphers")) { if (htval->type != LI_VALUE_STRING) { ERROR(srv, "%s", "openssl ciphers expects a string as parameter"); return FALSE; } ciphers = htval->data.string->str; } else if (g_str_equal(htkey->str, "options")) { guint i; if (htval->type != LI_VALUE_LIST) { ERROR(srv, "%s", "openssl options expects a list of strings as parameter"); return FALSE; } for (i = 0; i < htval->data.list->len; i++) { v = g_array_index(htval->data.list, liValue*, i); if (v->type != LI_VALUE_STRING) { ERROR(srv, "%s", "openssl options expects a list of strings as parameter"); return FALSE; } if (!openssl_options_set_string(&options, v->data.string)) { ERROR(srv, "openssl option unknown: %s", v->data.string->str); return FALSE; } } } else if (g_str_equal(htkey->str, "verify")) {
gint checksum_file_list_parse_checksum_file (CheckcopyFileList * list, GFile *root, GFile *file) { CheckcopyFileListPrivate *priv = GET_PRIVATE (list); GDataInputStream * in; gchar * line; gsize length; GCancellable *cancel; GError * error = NULL; GFile * parent; gchar * prefix; gint n = 0; cancel = checkcopy_get_cancellable (); parent = g_file_get_parent (file); prefix = g_file_get_relative_path (root, parent); in = g_data_input_stream_new (G_INPUT_STREAM (g_file_read (file, cancel, &error))); while ((line = g_data_input_stream_read_line (in, &length, cancel, &error)) != NULL) { gchar *c; if (*line == ';' || *line == '#') { /* skip comment lines */ continue; } /* find the end of the first column */ for (c = line; *c != ' ' && *c != '\0'; c++); /* make sure we found some chars and we don't just have one column */ if (c != line && *c != '\0') { gchar * checksum = NULL; gchar * filename = NULL; CheckcopyFileInfo * info; CheckcopyChecksumType checksum_type; /* found a checksum, parse the line into * checksum and filename */ n++; *c = '\0'; c++; checksum = g_strdup (line); checksum_type = checkcopy_file_info_get_checksum_type (line); /* skip spaces */ while (*c == ' ' && *c != '\0') c++; /* some programs mark filenames with a star */ if (*c == '*') c++; /* rest of the line is the file name */ if (prefix != NULL && *prefix != '\0') filename = g_strconcat (prefix, G_DIR_SEPARATOR_S, c, NULL); else filename = g_strdup (c); info = checkcopy_file_list_grab_info (list, filename); if (info->status == CHECKCOPY_STATUS_NONE) { info->checksum = checksum; info->checksum_type = checksum_type; checkcopy_file_list_transition (list, info, CHECKCOPY_STATUS_VERIFIABLE); DBG ("Parsed checksum for %s", info->relname); if (priv->verify_only) { checkcopy_worker_add_file (g_file_resolve_relative_path (root, filename)); } } else { /* We saw the file before the checksum. * * Verify it now. */ DBG ("%s was copied already, verifying it immediately", filename); if (!g_str_equal (info->checksum, checksum)) { /* Verification failed. We want to display the checksum * the file is supposed to have in the gui, so switch * the two variables. */ gchar * ts; ts = info->checksum; info->checksum = checksum; checksum = ts; /* TODO: display the checksum which the file actually has */ g_free (checksum); checkcopy_file_list_transition (list, info, CHECKCOPY_STATUS_VERIFICATION_FAILED); } } } g_free (line); } g_object_unref (parent); g_free (prefix); g_input_stream_close (G_INPUT_STREAM (in), cancel, &error); return n; }
static void ide_recent_projects_load_recent (IdeRecentProjects *self) { g_autoptr(GBookmarkFile) projects_file; g_autoptr(GError) error = NULL; gchar **uris; gssize z; g_assert (IDE_IS_RECENT_PROJECTS (self)); projects_file = ide_recent_projects_get_bookmarks (self, &error); if (projects_file == NULL) { g_warning ("Unable to open recent projects file: %s", error->message); return; } uris = g_bookmark_file_get_uris (projects_file, NULL); for (z = 0; uris[z]; z++) { g_autoptr(GDateTime) last_modified_at = NULL; g_autoptr(GFile) project_file = NULL; g_autoptr(GFile) directory = NULL; g_autoptr(GPtrArray) languages = NULL; g_autoptr(IdeProjectInfo) project_info = NULL; const gchar *description; const gchar *uri = uris[z]; const gchar *name; time_t modified; gchar **groups; gsize len; gsize i; groups = g_bookmark_file_get_groups (projects_file, uri, &len, NULL); for (i = 0; i < len; i++) { if (g_str_equal (groups [i], IDE_RECENT_PROJECTS_GROUP)) goto is_project; } continue; is_project: name = g_bookmark_file_get_title (projects_file, uri, NULL); description = g_bookmark_file_get_description (projects_file, uri, NULL); modified = g_bookmark_file_get_modified (projects_file, uri, NULL); last_modified_at = g_date_time_new_from_unix_local (modified); project_file = g_file_new_for_uri (uri); directory = g_file_get_parent (project_file); languages = g_ptr_array_new (); for (i = 0; i < len; i++) { if (g_str_has_prefix (groups [i], IDE_RECENT_PROJECTS_LANGUAGE_GROUP_PREFIX)) g_ptr_array_add (languages, groups [i] + strlen (IDE_RECENT_PROJECTS_LANGUAGE_GROUP_PREFIX)); } g_ptr_array_add (languages, NULL); project_info = g_object_new (IDE_TYPE_PROJECT_INFO, "description", description, "directory", directory, "file", project_file, "is-recent", TRUE, "languages", (gchar **)languages->pdata, "last-modified-at", last_modified_at, "name", name, NULL); ide_recent_projects_added (self, project_info); g_hash_table_insert (self->recent_uris, g_strdup (uri), NULL); } g_strfreev (uris); }
int main( int argc, char ** argv) { config_overrides_t *cfg_ovr; char *hostname; char *auth; char *service; char *config = NULL; int opt; extern int optind; extern char *optarg; FILE *input_file; int use_connect = 0; int got_input_file = 0; int i; unsigned char gfd[32768]; glib_init(); /* * Configure program for internationalization: * 1) Only set the message locale for now. * 2) Set textdomain for all amanda related programs to "amanda" * We don't want to be forced to support dozens of message catalogs. */ setlocale(LC_MESSAGES, "C"); textdomain("amanda"); // safe_fd(-1, 0); safe_cd(); set_pname("amservice"); /* drop root privileges */ if (!set_root_privs(0)) { error(_("amservice must be run setuid root")); } /* Don't die when child closes pipe */ signal(SIGPIPE, SIG_IGN); dbopen(DBG_SUBDIR_SERVER); add_amanda_log_handler(amanda_log_stderr); our_features = am_init_feature_set(); our_feature_string = am_feature_to_string(our_features); /* process arguments */ for (i=0; i<argc; i++) { g_debug("argv[%d] = %s", i, argv[i]); } for (i = 0;i < 32768; i++) { gfd[i] = 0; } cfg_ovr = new_config_overrides(argc/2); input_file = stdin; while((opt = getopt_long(argc, argv, "o:f:s", long_options, NULL)) != EOF) { switch(opt) { case 1: printf("amservice-%s\n", VERSION); return(0); break; case 2: g_free(our_feature_string); g_free(our_features); our_feature_string = g_strdup(optarg); our_features = am_string_to_feature(our_feature_string); break; case 3: { gchar *copy_optarg = g_strdup(optarg); gchar *coma = strchr(copy_optarg, ','); gchar *stream_in; if (nb_lstream == DATA_FD_COUNT) { g_critical("Too many --stream, maximum is %d", DATA_FD_COUNT); exit(1); } else if (coma) { *coma++ = '\0'; stream_in = coma; coma = strchr(coma, ','); if (coma) { *coma++ = '\0'; lstreams[nb_lstream].name = g_strdup(copy_optarg); lstreams[nb_lstream].fd_in = atoi(stream_in); lstreams[nb_lstream].fd_out = atoi(coma); gfd[lstreams[nb_lstream].fd_in] = 1; gfd[lstreams[nb_lstream].fd_out] = 1; nb_lstream++; } } if (!coma) { g_critical("Invalid --stream option (%s)", optarg); exit(1); } g_free(copy_optarg); break; } case 4: g_free(config); config = g_strdup(optarg); break; case 'o': add_config_override_opt(cfg_ovr, optarg); break; case 'f': if (got_input_file == 1) { g_critical("Invalid two -f argument"); exit(1); } got_input_file = 1; if (*optarg == '/') { input_file = fopen(optarg, "r"); } else { char *name = g_strjoin(NULL, get_original_cwd(), "/", optarg, NULL); input_file = fopen(name, "r"); amfree(name); } if (!input_file) { g_critical("Cannot open input file '%s': %s", optarg, strerror(errno)); exit(1); } break; case 's': use_connect = 1; break; } } if (use_connect && !got_input_file) { g_critical("The -s option require -f"); exit(1); } /* close all unused fd */ for (i = 3;i < 32768; i++) { if (gfd[i] == 0 && i != dbfd() && (!got_input_file || i != fileno(input_file))) { close(i); } } argc -= optind, argv += optind; if(argc < 3) usage(); /* set a default config */ set_config_overrides(cfg_ovr); config_init(CONFIG_INIT_CLIENT|CONFIG_INIT_GLOBAL, NULL); if (config) { config_init(CONFIG_INIT_CLIENT | CONFIG_INIT_EXPLICIT_NAME | CONFIG_INIT_OVERLAY, config); } dbrename(get_config_name(), DBG_SUBDIR_SERVER); if (config_errors(NULL) >= CFGERR_WARNINGS) { config_print_errors(); if (config_errors(NULL) >= CFGERR_ERRORS) { g_critical(_("errors processing config file")); } } conf_ctimeout = (time_t)getconf_int(CNF_CTIMEOUT); hostname = argv[0]; auth = argv[1]; if (g_str_equal(auth,"NULL")) { auth = getconf_str(CNF_AUTH); } service = argv[2]; /* start client side checks */ copy_stream = use_connect && got_input_file; client_protocol(hostname, auth, service, config, input_file); amfree(our_feature_string); am_release_feature_set(our_features); our_features = NULL; if (got_input_file) fclose(input_file); dbclose(); return(remote_errors != 0); }
static void _reset_thumbnail (MexContentTile *tile) { MexContentTilePrivate *priv = tile->priv; MexDownloadQueue *queue = mex_download_queue_get_default (); const gchar *mime = NULL; gchar *placeholder_filename = NULL; queue = mex_download_queue_get_default (); /* cancel any download already in progress */ if (priv->download_id) { mex_download_queue_cancel (queue, priv->download_id); priv->download_id = NULL; } priv->thumbnail_loaded = FALSE; /* Load placeholder image */ if (priv->content) mime = mex_content_get_metadata (priv->content, MEX_CONTENT_METADATA_MIMETYPE); if (mime && g_str_has_prefix (mime, "image/")) { placeholder_filename = "thumb-image.png"; } else if (mime && g_str_equal (mime, "x-mex/tv")) { placeholder_filename = "thumb-tv.png"; } else if (mime && g_str_equal (mime, "video/dvd")) { placeholder_filename = "thumb-disc.png"; } else if (mime && (g_str_has_prefix (mime, "video/") || g_str_equal (mime, "x-mex/media"))) { placeholder_filename = "thumb-video.png"; } else if (mime && (g_str_has_prefix (mime, "audio/"))) { placeholder_filename = "thumb-music.png"; } else if (mime && g_str_equal (mime, "x-grl/box")) { placeholder_filename = "folder-tile.png"; } else if (mime && g_str_equal (mime, "x-mex/group")) { placeholder_filename = "folder-tile.png"; } else if (mime && g_str_equal (mime, "x-mex/app")) { placeholder_filename = "thumb-app.png"; } if (placeholder_filename) { gchar *tmp; const gchar *dir = mex_get_data_dir (); tmp = g_build_filename (dir, "style", placeholder_filename, NULL); _update_thumbnail_from_image (tile, tmp); g_free (tmp); } else { mx_image_clear (MX_IMAGE (priv->image)); /* Reset the height - really, we ought to reset the width and height, * but for all our use-cases, we want to keep the set width. */ clutter_actor_set_height (priv->image, -1); priv->image_set = FALSE; return; } clutter_actor_set_size (priv->image, priv->thumb_width, priv->thumb_height); }
static gboolean managedstring_equal( Managedstring *a, Managedstring *b ) { return( ((Managed *) a)->heap == ((Managed *) b)->heap && g_str_equal( a->string, b->string ) ); }
/* Returns: TRUE if the notifier was created, FALSE if it was already existing. */ static gboolean gconf_settings_backend_add_notifier (GConfSettingsBackend *gconf, const gchar *path) { GConfSettingsBackendNotifier *n_or_p; GConfSettingsBackendNotifier *notifier; GSList *siblings; GSList *l; n_or_p = gconf_settings_backend_find_notifier_or_parent (gconf, path); if (n_or_p && g_str_equal (path, n_or_p->path)) { n_or_p->refcount += 1; return FALSE; } notifier = g_slice_new0 (GConfSettingsBackendNotifier); notifier->parent = n_or_p; notifier->path = g_strdup (path); notifier->refcount = 1; if (notifier->parent == NULL) notifier->notify_id = gconf_client_notify_add (gconf->priv->client, path, (GConfClientNotifyFunc) gconf_settings_backend_notified, gconf, NULL, NULL); else notifier->notify_id = 0; /* Move notifiers living at the same level but that are subpaths below this * new notifier, removing their notify handler if necessary. */ if (notifier->parent) siblings = notifier->parent->subpaths; else siblings = gconf->priv->notifiers; l = siblings; while (l != NULL) { GConfSettingsBackendNotifier *sibling; GSList *next; sibling = l->data; next = l->next; if (g_str_has_prefix (sibling->path, notifier->path)) { if (sibling->notify_id) { gconf_client_notify_remove (gconf->priv->client, sibling->notify_id); sibling->notify_id = 0; } siblings = g_slist_remove_link (siblings, l); l->next = notifier->subpaths; notifier->subpaths = l; } l = next; } siblings = g_slist_prepend (siblings, notifier); if (notifier->parent) notifier->parent->subpaths = siblings; else gconf->priv->notifiers = siblings; return TRUE; }
static void list_update_property (const gchar *property, GValue *value, gpointer user_data) { CarrickList *list = user_data; CarrickListPrivate *priv = list->priv; if (g_str_equal (property, "OfflineMode")) { priv->offline_mode = g_value_get_boolean (value); } else if (g_str_equal (property, "AvailableTechnologies")) { gchar **tech = g_value_get_boxed (value); gint i; priv->have_wifi = FALSE; priv->have_ethernet = FALSE; priv->have_threeg = FALSE; priv->have_wimax = FALSE; priv->have_bluetooth = FALSE; for (i = 0; i < g_strv_length (tech); i++) { if (g_str_equal ("wifi", *(tech + i))) priv->have_wifi = TRUE; else if (g_str_equal ("wimax", *(tech + i))) priv->have_wimax = TRUE; else if (g_str_equal ("bluetooth", *(tech + i))) priv->have_bluetooth = TRUE; else if (g_str_equal ("cellular", *(tech + i))) priv->have_threeg = TRUE; else if (g_str_equal ("ethernet", *(tech + i))) priv->have_ethernet = TRUE; } } else if (g_str_equal (property, "EnabledTechnologies")) { gchar **tech = g_value_get_boxed (value); gint i; priv->wifi_enabled = FALSE; priv->ethernet_enabled = FALSE; priv->threeg_enabled = FALSE; priv->wimax_enabled = FALSE; priv->bluetooth_enabled = FALSE; for (i = 0; i < g_strv_length (tech); i++) { if (g_str_equal ("wifi", *(tech + i))) priv->wifi_enabled = TRUE; else if (g_str_equal ("wimax", *(tech + i))) priv->wimax_enabled = TRUE; else if (g_str_equal ("bluetooth", *(tech + i))) priv->bluetooth_enabled = TRUE; else if (g_str_equal ("cellular", *(tech + i))) priv->threeg_enabled = TRUE; else if (g_str_equal ("ethernet", *(tech + i))) priv->ethernet_enabled = TRUE; } } }
static void device_added (MMBaseManager *manager, GUdevDevice *port, gboolean hotplugged, gboolean manual_scan) { MMDevice *device; const char *subsys, *name, *physdev_path, *physdev_subsys; gboolean is_candidate; GUdevDevice *physdev = NULL; g_return_if_fail (port != NULL); subsys = g_udev_device_get_subsystem (port); name = g_udev_device_get_name (port); /* ignore VTs */ if (strncmp (name, "tty", 3) == 0 && isdigit (name[3])) return; /* Ignore devices that aren't completely configured by udev yet. If * ModemManager is started in parallel with udev, explicitly requesting * devices may return devices for which not all udev rules have yet been * applied (a bug in udev/gudev). Since we often need those rules to match * the device to a specific ModemManager driver, we need to ensure that all * rules have been processed before handling a device. */ is_candidate = g_udev_device_get_property_as_boolean (port, "ID_MM_CANDIDATE"); if (!is_candidate) { /* This could mean that device changed, loosing its ID_MM_CANDIDATE * flags (such as Bluetooth RFCOMM devices upon disconnect. * Try to forget it. */ if (hotplugged && !manual_scan) device_removed (manager, port); return; } if (find_device_by_port (manager, port)) return; /* Find the port's physical device's sysfs path. This is the kernel device * that "owns" all the ports of the device, like the USB device or the PCI * device the provides each tty or network port. */ physdev = find_physical_device (port); if (!physdev) { /* Warn about it, but filter out some common ports that we know don't have * anything to do with mobile broadband. */ if ( strcmp (name, "console") && strcmp (name, "ptmx") && strcmp (name, "lo") && strcmp (name, "tty") && !strstr (name, "virbr")) mm_dbg ("(%s/%s): could not get port's parent device", subsys, name); goto out; } /* Is the device blacklisted? */ if (g_udev_device_get_property_as_boolean (physdev, "ID_MM_DEVICE_IGNORE")) { mm_dbg ("(%s/%s): port's parent device is blacklisted", subsys, name); goto out; } /* Is the device in the manual-only greylist? If so, return if this is an * automatic scan. */ if (!manual_scan && g_udev_device_get_property_as_boolean (physdev, "ID_MM_DEVICE_MANUAL_SCAN_ONLY")) { mm_dbg ("(%s/%s): port probed only in manual scan", subsys, name); goto out; } /* If the physdev is a 'platform' or 'pnp' device that's not whitelisted, ignore it */ physdev_subsys = g_udev_device_get_subsystem (physdev); if ( physdev_subsys && ( g_str_equal (physdev_subsys, "platform") || g_str_equal (physdev_subsys, "pnp")) && !g_udev_device_get_property_as_boolean (physdev, "ID_MM_PLATFORM_DRIVER_PROBE")) { mm_dbg ("(%s/%s): port's parent platform driver is not whitelisted", subsys, name); goto out; } physdev_path = g_udev_device_get_sysfs_path (physdev); if (!physdev_path) { mm_dbg ("(%s/%s): could not get port's parent device sysfs path", subsys, name); goto out; } /* See if we already created an object to handle ports in this device */ device = find_device_by_sysfs_path (manager, physdev_path); if (!device) { FindDeviceSupportContext *ctx; /* Keep the device listed in the Manager */ device = mm_device_new (physdev, hotplugged); g_hash_table_insert (manager->priv->devices, g_strdup (physdev_path), device); /* Launch device support check */ ctx = g_slice_new (FindDeviceSupportContext); ctx->self = g_object_ref (manager); ctx->device = g_object_ref (device); mm_plugin_manager_find_device_support ( manager->priv->plugin_manager, device, (GAsyncReadyCallback)find_device_support_ready, ctx); } /* Grab the port in the existing device. */ mm_device_grab_port (device, port); out: if (physdev) g_object_unref (physdev); }
static void amindexd_response( void *datap, pkt_t *pkt, security_handle_t *sech) { int ports[NSTREAMS], *response_error = datap; guint i; char *p; char *tok; char *extra = NULL; assert(response_error != NULL); assert(sech != NULL); if (pkt == NULL) { g_free(errstr); errstr = g_strdup_printf(_("[request failed: %s]"), security_geterror(sech)); *response_error = 1; return; } if (pkt->type == P_NAK) { #if defined(PACKET_DEBUG) dbprintf(_("got nak response:\n----\n%s\n----\n\n"), pkt->body); #endif tok = strtok(pkt->body, " "); if (tok == NULL || !g_str_equal(tok, "ERROR")) goto bad_nak; tok = strtok(NULL, "\n"); if (tok != NULL) { g_free(errstr); errstr = g_strdup_printf("NAK: %s", tok); *response_error = 1; } else { bad_nak: g_free(errstr); errstr = g_strdup("request NAK"); *response_error = 2; } return; } if (pkt->type != P_REP) { g_free(errstr); errstr = g_strdup_printf(_("received strange packet type %s: %s"), pkt_type2str(pkt->type), pkt->body); *response_error = 1; return; } #if defined(PACKET_DEBUG) g_fprintf(stderr, _("got response:\n----\n%s\n----\n\n"), pkt->body); #endif for(i = 0; i < NSTREAMS; i++) { ports[i] = -1; streams[i].fd = NULL; } p = pkt->body; while((tok = strtok(p, " \n")) != NULL) { p = NULL; /* * Error response packets have "ERROR" followed by the error message * followed by a newline. */ if (g_str_equal(tok, "ERROR")) { tok = strtok(NULL, "\n"); if (tok == NULL) { g_free(errstr); errstr = g_strdup("[bogus error packet]"); } else { g_free(errstr); errstr = g_strdup_printf("%s", tok); } *response_error = 2; return; } /* * Regular packets have CONNECT followed by three streams */ if (g_str_equal(tok, "CONNECT")) { /* * Parse the three stream specifiers out of the packet. */ for (i = 0; i < NSTREAMS; i++) { tok = strtok(NULL, " "); if (tok == NULL || !g_str_equal(tok, streams[i].name)) { extra = g_strdup_printf( _("CONNECT token is \"%s\": expected \"%s\""), tok ? tok : _("(null)"), streams[i].name); goto parse_error; } tok = strtok(NULL, " \n"); if (tok == NULL || sscanf(tok, "%d", &ports[i]) != 1) { extra = g_strdup_printf( _("CONNECT %s token is \"%s\" expected a port number"), streams[i].name, tok ? tok : _("(null)")); goto parse_error; } } continue; } /* * OPTIONS [options string] '\n' */ if (g_str_equal(tok, "OPTIONS")) { tok = strtok(NULL, "\n"); if (tok == NULL) { extra = g_strdup(_("OPTIONS token is missing")); goto parse_error; } #if 0 tok_end = tok + strlen(tok); while((p = strchr(tok, ';')) != NULL) { *p++ = '\0'; if(strncmp_const(tok, "features=") == 0) { tok += sizeof("features=") - 1; am_release_feature_set(their_features); if((their_features = am_string_to_feature(tok)) == NULL) { errstr = newvstrallocf(errstr, _("OPTIONS: bad features value: %s"), tok); goto parse_error; } } tok = p; } #endif continue; } #if 0 extra = g_strdup_printf(_("next token is \"%s\": expected \"CONNECT\", \"ERROR\" or \"OPTIONS\""), tok ? tok : _("(null)")); goto parse_error; #endif } /* * Connect the streams to their remote ports */ for (i = 0; i < NSTREAMS; i++) { /*@i@*/ if (ports[i] == -1) continue; streams[i].fd = security_stream_client(sech, ports[i]); if (streams[i].fd == NULL) { g_free(errstr); errstr = g_strdup_printf(_("[could not connect %s stream: %s]"), streams[i].name, security_geterror(sech)); goto connect_error; } } /* * Authenticate the streams */ for (i = 0; i < NSTREAMS; i++) { if (streams[i].fd == NULL) continue; if (security_stream_auth(streams[i].fd) < 0) { g_free(errstr); errstr = g_strdup_printf(_("[could not authenticate %s stream: %s]"), streams[i].name, security_stream_geterror(streams[i].fd)); goto connect_error; } } /* * The MESGFD and DATAFD streams are mandatory. If we didn't get * them, complain. */ if (streams[MESGFD].fd == NULL) { g_free(errstr); errstr = g_strdup("[couldn't open MESG streams]"); goto connect_error; } /* everything worked */ *response_error = 0; amindexd_alive = 1; return; parse_error: g_free(errstr); errstr = g_strdup_printf(_("[parse of reply message failed: %s]"), extra ? extra : _("(no additional information)")); amfree(extra); *response_error = 2; return; connect_error: stop_amindexd(); *response_error = 1; }
/** * gst_audio_info_from_caps: * @info: a #GstAudioInfo * @caps: a #GstCaps * * Parse @caps and update @info. * * Returns: TRUE if @caps could be parsed */ gboolean gst_audio_info_from_caps (GstAudioInfo * info, const GstCaps * caps) { GstStructure *str; const gchar *s; GstAudioFormat format; gint rate, channels; guint64 channel_mask; gint i; GstAudioChannelPosition position[64]; GstAudioFlags flags; GstAudioLayout layout; g_return_val_if_fail (info != NULL, FALSE); g_return_val_if_fail (caps != NULL, FALSE); g_return_val_if_fail (gst_caps_is_fixed (caps), FALSE); GST_DEBUG ("parsing caps %" GST_PTR_FORMAT, caps); flags = 0; str = gst_caps_get_structure (caps, 0); if (!gst_structure_has_name (str, "audio/x-raw")) goto wrong_name; if (!(s = gst_structure_get_string (str, "format"))) goto no_format; format = gst_audio_format_from_string (s); if (format == GST_AUDIO_FORMAT_UNKNOWN) goto unknown_format; if (!(s = gst_structure_get_string (str, "layout"))) goto no_layout; if (g_str_equal (s, "interleaved")) layout = GST_AUDIO_LAYOUT_INTERLEAVED; else if (g_str_equal (s, "non-interleaved")) layout = GST_AUDIO_LAYOUT_NON_INTERLEAVED; else goto unknown_layout; if (!gst_structure_get_int (str, "rate", &rate)) goto no_rate; if (!gst_structure_get_int (str, "channels", &channels)) goto no_channels; if (!gst_structure_get (str, "channel-mask", GST_TYPE_BITMASK, &channel_mask, NULL)) { if (channels == 1) { position[0] = GST_AUDIO_CHANNEL_POSITION_MONO; } else if (channels == 2) { position[0] = GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT; position[1] = GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT; } else { goto no_channel_mask; } } else if (channel_mask == 0) { flags |= GST_AUDIO_FLAG_UNPOSITIONED; for (i = 0; i < MIN (64, channels); i++) position[i] = GST_AUDIO_CHANNEL_POSITION_NONE; } else { if (!gst_audio_channel_positions_from_mask (channels, channel_mask, position)) goto invalid_channel_mask; } gst_audio_info_set_format (info, format, rate, channels, (channels > 64) ? NULL : position); info->flags = flags; info->layout = layout; return TRUE; /* ERROR */ wrong_name: { GST_ERROR ("wrong name, expected audio/x-raw"); return FALSE; } no_format: { GST_ERROR ("no format given"); return FALSE; } unknown_format: { GST_ERROR ("unknown format given"); return FALSE; } no_layout: { GST_ERROR ("no layout given"); return FALSE; } unknown_layout: { GST_ERROR ("unknown layout given"); return FALSE; } no_rate: { GST_ERROR ("no rate property given"); return FALSE; } no_channels: { GST_ERROR ("no channels property given"); return FALSE; } no_channel_mask: { GST_ERROR ("no channel-mask property given"); return FALSE; } invalid_channel_mask: { GST_ERROR ("Invalid channel mask 0x%016" G_GINT64_MODIFIER "x for %d channels", channel_mask, channels); return FALSE; } }
static int extract_ip(DBusMessageIter *array, int family, struct connection_data *data) { DBusMessageIter dict; char *address = NULL, *gateway = NULL, *netmask = NULL, *peer = NULL; unsigned char prefix_len; if (dbus_message_iter_get_arg_type(array) != DBUS_TYPE_ARRAY) return -EINVAL; dbus_message_iter_recurse(array, &dict); while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) { DBusMessageIter entry, value; const char *key; dbus_message_iter_recurse(&dict, &entry); dbus_message_iter_get_basic(&entry, &key); dbus_message_iter_next(&entry); dbus_message_iter_recurse(&entry, &value); if (g_str_equal(key, "Address") == TRUE) { dbus_message_iter_get_basic(&value, &address); DBG("address %s", address); } else if (g_str_equal(key, "Netmask") == TRUE) { dbus_message_iter_get_basic(&value, &netmask); DBG("netmask %s", netmask); } else if (g_str_equal(key, "PrefixLength") == TRUE) { dbus_message_iter_get_basic(&value, &netmask); DBG("prefix length %s", netmask); } else if (g_str_equal(key, "Peer") == TRUE) { dbus_message_iter_get_basic(&value, &peer); DBG("peer %s", peer); } else if (g_str_equal(key, "Gateway") == TRUE) { dbus_message_iter_get_basic(&value, &gateway); DBG("gateway %s", gateway); } dbus_message_iter_next(&dict); } data->ip = connman_ipaddress_alloc(family); if (data->ip == NULL) return -ENOMEM; switch (family) { case AF_INET: connman_ipaddress_set_ipv4(data->ip, address, netmask, gateway); break; case AF_INET6: prefix_len = atoi(netmask); connman_ipaddress_set_ipv6(data->ip, address, prefix_len, gateway); break; default: return -EINVAL; } connman_ipaddress_set_peer(data->ip, peer); return 0; }
static void on_dialog_add_edit_reponse (GtkWidget *dialog, int response_id, LogviewFilterManager *manager) { GtkWidget *entry_name, *entry_regex; GtkWidget *radio_color, *radio_visible; GtkWidget *check_foreground, *check_background; GtkWidget *color_foreground, *color_background; gchar *old_name; const gchar *name; const gchar *regex; LogviewFilter *filter; GtkTextTag *tag; GtkBuilder *builder; old_name = g_object_get_data (G_OBJECT (manager), "old_name"); builder = manager->priv->builder; entry_name = GTK_WIDGET (gtk_builder_get_object (builder, "entry_name")); entry_regex = GTK_WIDGET (gtk_builder_get_object (builder, "entry_regex")); radio_color = GTK_WIDGET (gtk_builder_get_object (builder, "radio_color")); radio_visible = GTK_WIDGET (gtk_builder_get_object (builder, "radio_visible")); check_foreground = GTK_WIDGET (gtk_builder_get_object (builder, "check_foreground")); check_background = GTK_WIDGET (gtk_builder_get_object (builder, "check_background")); color_foreground = GTK_WIDGET (gtk_builder_get_object (builder, "color_foreground")); color_background = GTK_WIDGET (gtk_builder_get_object (builder, "color_background")); if (response_id == GTK_RESPONSE_APPLY) { name = gtk_entry_get_text (GTK_ENTRY (entry_name)); regex = gtk_entry_get_text (GTK_ENTRY (entry_regex)); if (!check_name (manager, name) || !check_regex (manager, regex)) { return; } filter = logview_filter_new (name, regex); tag = gtk_text_tag_new (name); if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (radio_color))) { if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check_foreground))) { GdkColor foreground_color; gtk_color_button_get_color (GTK_COLOR_BUTTON (color_foreground), &foreground_color); g_object_set (G_OBJECT (tag), "foreground-gdk", &foreground_color, "foreground-set", TRUE, NULL); } if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check_background))) { GdkColor background_color; gtk_color_button_get_color (GTK_COLOR_BUTTON (color_background), &background_color); g_object_set (tag, "paragraph-background-gdk", &background_color, "paragraph-background-set", TRUE, NULL); } if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check_foreground)) && !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check_background))) { GtkWidget *error_dialog; error_dialog = gtk_message_dialog_new (GTK_WINDOW (manager), GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "%s", _("Please specify either foreground or background color!")); gtk_dialog_run (GTK_DIALOG (error_dialog)); gtk_widget_destroy (error_dialog); g_object_unref (tag); g_object_unref (filter); return; } } else { /* !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (radio_color)) */ g_object_set (tag, "invisible", TRUE, NULL); } if (old_name && !g_str_equal (old_name, name)) { logview_prefs_remove_filter (manager->priv->prefs, old_name); } g_object_set (G_OBJECT (filter), "texttag", tag, NULL); g_object_unref (tag); logview_prefs_add_filter (manager->priv->prefs, filter); g_object_unref (filter); logview_filter_manager_update_model (manager); } gtk_widget_destroy (dialog); }
static JabberSaslState jabber_auth_start_cyrus(JabberStream *js, xmlnode **reply, char **error) { PurpleAccount *account; const char *clientout = NULL; char *enc_out; unsigned coutlen = 0; sasl_security_properties_t secprops; gboolean again; gboolean plaintext = TRUE; /* Set up security properties and options */ secprops.min_ssf = 0; secprops.security_flags = SASL_SEC_NOANONYMOUS; account = purple_connection_get_account(js->gc); if (!jabber_stream_is_ssl(js)) { secprops.max_ssf = -1; secprops.maxbufsize = 4096; plaintext = purple_account_get_bool(account, "auth_plain_in_clear", FALSE); if (!plaintext) secprops.security_flags |= SASL_SEC_NOPLAINTEXT; } else { secprops.max_ssf = 0; secprops.maxbufsize = 0; plaintext = TRUE; } secprops.property_names = 0; secprops.property_values = 0; do { again = FALSE; js->sasl_state = sasl_client_new("xmpp", js->serverFQDN, NULL, NULL, js->sasl_cb, 0, &js->sasl); if (js->sasl_state==SASL_OK) { sasl_setprop(js->sasl, SASL_SEC_PROPS, &secprops); purple_debug_info("sasl", "Mechs found: %s\n", js->sasl_mechs->str); js->sasl_state = sasl_client_start(js->sasl, js->sasl_mechs->str, NULL, &clientout, &coutlen, &js->current_mech); } switch (js->sasl_state) { /* Success */ case SASL_OK: case SASL_CONTINUE: break; case SASL_NOMECH: /* No mechanisms have offered to help */ /* Firstly, if we don't have a password try * to get one */ if (!purple_account_get_password(account)) { purple_account_request_password(account, G_CALLBACK(auth_pass_cb), G_CALLBACK(auth_no_pass_cb), js->gc); return JABBER_SASL_STATE_CONTINUE; /* If we've got a password, but aren't sending * it in plaintext, see if we can turn on * plaintext auth */ /* XXX Should we just check for PLAIN/LOGIN being offered mechanisms? */ } else if (!plaintext) { char *msg = g_strdup_printf(_("%s may require plaintext authentication over an unencrypted connection. Allow this and continue authentication?"), purple_account_get_username(account)); purple_request_yes_no(js->gc, _("Plaintext Authentication"), _("Plaintext Authentication"), msg, 1, account, NULL, NULL, account, allow_cyrus_plaintext_auth, disallow_plaintext_auth); g_free(msg); return JABBER_SASL_STATE_CONTINUE; } else js->auth_fail_count++; if (js->auth_fail_count == 1 && (js->sasl_mechs->str && g_str_equal(js->sasl_mechs->str, "GSSAPI"))) { /* If we tried GSSAPI first, it failed, and it was the only method we had to try, try jabber:iq:auth * for compatibility with iChat 10.5 Server and other jabberd based servers. * * iChat Server 10.5 and certain other corporate servers offer SASL GSSAPI by default, which is often * not configured on the client side, and expects a fallback to jabber:iq:auth when it (predictably) fails. * * Note: xep-0078 points out that using jabber:iq:auth after a sasl failure is wrong. However, * I believe this refers to actual authentication failure, not a simple lack of concordant mechanisms. * Doing otherwise means that simply compiling with SASL support renders the client unable to connect to servers * which would connect without issue otherwise. -evands */ js->auth_mech = NULL; jabber_auth_start_old(js); return JABBER_SASL_STATE_CONTINUE; } break; /* Fatal errors. Give up and go home */ case SASL_BADPARAM: case SASL_NOMEM: *error = g_strdup(_("SASL authentication failed")); break; /* For everything else, fail the mechanism and try again */ default: purple_debug_info("sasl", "sasl_state is %d, failing the mech and trying again\n", js->sasl_state); js->auth_fail_count++; /* * DAA: is this right? * The manpage says that "mech" will contain the chosen mechanism on success. * Presumably, if we get here that isn't the case and we shouldn't try again? * I suspect that this never happens. */ /* * SXW: Yes, this is right. What this handles is the situation where a * mechanism, say GSSAPI, is tried. If that mechanism fails, it may be * due to mechanism specific issues, so we want to try one of the other * supported mechanisms. This code handles that case */ if (js->current_mech && *js->current_mech) { char *pos; if ((pos = strstr(js->sasl_mechs->str, js->current_mech))) { g_string_erase(js->sasl_mechs, pos-js->sasl_mechs->str, strlen(js->current_mech)); } /* Remove space which separated this mech from the next */ if ((js->sasl_mechs->str)[0] == ' ') { g_string_erase(js->sasl_mechs, 0, 1); } again = TRUE; } sasl_dispose(&js->sasl); } } while (again); if (js->sasl_state == SASL_CONTINUE || js->sasl_state == SASL_OK) { xmlnode *auth = xmlnode_new("auth"); xmlnode_set_namespace(auth, NS_XMPP_SASL); xmlnode_set_attrib(auth, "mechanism", js->current_mech); xmlnode_set_attrib(auth, "xmlns:ga", "http://www.google.com/talk/protocol/auth"); xmlnode_set_attrib(auth, "ga:client-uses-full-bind-result", "true"); if (clientout) { if (coutlen == 0) { xmlnode_insert_data(auth, "=", -1); } else { enc_out = purple_base64_encode((unsigned char*)clientout, coutlen); xmlnode_insert_data(auth, enc_out, -1); g_free(enc_out); } } *reply = auth; return JABBER_SASL_STATE_CONTINUE; } else { return JABBER_SASL_STATE_FAIL; } }
GtkWidget *ly_3lrc_config() { GtkWidget *page; GtkWidget *item; GtkWidget *vbox; GtkWidget *hbox; GtkWidget *check; GtkWidget *button; GtkWidget *entry; GtkWidget *label; GtkWidget *table; char str[1024]=""; char name[1024]=""; LyPliPlugin *pl=ly_pli_get("lrc"); g_snprintf(name, sizeof(name), "PLUGIN:%s", pl->name); page=ly_cfg_page_new(name, pl->alias, pl->logo); item=ly_cfg_item_new(_("Desktop Lyrics")); ly_cfg_page_append(LY_CFG_PAGE(page), item); vbox=gtk_vbox_new(FALSE, 0); ly_cfg_item_append(LY_CFG_ITEM(item), vbox); int lrc_desktop=0; int lrc_desktop_fixed=0; ly_reg_get("3lrc_desktop_state", "%d:%d", &lrc_desktop, &lrc_desktop_fixed); check=gtk_check_button_new_with_label(_("Show desktop lyrics")); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check),(gboolean)lrc_desktop); g_signal_connect(G_OBJECT(check), "toggled", G_CALLBACK(ly_3lrc_config_on_desktop_changed_cb), NULL); gtk_box_pack_start(GTK_BOX(vbox),check,FALSE,FALSE,0); check=gtk_check_button_new_with_label(_("Set desktop lyrics FIXED")); g_signal_connect(G_OBJECT(check), "toggled", G_CALLBACK(ly_3lrc_config_on_fixed_changed_cb), NULL); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check),(gboolean)lrc_desktop_fixed); gtk_box_pack_start(GTK_BOX(vbox),check,FALSE,FALSE,0); item=ly_cfg_item_new(_("Lyrics File Storage")); ly_cfg_page_append(LY_CFG_PAGE(page), item); char location[1024]="./"; ly_reg_get("lrc_dir", "%s", location); vbox=gtk_vbox_new(FALSE, 0); ly_cfg_item_append(LY_CFG_ITEM(item), vbox); hbox=gtk_hbox_new(FALSE,0); if(g_str_equal(location,"")||g_str_equal(location,"./")) gtk_widget_set_sensitive(hbox, FALSE); check=gtk_check_button_new_with_label(_("The same directory of music file")); if(g_str_equal(location,"")||g_str_equal(location,"./")) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check), TRUE); g_signal_connect(G_OBJECT(check), "toggled", G_CALLBACK(ly_3lrc_config_on_location_changed_cb), hbox); gtk_box_pack_start(GTK_BOX(vbox),check,FALSE,FALSE,0); gtk_box_pack_start(GTK_BOX(vbox),hbox,FALSE,FALSE,0); label=gtk_label_new(_("Custom LRC location")); gtk_box_pack_start(GTK_BOX(hbox),label,FALSE,FALSE,0); entry=gtk_entry_new(); gtk_entry_set_text(GTK_ENTRY(entry), location); check=gtk_check_button_new_with_label(_("The same directory of music file")); gtk_widget_set_sensitive(entry,FALSE); gtk_box_pack_start(GTK_BOX(hbox),entry,TRUE,TRUE,0); button=gtk_button_new_from_stock(GTK_STOCK_OPEN); g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(ly_3lrc_config_on_location_set_cb), entry); gtk_box_pack_start(GTK_BOX(hbox),button,FALSE,FALSE,0); item=ly_cfg_item_new(_("Font")); ly_cfg_page_append(LY_CFG_PAGE(page), item); table=gtk_table_new(3, 2, FALSE); ly_cfg_item_append(LY_CFG_ITEM(item), table); label=gtk_label_new(_("Title Font")); gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 0, 1); ly_reg_get("3lrc_title_font", "%1024[^\n]", str); button=gtk_font_button_new_with_font(str); g_signal_connect(G_OBJECT(button), "font-set", G_CALLBACK(ly_3lrc_config_on_title_font_set_cb), NULL); gtk_table_attach_defaults(GTK_TABLE(table), button, 1, 2, 0, 1); label=gtk_label_new(_("Normal Font")); gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 1, 2); ly_reg_get("3lrc_normal_font", "%1024[^\n]", str); button=gtk_font_button_new_with_font(str); g_signal_connect(G_OBJECT(button), "font-set", G_CALLBACK(ly_3lrc_config_on_normal_font_set_cb), NULL); gtk_table_attach_defaults(GTK_TABLE(table), button, 1, 2, 1, 2); label=gtk_label_new(_("Desktop Font")); gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 2, 3); ly_reg_get("3lrc_desktop_font", "%1024[^\n]", str); button=gtk_font_button_new_with_font(str); g_signal_connect(G_OBJECT(button), "font-set", G_CALLBACK(ly_3lrc_config_on_desktop_font_set_cb), NULL); gtk_table_attach_defaults(GTK_TABLE(table), button, 1, 2, 2, 3); return page; }
int main( int argc, char ** argv) { char ch; am_feature_t *our_features = NULL; char *our_feature_string = NULL; char *options; ssize_t n; (void)argc; /* Quiet unused parameter warning */ (void)argv; /* Quiet unused parameter warning */ glib_init(); if (argc > 1 && argv && argv[1] && g_str_equal(argv[1], "--version")) { printf("noop-%s\n", VERSION); return (0); } /* * Configure program for internationalization: * 1) Only set the message locale for now. * 2) Set textdomain for all amanda related programs to "amanda" * We don't want to be forced to support dozens of message catalogs. */ setlocale(LC_MESSAGES, "C"); textdomain("amanda"); /* Don't die when child closes pipe */ signal(SIGPIPE, SIG_IGN); safe_fd(-1, 0); openbsd_fd_inform(); check_running_as(RUNNING_AS_CLIENT_LOGIN); do { /* soak up any stdin */ n = read(0, &ch, 1); } while ((n > 0) || ((n < 0) && ((errno == EINTR) || (errno == EAGAIN)))); our_features = am_init_feature_set(); our_feature_string = am_feature_to_string(our_features); options = g_strjoin(NULL, "OPTIONS features=", our_feature_string, ";\n", NULL); amfree(our_feature_string); am_release_feature_set(our_features); our_features = NULL; if (full_write(1, options, strlen(options)) < strlen(options)) { error(_("error sending noop response: %s"), strerror(errno)); /*NOTREACHED*/ } amfree(options); close(0); close(1); close(2); return (0); /* exit */ }
static void filter_option_xml_create (EFilterElement *element, xmlNodePtr node) { EFilterOption *option = E_FILTER_OPTION (element); xmlNodePtr n, work; /* Chain up to parent's xml_create() method. */ E_FILTER_ELEMENT_CLASS (e_filter_option_parent_class)-> xml_create (element, node); n = node->children; while (n) { if (!strcmp ((gchar *) n->name, "option")) { gchar *tmp, *value, *title = NULL, *code = NULL, *code_gen_func = NULL; value = (gchar *) xmlGetProp (n, (xmlChar *)"value"); work = n->children; while (work) { if (!strcmp ((gchar *) work->name, "title") || !strcmp ((gchar *) work->name, "_title")) { if (!title) { if (!(tmp = (gchar *) xmlNodeGetContent (work))) tmp = (gchar *) xmlStrdup ((xmlChar *)""); title = g_strdup (tmp); xmlFree (tmp); } } else if (!strcmp ((gchar *) work->name, "code")) { if (code || code_gen_func) { g_warning ( "Element 'code' defined twice in '%s'", element->name); } else { xmlChar *fn; /* if element 'code' has attribute 'func', then * the content of the element is ignored and only * the 'func' is used to generate actual rule code; * The function prototype is: * void code_gen_func (EFilterElement *element, GString *out, EFilterPart *part); * where @element is the one on which was called, * @out is GString where to add the code, and * @part is part which contains @element and other options of it. */ fn = xmlGetProp (work, (xmlChar *)"func"); if (fn && *fn) { code_gen_func = g_strdup ((const gchar *) fn); } else { if (!(tmp = (gchar *) xmlNodeGetContent (work))) tmp = (gchar *) xmlStrdup ((xmlChar *)""); code = g_strdup (tmp); xmlFree (tmp); } xmlFree (fn); } } work = work->next; } e_filter_option_add (option, value, title, code, code_gen_func, FALSE); xmlFree (value); g_free (title); g_free (code); g_free (code_gen_func); } else if (g_str_equal ((gchar *) n->name, "dynamic")) { if (option->dynamic_func) { g_warning ( "Only one 'dynamic' node is " "acceptable in the optionlist '%s'", element->name); } else { /* Expecting only one <dynamic func="cb" /> * in the option list, * The 'cb' should be of this prototype: * GSList *cb (void); * returning GSList of struct _filter_option, * all newly allocated, because it'll be * freed with g_free and g_slist_free. * 'is_dynamic' member is ignored here. */ xmlChar *fn; fn = xmlGetProp (n, (xmlChar *)"func"); if (fn && *fn) { GSList *items, *i; struct _filter_option *op; option->dynamic_func = g_strdup ((const gchar *) fn); /* Get options now, to have them * available when reading saved * rules. */ items = filter_option_get_dynamic_options (option); for (i = items; i; i = i->next) { op = i->data; if (op) { e_filter_option_add ( option, op->value, op->title, op->code, op->code_gen_func, TRUE); free_option (op); } } g_slist_free (items); } else { g_warning ( "Missing 'func' attribute within " "'%s' node in optionlist '%s'", n->name, element->name); } xmlFree (fn); } } else if (n->type == XML_ELEMENT_NODE) { g_warning ("Unknown xml node within optionlist: %s\n", n->name); } n = n->next; } }
int main (int argc, char *argv[]) { gint ret = 1; g_autoptr(GOptionContext) context = NULL; g_autoptr(GTlsCertificate) certificate = NULL; g_autoptr(GError) error = NULL; g_auto(GStrv) roots = NULL; g_autofree gchar *cert_path = NULL; g_autoptr(GMainLoop) loop = NULL; g_autofree gchar *login_html = NULL; g_autofree gchar *login_po_html = NULL; CockpitWebServer *server = NULL; CockpitHandlerData data; CockpitPipe *pipe = NULL; int outfd = -1; signal (SIGPIPE, SIG_IGN); g_setenv ("GSETTINGS_BACKEND", "memory", TRUE); g_setenv ("GIO_USE_PROXY_RESOLVER", "dummy", TRUE); g_setenv ("GIO_USE_VFS", "local", TRUE); /* Any interaction with a krb5 ccache should be explicit */ g_setenv ("KRB5CCNAME", "FILE:/dev/null", TRUE); g_setenv ("G_TLS_GNUTLS_PRIORITY", "SECURE128:%LATEST_RECORD_VERSION:-VERS-SSL3.0:-VERS-TLS1.0", FALSE); memset (&data, 0, sizeof (data)); context = g_option_context_new (NULL); g_option_context_add_main_entries (context, cmd_entries, NULL); if (!g_option_context_parse (context, &argc, &argv, &error)) goto out; if (opt_version) { print_version (); ret = 0; goto out; } if (opt_for_tls_proxy) opt_no_tls = TRUE; /* * This process talks on stdin/stdout. However lots of stuff wants to write * to stdout, such as g_debug, and uses fd 1 to do that. Reroute fd 1 so that * it goes to stderr, and use another fd for stdout. */ outfd = dup (1); if (outfd < 0 || dup2 (2, 1) < 1) { g_printerr ("ws couldn't redirect stdout to stderr"); goto out; } cockpit_set_journal_logging (NULL, !isatty (2)); if (opt_local_session || opt_no_tls) { /* no certificate */ } else { cert_path = cockpit_certificate_locate (FALSE, &error); if (cert_path != NULL) certificate = cockpit_certificate_load (cert_path, &error); if (certificate == NULL) goto out; g_info ("Using certificate: %s", cert_path); } loop = g_main_loop_new (NULL, FALSE); data.os_release = cockpit_system_load_os_release (); data.auth = cockpit_auth_new (opt_local_ssh); roots = setup_static_roots (data.os_release); data.branding_roots = (const gchar **)roots; login_html = g_strdup (DATADIR "/cockpit/static/login.html"); data.login_html = (const gchar *)login_html; login_po_html = g_strdup (DATADIR "/cockpit/static/login.po.html"); data.login_po_html = (const gchar *)login_po_html; server = cockpit_web_server_new (opt_address, opt_port, certificate, opt_for_tls_proxy ? COCKPIT_WEB_SERVER_FOR_TLS_PROXY : COCKPIT_WEB_SERVER_NONE, NULL, &error); if (server == NULL) { g_prefix_error (&error, "Error starting web server: "); goto out; } cockpit_web_server_set_redirect_tls (server, !cockpit_conf_bool ("WebService", "AllowUnencrypted", FALSE)); if (cockpit_conf_string ("WebService", "UrlRoot")) { g_object_set (server, "url-root", cockpit_conf_string ("WebService", "UrlRoot"), NULL); } if (cockpit_web_server_get_socket_activated (server)) g_signal_connect_swapped (data.auth, "idling", G_CALLBACK (g_main_loop_quit), loop); /* Ignores stuff it shouldn't handle */ g_signal_connect (server, "handle-stream", G_CALLBACK (cockpit_handler_socket), &data); /* External channels, ignore stuff they shouldn't handle */ g_signal_connect (server, "handle-stream", G_CALLBACK (cockpit_handler_external), &data); /* Don't redirect to TLS for /ping */ g_object_set (server, "ssl-exception-prefix", "/ping", NULL); g_signal_connect (server, "handle-resource::/ping", G_CALLBACK (cockpit_handler_ping), &data); /* Files that cannot be cache-forever, because of well known names */ g_signal_connect (server, "handle-resource::/favicon.ico", G_CALLBACK (cockpit_handler_root), &data); g_signal_connect (server, "handle-resource::/apple-touch-icon.png", G_CALLBACK (cockpit_handler_root), &data); /* The fallback handler for everything else */ g_signal_connect (server, "handle-resource", G_CALLBACK (cockpit_handler_default), &data); if (opt_local_session) { struct passwd *pwd; if (g_str_equal (opt_local_session, "-")) { pipe = cockpit_pipe_new (opt_local_session, 0, outfd); outfd = -1; } else { const gchar *args[] = { opt_local_session, NULL }; pipe = cockpit_pipe_spawn (args, NULL, NULL, COCKPIT_PIPE_FLAGS_NONE); } /* Spawn a local session as a bridge */ pwd = getpwuid (geteuid ()); if (!pwd) { g_printerr ("Failed to resolve current user id %u\n", geteuid ()); goto out; } cockpit_auth_local_async (data.auth, pwd->pw_name, pipe, on_local_ready, g_object_ref (server)); g_object_unref (pipe); } else { /* When no local bridge, start serving immediately */ cockpit_web_server_start (server); } /* Debugging issues during testing */ #if WITH_DEBUG signal (SIGABRT, cockpit_test_signal_backtrace); signal (SIGSEGV, cockpit_test_signal_backtrace); #endif g_main_loop_run (loop); ret = 0; out: if (outfd >= 0) close (outfd); if (error) g_printerr ("cockpit-ws: %s\n", error->message); g_clear_object (&server); g_clear_object (&data.auth); if (data.os_release) g_hash_table_unref (data.os_release); g_free (opt_address); g_free (opt_local_session); cockpit_conf_cleanup (); return ret; }
void e_mail_formatter_format_header (EMailFormatter *formatter, GString *buffer, const gchar *header_name, const gchar *header_value, guint32 flags, const gchar *charset) { gchar *canon_name, *buf, *value = NULL; const gchar *label, *txt; gboolean addrspec = FALSE; gchar *str_field = NULL; gint i; g_return_if_fail (E_IS_MAIL_FORMATTER (formatter)); g_return_if_fail (buffer != NULL); g_return_if_fail (header_name != NULL); g_return_if_fail (header_value != NULL); canon_name = g_alloca (strlen (header_name) + 1); strcpy (canon_name, header_name); e_mail_formatter_canon_header_name (canon_name); for (i = 0; addrspec_hdrs[i]; i++) { if (g_str_equal (canon_name, addrspec_hdrs[i])) { addrspec = TRUE; break; } } label = _(canon_name); if (addrspec) { struct _camel_header_address *addrs; GString *html; gchar *img; gchar *charset; charset = e_mail_formatter_dup_charset (formatter); if (charset == NULL) charset = e_mail_formatter_dup_default_charset (formatter); buf = camel_header_unfold (header_value); addrs = camel_header_address_decode (buf, charset); if (addrs == NULL) { g_free (charset); g_free (buf); return; } g_free (charset); g_free (buf); html = g_string_new (""); img = e_mail_formatter_format_address ( formatter, html, addrs, label, (flags & E_MAIL_FORMATTER_HEADER_FLAG_NOLINKS), !(flags & E_MAIL_FORMATTER_HEADER_FLAG_NOELIPSIZE)); if (img != NULL) { str_field = g_strdup_printf ("%s: %s", label, img); label = str_field; flags |= E_MAIL_FORMATTER_HEADER_FLAG_NODEC; g_free (img); } camel_header_address_list_clear (&addrs); txt = value = html->str; g_string_free (html, FALSE); flags |= E_MAIL_FORMATTER_HEADER_FLAG_HTML; flags |= E_MAIL_FORMATTER_HEADER_FLAG_BOLD; } else if (g_str_equal (canon_name, "Subject")) { buf = camel_header_unfold (header_value); txt = value = camel_header_decode_string (buf, charset); g_free (buf); flags |= E_MAIL_FORMATTER_HEADER_FLAG_BOLD; } else if (g_str_equal (canon_name, "X-Evolution-Mailer")) { /* pseudo-header */ label = _("Mailer"); txt = value = camel_header_format_ctext (header_value, charset); flags |= E_MAIL_FORMATTER_HEADER_FLAG_BOLD; } else if (g_str_equal (canon_name, "Date") || g_str_equal (canon_name, "Resent-Date")) { CamelMimeFilterToHTMLFlags text_format_flags; gint msg_offset, local_tz; time_t msg_date; struct tm local; gchar *html; gboolean hide_real_date; hide_real_date = !e_mail_formatter_get_show_real_date (formatter); txt = header_value; while (*txt == ' ' || *txt == '\t') txt++; text_format_flags = e_mail_formatter_get_text_format_flags (formatter); html = camel_text_to_html (txt, text_format_flags, 0); msg_date = camel_header_decode_date (txt, &msg_offset); e_localtime_with_offset (msg_date, &local, &local_tz); /* Convert message offset to minutes (e.g. -0400 --> -240) */ msg_offset = ((msg_offset / 100) * 60) + (msg_offset % 100); /* Turn into offset from localtime, not UTC */ msg_offset -= local_tz / 60; /* value will be freed at the end */ if (!hide_real_date && !msg_offset) { /* No timezone difference; just * show the real Date: header. */ txt = value = html; } else { gchar *date_str; date_str = e_datetime_format_format ( "mail", "header", DTFormatKindDateTime, msg_date); if (hide_real_date) { /* Show only the local-formatted date, losing * all timezone information like Outlook does. * Should we attempt to show it somehow? */ txt = value = date_str; } else { txt = value = g_strdup_printf ( "%s (<I>%s</I>)", html, date_str); g_free (date_str); } g_free (html); } flags |= E_MAIL_FORMATTER_HEADER_FLAG_HTML; flags |= E_MAIL_FORMATTER_HEADER_FLAG_BOLD; } else if (g_str_equal (canon_name, "Newsgroups")) { struct _camel_header_newsgroup *ng, *scan; GString *html; buf = camel_header_unfold (header_value); if (!(ng = camel_header_newsgroups_decode (buf))) { g_free (buf); return; } g_free (buf); html = g_string_new (""); scan = ng; while (scan) { if (flags & E_MAIL_FORMATTER_HEADER_FLAG_NOLINKS) g_string_append_printf ( html, "%s", scan->newsgroup); else g_string_append_printf ( html, "<a href=\"news:%s\">%s</a>", scan->newsgroup, scan->newsgroup); scan = scan->next; if (scan) g_string_append_printf (html, ", "); } camel_header_newsgroups_free (ng); txt = html->str; g_string_free (html, FALSE); flags |= E_MAIL_FORMATTER_HEADER_FLAG_HTML; flags |= E_MAIL_FORMATTER_HEADER_FLAG_BOLD; } else if (g_str_equal (canon_name, "Received") || g_str_has_prefix (canon_name, "X-")) { /* don't unfold Received nor extension headers */ txt = value = camel_header_decode_string (header_value, charset); } else { /* don't unfold Received nor extension headers */ buf = camel_header_unfold (header_value); txt = value = camel_header_decode_string (buf, charset); g_free (buf); } e_mail_formatter_format_text_header ( formatter, buffer, label, txt, flags); g_free (value); g_free (str_field); }
/** * vinagre_connection_split_string: * @uri: The URI to be splitted. * @known_protocol: The protocol, if it's known. NULL otherwise. * @protocol: Will hold the protocol of this URI * @host: Will hold the host of this URI * @port: Will hold the port of this URI * @error_msg: Will hold an error message in case of fail * * Splits a URI into its several parts. * * Returns: %TRUE if the URI is splitted successfuly. FALSE otherwise. */ gboolean vinagre_connection_split_string (const gchar *uri, const gchar *known_protocol, gchar **protocol, gchar **host, gint *port, gchar **error_msg) { gchar **server, **url; gint lport; gchar *lhost; gchar ipv6_host[255] = {0,}; VinagreProtocol *ext; *error_msg = NULL; *host = NULL; *port = 0; url = g_strsplit (uri, "://", 2); if (g_strv_length (url) == 2) { if (known_protocol) *protocol = g_strdup (known_protocol); else *protocol = g_strdup (url[0]); lhost = url[1]; } else { if (known_protocol) *protocol = g_strdup (known_protocol); else *protocol = g_strdup ("vnc"); lhost = (gchar *) uri; } ext = vinagre_plugins_engine_get_plugin_by_protocol (vinagre_plugins_engine_get_default (), *protocol); if (!ext) { *error_msg = g_strdup_printf (_("The protocol %s is not supported."), *protocol); g_free (*protocol); *protocol = NULL; g_strfreev (url); return FALSE; } if (lhost[0] == '[') { int i; for (i = 1; lhost[i] && lhost[i] != ']'; i++) { ipv6_host[i-1] = lhost[i]; lhost[i-1] = '_'; } ipv6_host[i-1] = '\0'; lhost[i] = '_'; } if (g_strrstr (lhost, "::") != NULL) { server = g_strsplit (lhost, "::", 2); lport = server[1] ? atoi (server[1]) : vinagre_protocol_get_default_port (ext); } else { server = g_strsplit (lhost, ":", 2); lport = server[1] ? atoi (server[1]) : vinagre_protocol_get_default_port (ext); if ((g_str_equal (*protocol, "vnc")) && (lport < 1024)) lport += 5900; } lhost = ipv6_host[0] ? ipv6_host : (server[0] && server[0][0] ? server[0] : "localhost"); *host = g_strdup (lhost); *port = lport; g_strfreev (server); g_strfreev (url); return TRUE; }
static DBusMessage *modem_set_property(DBusConnection *conn, DBusMessage *msg, void *data) { struct ofono_modem *modem = data; DBusMessageIter iter, var; const char *name; if (dbus_message_iter_init(msg, &iter) == FALSE) return __ofono_error_invalid_args(msg); if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING) return __ofono_error_invalid_args(msg); dbus_message_iter_get_basic(&iter, &name); dbus_message_iter_next(&iter); if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT) return __ofono_error_invalid_args(msg); if (powering_down == TRUE) return __ofono_error_failed(msg); dbus_message_iter_recurse(&iter, &var); if (g_str_equal(name, "Online")) return set_property_online(modem, msg, &var); if (g_str_equal(name, "Powered") == TRUE) { ofono_bool_t powered; int err; if (dbus_message_iter_get_arg_type(&var) != DBUS_TYPE_BOOLEAN) return __ofono_error_invalid_args(msg); dbus_message_iter_get_basic(&var, &powered); if (modem->pending != NULL) return __ofono_error_busy(msg); if (modem->powered == powered) return dbus_message_new_method_return(msg); if (ofono_modem_get_emergency_mode(modem) == TRUE) return __ofono_error_emergency_active(msg); if (modem->lockdown) return __ofono_error_access_denied(msg); err = set_powered(modem, powered); if (err < 0) { if (err != -EINPROGRESS) return __ofono_error_failed(msg); modem->pending = dbus_message_ref(msg); modem->timeout = g_timeout_add_seconds(20, set_powered_timeout, modem); return NULL; } g_dbus_send_reply(conn, msg, DBUS_TYPE_INVALID); ofono_dbus_signal_property_changed(conn, modem->path, OFONO_MODEM_INTERFACE, "Powered", DBUS_TYPE_BOOLEAN, &powered); if (powered) { modem_change_state(modem, MODEM_STATE_PRE_SIM); /* Force SIM Ready for devies with no sim atom */ if (modem_has_sim(modem) == FALSE) sim_state_watch(OFONO_SIM_STATE_READY, modem); } else { set_online(modem, FALSE); modem_change_state(modem, MODEM_STATE_POWER_OFF); } return NULL; } if (g_str_equal(name, "Lockdown")) return set_property_lockdown(modem, msg, &var); return __ofono_error_invalid_args(msg); }
static void picture_scaled (GObject *source_object, GAsyncResult *res, gpointer user_data) { BgPicturesSource *bg_source; CcBackgroundItem *item; GError *error = NULL; GdkPixbuf *pixbuf; const char *source_url; const char *software; GtkTreeIter iter; GtkListStore *store; pixbuf = gdk_pixbuf_new_from_stream_finish (res, &error); if (pixbuf == NULL) { if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) g_warning ("Failed to load image: %s", error->message); g_error_free (error); return; } /* since we were not cancelled, we can now cast user_data * back to BgPicturesSource. */ bg_source = BG_PICTURES_SOURCE (user_data); store = bg_source_get_liststore (BG_SOURCE (bg_source)); item = g_object_get_data (source_object, "item"); gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (store), 1, (GtkTreeIterCompareFunc)sort_func, bg_source, NULL); gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store), 1, GTK_SORT_ASCENDING); /* Ignore screenshots */ software = gdk_pixbuf_get_option (pixbuf, "tEXt::Software"); if (software != NULL && g_str_equal (software, "gnome-screenshot")) { g_debug ("Ignored URL '%s' as it's a screenshot from gnome-screenshot", cc_background_item_get_uri (item)); g_object_unref (pixbuf); g_object_unref (item); return; } cc_background_item_load (item, NULL); /* insert the item into the liststore */ gtk_list_store_insert_with_values (store, &iter, 0, 0, pixbuf, 1, item, -1); source_url = cc_background_item_get_source_url (item); if (source_url != NULL) { g_hash_table_insert (bg_source->priv->known_items, bg_pictures_source_get_unique_filename (source_url), GINT_TO_POINTER (TRUE)); } else { char *cache_path; GFile *file, *parent, *dir; cache_path = bg_pictures_source_get_cache_path (); dir = g_file_new_for_path (cache_path); g_free (cache_path); file = g_file_new_for_uri (cc_background_item_get_uri (item)); parent = g_file_get_parent (file); if (g_file_equal (parent, dir)) { char *basename; basename = g_file_get_basename (file); g_hash_table_insert (bg_source->priv->known_items, basename, GINT_TO_POINTER (TRUE)); } g_object_unref (file); g_object_unref (parent); } g_object_unref (pixbuf); }
int main (int argc, char **argv) { GError *error = NULL; GUPnPContext *context; GUPnPControlPoint *cp; #if !GLIB_CHECK_VERSION(2,35,0) g_type_init (); #endif /* Check and parse command line arguments */ if (argc != 2) { usage (); return EXIT_FAILURE; } if (g_str_equal (argv[1], "on")) { mode = ON; } else if (g_str_equal (argv[1], "off")) { mode = OFF; } else if (g_str_equal (argv[1], "toggle")) { mode = TOGGLE; } else { usage (); return EXIT_FAILURE; } /* Create the UPnP context */ context = gupnp_context_new (NULL, NULL, 0, &error); if (error) { g_printerr ("Error creating the GUPnP context: %s\n", error->message); g_error_free (error); return EXIT_FAILURE; } /* Create the control point, searching for SwitchPower services */ cp = gupnp_control_point_new (context, "urn:schemas-upnp-org:service:SwitchPower:1"); /* Connect to the service-found callback */ g_signal_connect (cp, "service-proxy-available", G_CALLBACK (service_proxy_available_cb), NULL); /* Start searching when the main loop runs */ gssdp_resource_browser_set_active (GSSDP_RESOURCE_BROWSER (cp), TRUE); /* Run the main loop */ main_loop = g_main_loop_new (NULL, FALSE); g_main_loop_run (main_loop); /* Cleanup */ g_main_loop_unref (main_loop); g_object_unref (cp); g_object_unref (context); return EXIT_SUCCESS; }