Пример #1
0
/*
 * Get the check sum of password and verify code.
 *
 * First, compute check sum of password for three times.
 * Then, join the result with the capitalizaion of the verify code.
 * Compute the chekc sum of the new string.
 */
GString* get_pwvc_md5(const gchar *pwd, const gchar *vc, GError **err)
{
	guint8 buf[100];
	gsize bsize = 100;
	
	GChecksum *cs = g_checksum_new(G_CHECKSUM_MD5);
	g_checksum_update(cs, (const guchar*)pwd, strlen(pwd));
	g_checksum_get_digest(cs, buf, &bsize);
	g_checksum_free(cs);
	
	cs = g_checksum_new(G_CHECKSUM_MD5);
	g_checksum_update(cs, buf, bsize);
	g_checksum_get_digest(cs, buf, &bsize);
	g_checksum_free(cs);
	
	cs = g_checksum_new(G_CHECKSUM_MD5);
	g_checksum_update(cs, buf, bsize);
	const gchar * md5_3 = g_checksum_get_string(cs);
	md5_3 = g_ascii_strup(md5_3, strlen(md5_3));
	gchar buf2[100];
	g_sprintf(buf2, "%s%s", md5_3, vc);
	g_checksum_free(cs);

	gchar *tmp1;
	tmp1 = g_ascii_strup(buf2, strlen(buf2));
	tmp1 = g_compute_checksum_for_string(G_CHECKSUM_MD5
						, tmp1, -1);
	tmp1 = g_ascii_strup(tmp1, strlen(tmp1));
	GString *re = g_string_new(tmp1);
	g_free(tmp1);

	return re;
}
Пример #2
0
void
token_set_counter_type ( Token *token, const gchar *str, GError **err )
{
  gchar *str_up, *label_up;
  CounterType counter_t;

  str_up = g_ascii_strup ( str, -1 );
  for ( counter_t=0; counter_t < N_OTP_COUNTER_TYPES; ++counter_t ){
    label_up = g_ascii_strup ( counter_type_labels[counter_t], -1 );
    if ( g_strcmp0( label_up, str_up ) == 0 ){
      g_free ( label_up );
      break;
    } else {
      g_free ( label_up );
    }
  }
  g_free ( str_up );
  if ( counter_t == N_OTP_COUNTER_TYPES ){
    g_set_error ( err, OTP_ERROR, OTP_ERROR_INVALID_TOKEN,
		  "Invalid counter type '%s'.", str );
    return;
  }

  token->counter_t = counter_t;
}
Пример #3
0
void hon_parse_tmm_invite(PurpleConnection *gc,gchar* buffer)
{
    PurpleMessageFlags receive_flags;
    gchar* tmp;
    gchar* upcase;
    gchar* split;
    gchar* message;
    gchar* map;
    gchar* modes;
    gchar* regions;
    gchar* from_username = NULL;

    from_username = read_string(buffer);
    read_guint32(buffer); // id
    read_byte(buffer); //flags /
    read_byte(buffer); // ??
    read_string(buffer); // color
    read_string(buffer); // icon

    read_guint32(buffer); // ??

    map = read_string(buffer);

    if (from_username[0] == '[')
    {
        while (from_username[0] != ']')
            from_username++;
        from_username++;
    }

    read_byte(buffer); // ??

    // uppercase mode/region
    // show array of mode/region more nicely
    tmp = read_string(buffer);
    upcase = g_ascii_strup(tmp, -1);
    split = g_strsplit(upcase, _("|"),-1);
    modes = g_strchomp(g_strjoinv(_(" "),split));
    g_free(upcase);
    g_strfreev(split);

    tmp = read_string(buffer);
    upcase = g_ascii_strup(tmp, -1);
    split = g_strsplit(upcase, _("|"),-1);
    regions = g_strchomp(g_strjoinv(_(" "),split));
    g_free(upcase);
    g_strfreev(split);

    receive_flags = PURPLE_MESSAGE_WHISPER;

    message = g_strdup_printf("%s %s %s %s %s %s" ,_("I invited you to matchmaking:\nMap:"),map,_("\nModes:"),modes,_("\nRegions:"),regions);
    serv_got_im(gc, from_username, message, receive_flags, time(NULL));
    g_free(message);
    g_free(modes);
    g_free(regions);
}
Пример #4
0
/*! \brief Determines visibility of items of the library treeview.
 *  \par Function Description
 *  This is the function used to filter entries of the footprint
 *  selection tree.
 *
 *  \param [in] model The current selection in the treeview.
 *  \param [in] iter  An iterator on a footprint or folder in the tree.
 *  \param [in] data  The library dialog.
 *  \returns TRUE if item should be visible, FALSE otherwise.
 */
