示例#1
0
static void XMLCALL
charElement(void *userData, const XML_Char *s, int len)
{
	char buf[1024];

	struct XMLstate **state = userData;

	if (len > 1024)
		len = 1023;
	memcpy(buf, s, len);
	buf[len] = '\0';

	if (!(*state)->text) {
		(*state)->text = calloc(len + 1, 1);
	} else
		(*state)->text = realloc((*state)->text, strlen((*state)->text) + len + 1);

	if (!(*state)->text)
		return;

	if (((*state)->flags & XML_ESCAPED) == XML_ESCAPED)
		string_unescape((*state)->text, s, len);
	else
		strncat((*state)->text, s, len);
}
示例#2
0
/** Parses a series of space-separated key[=value|="value"] tokens from
 * <b>str</b> and returns the mappings in a QHash. If <b>str</b> was unable
 * to be parsed, <b>ok</b> is set to false. */
QHash<QString,QString>
string_parse_keyvals(const QString &str, bool *ok)
{
  int i, len;
  bool tmp_ok;
  QHash<QString,QString> keyvals;
  
  i = 0;
  len = str.length();
  while (i < len && str[i].isSpace())
    i++; /* Skip initial whitespace */
  while (i < len) {
    QString key, val;
    
    while (i < len && !str[i].isSpace() && str[i] != '=')
      key.append(str[i++]);
      
    if (i < len && str[i] == '=') {
      if (++i < len && str[i] == '\"') {
        /* The value is wrapped in quotes */
        val.append(str[i]);
        while (++i < len) {
          val.append(str[i]);
          if (str[i] == '\\') {
            if (++i == len)
              goto error;
            val.append(str[i]);
          } else if (str[i] == '\"') {
            i++;
            break;
          } 
        }
        val = string_unescape(val, &tmp_ok);
        if (!tmp_ok)
          goto error;
        keyvals.insert(key, val);
      } else {
        /* The value was not wrapped in quotes */
        while (i < len && !str[i].isSpace())
          val.append(str[i++]);
        keyvals.insert(key, val);
      }
    } else {
      /* The key had no value */
      keyvals.insert(key, QString(""));
    }
    while (i < len && str[i].isSpace())
      i++;
  }
  if (ok)
    *ok = true;
  return keyvals;

error:
  if (ok)
    *ok = false;
  return QHash<QString,QString>();
}
示例#3
0
/** Parses a series of command line arguments from <b>str</b>. If <b>str</b>
 * was unable to be parsed, <b>ok</b> is set to false. */
QStringList
string_parse_arguments(const QString &str, bool *ok)
{
  QStringList args;
  int i, len;
  bool tmp_ok;

  i = 0;
  len = str.length();
  while (i < len && str[i].isSpace())
    i++; /* Skip initial whitespace */
  while (i < len) {
    QString arg;
    
    if (str[i] == '\"') {
      /* The value is wrapped in quotes */
      arg.append(str[i]);
      while (++i < len) {
        arg.append(str[i]);
        if (str[i] == '\\') {
          if (++i == len)
            goto error;
          arg.append(str[i]);
        } else if (str[i] == '\"') {
          i++;
          break;
        } 
      }
      arg = string_unescape(arg, &tmp_ok);
      if (!tmp_ok)
        goto error;
      args << arg;
    } else {
      /* The value was not wrapped in quotes */
      while (i < len && !str[i].isSpace())
        arg.append(str[i++]);
      args << arg;
    }
    while (i < len && str[i].isSpace())
      i++;
  }

  if (ok)
    *ok = true;
  return args;

error:
  if (ok)
    *ok = false;
  return QStringList();
}
示例#4
0
文件: config.c 项目: XQF/xqf
char *config_get_string_with_default (const char *path, int *def) {
	char *val;

	val = config_get_raw_with_default (path, def);
	return (val)? string_unescape (val) : NULL;
}
示例#5
0
unsigned long pi_configlock_event_load_old (plugin_user_t * user, void *dummy, unsigned long event,
        buffer_t * token)
{
    FILE *fp;
    unsigned long l;
    char buffer[1024], *c;
    configlock_t *lock;
    config_element_t *elem;

    while (locklist) {
        lock = locklist;
        locklist = locklist->next;
        free (lock);
    }

    config_load_old (filename);

    fp = fopen (filename, "r");
    if (!fp)
        return PLUGIN_RETVAL_CONTINUE;

    while (fgets (buffer, 1024, fp)) {
        for (c = buffer; *c && *c != ' '; c++);
        if (!*c)
            continue;
        *c++ = '\0';
        elem = config_find (buffer);
        if (!elem)
            continue;

        lock = malloc (sizeof (configlock_t));
        memset (lock, 0, sizeof (configlock_t));

        lock->elem = elem;
        strncpy (lock->name, elem->name, CONFIG_NAMELENGTH);
        switch (elem->type) {
        case CFG_ELEM_PTR:
            sscanf (c, "%p", &lock->data.v_ptr);
            break;
        case CFG_ELEM_LONG:
            sscanf (c, "%ld", &lock->data.v_long);
            break;
        case CFG_ELEM_ULONG:
        case CFG_ELEM_CAP:
        case CFG_ELEM_MEMSIZE:
            sscanf (c, "%lu", &lock->data.v_ulong);
            break;
        case CFG_ELEM_BYTESIZE:
        case CFG_ELEM_ULONGLONG:
#ifndef USE_WINDOWS
            sscanf (c, "%Lu", &lock->data.v_ulonglong);
#else
            sscanf (c, "%I64u", &lock->data.v_ulonglong);
#endif
            break;
        case CFG_ELEM_INT:
            sscanf (c, "%d", &lock->data.v_int);
            break;
        case CFG_ELEM_UINT:
            sscanf (c, "%u", &lock->data.v_uint);
            break;
        case CFG_ELEM_DOUBLE:
            sscanf (c, "%lf", &lock->data.v_double);
            break;
        case CFG_ELEM_STRING:
            if (lock->data.v_string)
                free (lock->data.v_string);
            l = strlen (c);
            if (c[l - 1] == '\n')
                c[l-- - 1] = '\0';
            if ((*c == '"') && (c[l - 1] == '"')) {
                c[l - 1] = '\0';
                c++;
            };
            lock->data.v_string = string_unescape (c);
            break;
        case CFG_ELEM_IP:
        {
#ifdef HAVE_INET_NTOA
            struct in_addr ia;

            if (inet_aton (c, &ia))
                lock->data.v_ip = ia.s_addr;
#else
#warning "inet_ntoa not support. Support for CFG_ELEM_IP disabled."
#endif
            break;
        }
        }
        lock->next = locklist;
        locklist = lock;
    }
    fclose (fp);

    return PLUGIN_RETVAL_CONTINUE;
}