static gboolean
lib_model_filter_visible_func (GtkTreeModel * model,
			       GtkTreeIter * iter, gpointer data)
{
  GhidLibraryWindow *library_window = (GhidLibraryWindow *) data;
  const gchar *compname;
  gchar *compname_upper, *text_upper, *pattern;
  const gchar *text;
  gboolean ret;

  g_assert (GHID_IS_LIBRARY_WINDOW (data));

  text = gtk_entry_get_text (library_window->entry_filter);
  if (g_ascii_strcasecmp (text, "") == 0)
    {
      return TRUE;
    }

  /* If this is a source, only display it if it has children that
   * match */
  if (gtk_tree_model_iter_has_child (model, iter))
    {
      GtkTreeIter iter2;

      gtk_tree_model_iter_children (model, &iter2, iter);
      ret = FALSE;
      do
	{
	  if (lib_model_filter_visible_func (model, &iter2, data))
	    {
	      ret = TRUE;
	      break;
	    }
	}
      while (gtk_tree_model_iter_next (model, &iter2));
    }
  else
    {
      gtk_tree_model_get (model, iter, MENU_NAME_COLUMN, &compname, -1);
      /* Do a case insensitive comparison, converting the strings
         to uppercase */
      compname_upper = g_ascii_strup (compname, -1);
      text_upper = g_ascii_strup (text, -1);
      pattern = g_strconcat ("*", text_upper, "*", NULL);
      ret = g_pattern_match_simple (pattern, compname_upper);
      g_free (compname_upper);
      g_free (text_upper);
      g_free (pattern);
    }

  return ret;
}
Пример #5
0
/* FIXME: Always returns 0, which is dandy for debugging. */
int config_get_value(const field_t field_name,
                     const char * const service_name,
                     field_t value)
{
	char *key;
	gssize field_len;

	field_len = strlen(field_name);
	
	// First look in the SERVICE section.
	// For each attempt, try as-is, upper, lower.
	       
	key = NULL;
	if (config_get_value_once(field_name, service_name, value))
		goto config_get_value_done;
	
	key = g_ascii_strup(field_name, field_len);
	if (config_get_value_once(key, service_name, value))
		goto config_get_value_done;
	g_free(key);

	key = g_ascii_strdown(field_name, field_len);
	if (config_get_value_once(key, service_name, value))
		goto config_get_value_done;
	g_free(key);

	// if not found, get the DBMAIL section.
	// For each attempt, try as-is, upper, lower.
	       
	key = NULL;
	if (config_get_value_once(field_name, "DBMAIL", value))
		goto config_get_value_done;
	
	key = g_ascii_strup(field_name, field_len);
	if (config_get_value_once(key, "DBMAIL", value))
		goto config_get_value_done;
	g_free(key);

	key = g_ascii_strdown(field_name, field_len);
	if (config_get_value_once(key, "DBMAIL", value))
		goto config_get_value_done;
	g_free(key);
	
	/* give up */
        value[0] = '\0';
	return 0;

config_get_value_done:
	g_free(key);
	return 0;
}
static void
set_property (GObject *object, guint prop_id,
              const GValue *value, GParamSpec *pspec)
{
    NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE (object);

    switch (prop_id) {
    case PROP_HW_ADDRESS:
        /* Construct only */
        priv->bdaddr = g_ascii_strup (g_value_get_string (value), -1);
        if (!nm_utils_hwaddr_aton (priv->bdaddr, ARPHRD_ETHER, &priv->hw_addr))
            nm_log_err (LOGD_HW, "Failed to convert BT address '%s'", priv->bdaddr);
        break;
    case PROP_BT_NAME:
        /* Construct only */
        priv->name = g_value_dup_string (value);
        break;
    case PROP_BT_CAPABILITIES:
        /* Construct only */
        priv->capabilities = g_value_get_uint (value);
        break;
    default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
        break;
    }
}
Пример #7
0
static void
xlsx_func_map_out (GnmConventionsOut *out, GnmExprFunction const *func)
{
	XLSXExprConventions const *xconv = (XLSXExprConventions const *)(out->convs);
	char const *name = gnm_func_get_name (func->func, FALSE);
	gboolean (*handler) (GnmConventionsOut *out, GnmExprFunction const *func);

	handler = g_hash_table_lookup (xconv->xlfn_handler_map, name);

	if (handler == NULL || !handler (out, func)) {
		char const *new_name = g_hash_table_lookup (xconv->xlfn_map, name);
		GString *target = out->accum;

		if (new_name == NULL) {
				char *new_u_name;
				new_u_name = g_ascii_strup (name, -1);
				if (func->func->impl_status ==
				    GNM_FUNC_IMPL_STATUS_UNIQUE_TO_GNUMERIC)
					g_string_append (target, "_xlfngnumeric.");
				/* LO & friends use _xlfnodf */
				g_string_append (target, new_u_name);
				g_free (new_u_name);
		}
		else {
			g_string_append (target, "_xlfn.");
			g_string_append (target, new_name);
		}

		gnm_expr_list_as_string (func->argc, func->argv, out);
	}
	return;
}
Пример #8
0
static DBusMessage *sync_setlocation(DBusConnection *connection,
			DBusMessage *message, void *user_data)
{
	struct session_data *session = user_data;
	struct sync_data *syncdata = session_get_data(session);
	const char *location;
	char *path = NULL, *tmp;

	if (dbus_message_get_args(message, NULL,
			DBUS_TYPE_STRING, &location,
			DBUS_TYPE_INVALID) == FALSE)
		return g_dbus_create_error(message,
			ERROR_INF ".InvalidArguments", NULL);

	if (!g_ascii_strcasecmp(location, "INT") ||
			!g_ascii_strcasecmp(location, "INTERNAL"))
		path = g_strdup("telecom/pb.vcf");
	else if (!g_ascii_strncasecmp(location, "SIM", 3)) {
		tmp = g_ascii_strup(location, 4);
		path = g_build_filename(tmp, "telecom/pb.vcf", NULL);
		g_free(tmp);
	} else
		return g_dbus_create_error(message,
			ERROR_INF ".InvalidArguments", "InvalidPhonebook");

	g_free(syncdata->phonebook_path);
	syncdata->phonebook_path = path;

	return dbus_message_new_method_return(message);
}
Пример #9
0
static gchar *build_phonebook_path(const char *location, const char *item)
{
	gchar *path = NULL, *tmp, *tmp1;

	if (!g_ascii_strcasecmp(location, "INT") ||
			!g_ascii_strcasecmp(location, "INTERNAL"))
		path = g_strdup("telecom");
	else if (!g_ascii_strncasecmp(location, "SIM", 3)) {
		if (strlen(location) == 3)
			tmp = g_strdup("SIM1");
		else
			tmp = g_ascii_strup(location, 4);

		path = g_build_filename(tmp, "telecom", NULL);
		g_free(tmp);
	} else
		return NULL;

	if (!g_ascii_strcasecmp(item, "PB") ||
		!g_ascii_strcasecmp(item, "ICH") ||
		!g_ascii_strcasecmp(item, "OCH") ||
		!g_ascii_strcasecmp(item, "MCH") ||
		!g_ascii_strcasecmp(item, "CCH")) {
		tmp = path;
		tmp1 = g_ascii_strdown(item, -1);
		path = g_build_filename(tmp, tmp1, NULL);
		g_free(tmp);
		g_free(tmp1);
	} else {
		g_free(path);
		return NULL;
	}

	return path;
}
Пример #10
0
int
ns__get_radar_data(soap* soap, int sessionID, char* site, char* product, struct DateTime time, struct RadarData* result)
{
	DarxendClient* client = client_manager_get_client(sessionID);
	if (!client)
		return die_bad_client(soap);

	unsigned int length = 0;

	gchar* psite = g_ascii_strdown(site, -1);
	gchar* pproduct = g_ascii_strup(product, -1);

	char* data = radar_data_manager_read_data(psite, pproduct, time, &length);

	g_free(psite);
	g_free(pproduct);

	if (!data)
		return soap_receiver_fault(soap, "Data not found", NULL);

	gchar* b64data = g_base64_encode((guchar*)data, length);
	free(data);
	result->data = (char*)soap_malloc(soap, strlen(b64data));
	strcpy(result->data, b64data);
	g_free(b64data);

	return SOAP_OK;
}
Пример #11
0
static gboolean
filter_string_ascii_case (const TpCMParamSpec *param_spec,
    GValue *value,
    GError **error)
{
  const gchar *s = g_value_get_string (value);
  guint i;

  for (i = 0; s[i] != '\0'; i++)
    {
      int c = s[i];           /* just to avoid -Wtype-limits */

      if (c < 0 || c > 127)   /* char might be signed or unsigned */
        {
          g_set_error (error, TP_ERRORS, TP_ERROR_INVALID_ARGUMENT,
              "%s must be ASCII", param_spec->name);
          return FALSE;
        }
    }

  if (GINT_TO_POINTER (param_spec->filter_data))
    g_value_take_string (value, g_ascii_strup (s, -1));
  else
    g_value_take_string (value, g_ascii_strdown (s, -1));

  return TRUE;
}
/**
 * geoclue_address_details_set_country_from_code:
 * @address: #GHashTable with address data
 *
 * Uses the "ISO 3166-1 alpha-2" list to figure out the country name matching
 * the country code in @details, and adds the country name to details.
 *
 * Using this function in providers is useful even when the data source includes
 * country name: this way names are standardized.
 */
void
geoclue_address_details_set_country_from_code (GHashTable *address)
{
	static GHashTable *country_table = NULL;
	const char *code;
	const char *country = NULL;

	if (!country_table) {
		int i;

		country_table = g_hash_table_new (g_str_hash, g_str_equal);
		for (i = 0; countries[i][0]; i++) {
			g_hash_table_insert (country_table, countries[i][0], countries[i][1]);
		}
	}

	code = g_hash_table_lookup (address, GEOCLUE_ADDRESS_KEY_COUNTRYCODE);
	if (code) {
		char *upper = g_ascii_strup (code, -1);
		country = g_hash_table_lookup (country_table, upper);
		g_free (upper);
	}

	if (country) {
		geoclue_address_details_insert (
		    address, GEOCLUE_ADDRESS_KEY_COUNTRY, country);
	} else {
		g_hash_table_remove (address, GEOCLUE_ADDRESS_KEY_COUNTRY);
	}
}
gboolean to_bool(gchar *val)
{
  if (g_strcmp0(g_ascii_strup(val, -1), "TRUE"))
    return TRUE;
  else
    return FALSE;
}
Пример #14
0
Файл: app.c Проект: GnLWeB/balde
static GLogLevelFlags
balde_get_log_level_flag_from_string(const gchar *level)
{
    if (level == NULL)
        return G_LOG_LEVEL_MESSAGE;

    gchar *level_str = g_ascii_strup(level, -1);

    GLogLevelFlags level_flag = G_LOG_LEVEL_MESSAGE;
    if (g_strcmp0(level_str, "CRITICAL") == 0)
        level_flag = G_LOG_LEVEL_CRITICAL;
    else if (g_strcmp0(level_str, "WARNING") == 0)
        level_flag = G_LOG_LEVEL_WARNING;
    else if (g_strcmp0(level_str, "MESSAGE") == 0)
        level_flag = G_LOG_LEVEL_MESSAGE;
    else if (g_strcmp0(level_str, "INFO") == 0)
        level_flag = G_LOG_LEVEL_INFO;
    else if (g_strcmp0(level_str, "DEBUG") == 0)
        level_flag = G_LOG_LEVEL_DEBUG;
    else
        g_printerr("ERROR: Invalid log level, defaulting to MESSAGE ...\n");

    g_free(level_str);
    return level_flag;
}
Пример #15
0
static void remmina_tp_channel_handler_get_service(TpProxy *channel, const GValue *service, const GError *error,
		gpointer user_data, GObject *weak_object)
{
	RemminaTpChannelHandler *chandler = (RemminaTpChannelHandler *) user_data;
	const gchar *svc;

	if (error != NULL)
	{
		g_print("remmina_tp_channel_handler_get_service: %s", error->message);
		remmina_tp_channel_handler_free(chandler);
		return;
	}
	svc = g_value_get_string(service);
	g_print("remmina_tp_channel_handler_get_service: %s %s:%u\n", svc, chandler->host, chandler->port);

	if (g_strcmp0(svc, "rfb") == 0)
	{
		chandler->protocol = g_strdup("VNC");
	}
	else
	{
		chandler->protocol = g_ascii_strup(svc, -1);
	}
	remmina_tp_channel_handler_connect(chandler);
}
Пример #16
0
gboolean
my_object_many_args (MyObject *obj, guint32 x, const char *str, double trouble, double *d_ret, char **str_ret, GError **error)
{
  *d_ret = trouble + (x * 2);
  *str_ret = g_ascii_strup (str, -1);
  return TRUE;
}
Пример #17
0
void
token_set_algorithm ( Token *token, const gchar *str, GError **err)
{
  gchar* str_up;
  Algorithm alg;
  
  str_up = g_ascii_strup ( str, -1 );
  for ( alg=0; alg < N_OTP_ALGORITHMS; ++alg ){
    if ( g_strcmp0( algorithm_labels[alg], str_up ) == 0 )
      break;
  }
  g_free ( str_up );
  if ( alg == N_OTP_ALGORITHMS ){
    g_set_error ( err, OTP_ERROR, OTP_ERROR_INVALID_TOKEN,
		  "Invalid algorithm '%s'.", str );
    return;
  }
  
  token->algorithm = alg;
  switch ( alg )
    {
    case HOTP: 
      token->interval = DEFAULT_HOTP_INTERVAL;
      token->counter = DEFAULT_COUNTER; 
      break;
      
    case MOTP:
	token->interval = DEFAULT_MOTP_INTERVAL;
	token->counter = DEFAULT_COUNTER;
	break;

    default:;
    }

}
Пример #18
0
static gint
slng_verbose(int argc, char *argv[], const gchar *mode)
{
  gint ret = 0;
  GString *rsp = NULL;
  gchar buff[256], *ubuff;

  if (!verbose_set)
    snprintf(buff, 255, "LOG %s\n", mode);
  else
    snprintf(buff, 255, "LOG %s %s\n", mode,
        strncasecmp(verbose_set, "on", 2) == 0 || verbose_set[0] == '1' ? "ON" : "OFF");

  ubuff = g_ascii_strup(buff, -1);

  if (!(slng_send_cmd(ubuff) && ((rsp = slng_read_response()) != NULL)))
    {
      g_free(ubuff);
      return 1;
    }
  g_free(ubuff);

  if (!verbose_set)
    printf("%s\n", rsp->str);
  else
    ret = g_str_equal(rsp->str, "OK");

  g_string_free(rsp, TRUE);

  return ret;
}
Пример #19
0
void entry_clamp_text(GtkEntry *entry, int length, int setcase, int allowed(char))
{
    const gchar *text;
    gchar *clamped, *ptr_put, *ptr_get;

    text = gtk_entry_get_text(entry);

    switch (setcase) {
    case 1:
        clamped = g_ascii_strup(text, length);
        break;
    case -1:
        clamped = g_ascii_strdown(text, length);
        break;
    default:
        clamped = g_strndup(text, length);
    }

    ptr_put = ptr_get = clamped;
    while (*ptr_get) {
        if (allowed == NULL || allowed(*ptr_get)) {
            *ptr_put = *ptr_get;
            ptr_put++;
        }
        ptr_get++;
    }
    *ptr_put = '\0';

    gtk_entry_set_text(entry, clamped);
    g_free(clamped);
    /* *text need not be freed per gtk_entry_get_text docs */
}
Пример #20
0
void
ttl_sgml_print (OntologyDescription *description,
                Ontology *ontology,
                FILE *f,
                FILE *fts,
                const gchar *explanation_file)
{
        gchar *upper_name;

        upper_name = g_ascii_strup (description->localPrefix, -1);

        qname_init (description->baseUrl, description->localPrefix, NULL);
	print_sgml_header (f, description);

        /* FIXME: make desc files sgml */
	print_sgml_explanation (f, explanation_file);

        g_fprintf (f, "<section id='%s-classes'>\n", description->localPrefix);
	g_fprintf (f, "<title>%s Ontology Classes</title>\n", upper_name);
	g_hash_table_foreach (ontology->classes, print_ontology_class, f);
        g_fprintf (f, "</section>\n");

        g_fprintf (f, "<section id='%s-properties'>\n", description->localPrefix);
	g_fprintf (f, "<title>%s Ontology Properties</title>\n", upper_name);
	g_hash_table_foreach (ontology->properties, print_ontology_property, f);
        g_fprintf (f, "</section>\n");

	print_sgml_footer (f);

        g_free (upper_name);

        if (fts) {
                g_hash_table_foreach (ontology->properties, print_fts_properties, fts);
        }
}
Пример #21
0
void gaym_update_channel_member(struct gaym_conn *gaym, const char *nick,
                                const char *info)
{
    GaymBuddy *cm = gaym_get_channel_member_reference(gaym, nick);
    if (!cm) {
        gaim_debug_error("gaym",
                         "ERROR: A member has joined a channel, or a conversation was opened, but we were unable to add the member to the internal management structure. Report a bug.");
        return;
    } else {
        gchar *stats = gaym_stats_strdup(info);
        if (stats) {
            gchar **s = g_strsplit(stats, "|", 3);
            if (s[0] && strlen(g_strstrip(s[0])) > 0) {
                cm->sex = g_ascii_strup(s[0], -1);
            }
            if (s[1] && strlen(g_strstrip(s[1])) > 0) {
                cm->age = g_strdup(s[1]);
            }
            if (s[2] && strlen(g_strstrip(s[2])) > 0) {
                cm->location = g_strdup(s[2]);
            }
            g_strfreev(s);
            g_free(stats);
        }
        cm->name = g_strdup(nick);
        cm->bio = gaym_bio_strdup(info);
        cm->thumbnail = gaym_thumbnail_strdup(info);

    }
}
Пример #22
0
static void
print_sgml_header (FILE *f, OntologyDescription *desc)
{
        gchar *upper_name;

        g_fprintf (f, "<?xml version='1.0' encoding='UTF-8'?>\n");

        g_fprintf (f, "<chapter id='%s-ontology'>\n", desc->localPrefix);

        upper_name = g_ascii_strup (desc->localPrefix, -1);
        g_fprintf (f, "<title>%s: %s</title>\n", desc->title, desc->description ? desc->description : "");
        g_free (upper_name);

        print_people_list (f, "Authors:", desc->authors);
        print_people_list (f, "Editors:", desc->editors);
        print_people_list (f, "Contributors:", desc->contributors);

        print_link_as_varlistentry (f, "Upstream:", "Upstream version", desc->upstream);
        print_link_as_varlistentry (f, "ChangeLog:", "Tracker changes", desc->gitlog);

        g_fprintf (f, "<varlistentry>\n");
        g_fprintf (f, "  <term>Copyright:</term>\n");
        g_fprintf (f, "  <listitem>\n");
        g_fprintf (f, "<para>%s</para>\n", (desc->copyright ? desc->copyright : DEFAULT_COPYRIGHT));
        g_fprintf (f, "  </listitem>\n");
        g_fprintf (f, "</varlistentry>\n");
}
Пример #23
0
static gboolean
add_property_to_msg (HalDevice *device, HalProperty *property, 
                                     gpointer user_data)
{
  char *prop_upper, *value;
  char *c;
  gchar *env;
  DBusMessageIter *iter = (DBusMessageIter *)user_data;
  
  prop_upper = g_ascii_strup (hal_property_get_key (property), -1);
 
  /* periods aren't valid in the environment, so replace them with
   * underscores. */
  for (c = prop_upper; *c; c++) {
    if (*c == '.')
      *c = '_';
  }

  value = hal_property_to_string (property);
  env = g_strdup_printf ("HAL_PROP_%s=%s", prop_upper, value);
  dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &env);

  g_free (env);
  g_free (value);
  g_free (prop_upper);

  return TRUE;
}
Пример #24
0
static int core_upcase (lua_State *L)
{
  gchar *str = g_ascii_strup (luaL_checkstring (L, 1), -1);
  lua_pushstring (L, str);
  g_free (str);
  return 1;
}
Пример #25
0
int gKey::fromString(char *str)
{
	char *lstr;
	int key;
	
	if (!str || !*str)
		return 0;
	
	lstr = g_ascii_strup(str, -1);
	key = gdk_keyval_from_name(lstr);
	g_free(lstr);
	if (key) return key;

	lstr = g_ascii_strdown(str, -1);
	key = gdk_keyval_from_name(lstr);
	g_free(lstr);
	if (key) return key;

	key = gdk_keyval_from_name(str);
	if (key) return key;

	if (!str[1] && isascii(str[0]))
		return str[0];
	else
		return 0;
}
Пример #26
0
/**
 * gst_pb_utils_get_source_description:
 * @protocol: the protocol the source element needs to handle, e.g. "http"
 *
 * Returns a localised string describing a source element handling the protocol
 * specified in @protocol, for use in error dialogs or other messages to be
 * seen by the user. Should never return NULL unless @protocol is invalid.
 *
 * This function is mainly for internal use, applications would typically
 * use gst_missing_plugin_message_get_description() to get a description of
 * a missing feature from a missing-plugin message.
 *
 * Returns: a newly-allocated description string, or NULL on error. Free
 *          string with g_free() when not needed any longer.
 */
gchar *
gst_pb_utils_get_source_description (const gchar * protocol)
{
  gchar *proto_uc, *ret;

  g_return_val_if_fail (protocol != NULL, NULL);

  if (strcmp (protocol, "cdda") == 0)
    return g_strdup (_("Audio CD source"));

  if (strcmp (protocol, "dvd") == 0)
    return g_strdup (_("DVD source"));

  if (strcmp (protocol, "rtsp") == 0)
    return g_strdup (_("Real Time Streaming Protocol (RTSP) source"));

  /* TODO: what about mmst, mmsu, mmsh? */
  if (strcmp (protocol, "mms") == 0)
    return g_strdup (_("Microsoft Media Server (MMS) protocol source"));

  /* make protocol uppercase */
  proto_uc = g_ascii_strup (protocol, -1);

  /* TODO: find out how to add a comment for translators to the source code
   * (and tell them to make the first letter uppercase below if they move
   * the protocol to the middle or end of the string) */
  ret = g_strdup_printf (_("%s protocol source"), proto_uc);

  g_free (proto_uc);

  return ret;
}
Пример #27
0
void
str_init_strings (const char *termenc)
{
    codeset = termenc != NULL ? g_ascii_strup (termenc, -1) : g_strdup (str_detect_termencoding ());

    str_cnv_not_convert = g_iconv_open (codeset, codeset);
    if (str_cnv_not_convert == INVALID_CONV)
    {
        if (termenc != NULL)
        {
            g_free (codeset);
            codeset = g_strdup (str_detect_termencoding ());
            str_cnv_not_convert = g_iconv_open (codeset, codeset);
        }

        if (str_cnv_not_convert == INVALID_CONV)
        {
            g_free (codeset);
            codeset = g_strdup (DEFAULT_CHARSET);
            str_cnv_not_convert = g_iconv_open (codeset, codeset);
        }
    }

    str_cnv_to_term = str_cnv_not_convert;
    str_cnv_from_term = str_cnv_not_convert;

    str_choose_str_functions ();
}
Пример #28
0
static char *
get_eap_label (NMSettingWirelessSecurity *sec,
			   NMSetting8021x *s_8021x)
{
	GString *str = NULL;
	char *phase2_str = NULL;

	if (sec) {
		const char *key_mgmt = nm_setting_wireless_security_get_key_mgmt (sec);
		const char *auth_alg = nm_setting_wireless_security_get_auth_alg (sec);

		if (!strcmp (key_mgmt, "ieee8021x")) {
			if (auth_alg && !strcmp (auth_alg, "leap"))
				str = g_string_new (_("LEAP"));
			else
				str = g_string_new (_("Dynamic WEP"));
		} else if (!strcmp (key_mgmt, "wpa-eap"))
			str = g_string_new (_("WPA/WPA2"));
		else
			return NULL;
	} else if (s_8021x)
		str = g_string_new ("802.1x");

	if (!s_8021x)
		goto out;

	if (nm_setting_802_1x_get_num_eap_methods (s_8021x)) {
		char *eap_str = g_ascii_strup (nm_setting_802_1x_get_eap_method (s_8021x, 0), -1);
		g_string_append_printf (str, ", EAP-%s", eap_str);
		g_free (eap_str);
	}

	if (nm_setting_802_1x_get_phase2_auth (s_8021x))
		phase2_str = g_ascii_strup (nm_setting_802_1x_get_phase2_auth (s_8021x), -1);
	else if (nm_setting_802_1x_get_phase2_autheap (s_8021x))
		phase2_str = g_ascii_strup (nm_setting_802_1x_get_phase2_autheap (s_8021x), -1);

	if (phase2_str) {
		g_string_append (str, ", ");
		g_string_append (str, phase2_str);
		g_free (phase2_str);
	}
	
out:
	return g_string_free (str, FALSE);
}
Пример #29
0
GstCaps *
fs_codec_to_gst_caps (const FsCodec *codec)
{
  GstCaps *caps;
  GstStructure *structure;
  GList *item;

  if (codec == NULL)
    return NULL;

  structure = gst_structure_new ("application/x-rtp", NULL);

  if (codec->encoding_name)
  {
    gchar *encoding_name = g_ascii_strup (codec->encoding_name, -1);

    if (!g_ascii_strcasecmp (encoding_name, "H263-N800")) {
      g_free (encoding_name);
      encoding_name = g_strdup ("H263-1998");
    }

    gst_structure_set (structure,
        "encoding-name", G_TYPE_STRING, encoding_name,
        NULL);
    g_free (encoding_name);
  }

  if (codec->clock_rate)
    gst_structure_set (structure,
      "clock-rate", G_TYPE_INT, codec->clock_rate, NULL);

  if (fs_media_type_to_string (codec->media_type))
    gst_structure_set (structure, "media", G_TYPE_STRING,
      fs_media_type_to_string (codec->media_type), NULL);

  if (codec->id >= 0 && codec->id < 128)
    gst_structure_set (structure, "payload", G_TYPE_INT, codec->id, NULL);

  if (codec->channels)
    gst_structure_set (structure, "channels", G_TYPE_INT, codec->channels,
      NULL);

  for (item = codec->optional_params;
       item;
       item = g_list_next (item)) {
    FsCodecParameter *param = item->data;
    gchar *lower_name = g_ascii_strdown (param->name, -1);
    gst_structure_set (structure, lower_name, G_TYPE_STRING, param->value,
      NULL);
    g_free (lower_name);
  }

  caps = gst_caps_new_full (structure, NULL);

  return caps;
}
Пример #30
0
static char * fmtUniqueLogId(char *dest, const char *pFile, guint32 lineNbr)
{
    const char *pStart = strrchr (pFile, '/');
    gchar *str = g_ascii_strup((pStart ? pStart + 1 : pFile), MSGID_LENGTH - 6);
    char *ptr = strchr(str, '.');
    if (ptr) *ptr = '\0'; // trim off file extensions
    snprintf (dest, MSGID_LENGTH, "%s#%d", str, lineNbr);
    g_free (str);
    return dest;
}