Пример #1
0
struct ejudge_cfg *
ejudge_cfg_do_parse(char const *path)
{
  struct xml_tree *tree = 0, *p;
  struct ejudge_cfg *cfg = 0;
  struct xml_attr *a;
  unsigned char **p_str;

  xml_err_path = path;
  xml_err_spec = &ejudge_config_parse_spec;

  tree = xml_build_tree(NULL, path, &ejudge_config_parse_spec);
  if (!tree) return 0;
  if (tree->tag != TG_CONFIG) {
    xml_err_top_level(tree, TG_CONFIG);
    goto failed;
  }
  cfg = (struct ejudge_cfg *) tree;
  xfree(cfg->b.text); cfg->b.text = 0;
  cfg->l10n = -1;

  cfg->ejudge_xml_path = xstrdup(path);

  for (a = cfg->b.first; a; a = a->next) {
    switch (a->tag) {
    case AT_ENABLE_L10N:
    case AT_DISABLE_L10N:
    case AT_L10N:
      if (xml_attr_bool(a, &cfg->l10n) < 0) goto failed;
      if (a->tag == AT_DISABLE_L10N) cfg->l10n = !cfg->l10n;
      break;
    case AT_DISABLE_COOKIE_IP_CHECK:
      if (xml_attr_bool(a, &cfg->disable_cookie_ip_check) < 0) goto failed;
      break;
    case AT_ENABLE_COOKIE_IP_CHECK:
      if (xml_attr_bool(a, &cfg->enable_cookie_ip_check) < 0) goto failed;
      break;
    case AT_ENABLE_CONTEST_SELECT:
      if (xml_attr_bool(a, &cfg->enable_contest_select) < 0) goto failed;
      break;
    case AT_DISABLE_NEW_USERS:
      if (xml_attr_bool(a, &cfg->disable_new_users) < 0) goto failed;
      break;
    default:
      xml_err_attr_not_allowed(&cfg->b, a);
      goto failed;
    }
  }

  for (p = cfg->b.first_down; p; p = p->right) {
    if (cfg_final_offsets[p->tag] > 0) {
      p_str = XPDEREF(unsigned char *, cfg, cfg_final_offsets[p->tag]);
      if (xml_leaf_elem(p, p_str, 1, 0) < 0) goto failed;
      continue;
    }
    switch (p->tag) {
    case TG_USER_MAP:
      if (!(cfg->user_map = parse_user_map(path, p))) goto failed;
      break;
    case TG_CAPS:
      if (parse_capabilities(cfg, p) < 0) goto failed;
      break;
    case TG_SERIALIZATION_KEY:
      {
        int k, n;

        if (cfg->serialization_key) {
          xml_err_elem_redefined(p);
          goto failed;
        }
        if (!p->text || !p->text[0]
            || sscanf(p->text, "%d%n", &k, &n) != 1 || p->text[n]
            || k <= 0 || k >= 32768) {
          xml_err_elem_invalid(p);
          goto failed;
        }
        cfg->serialization_key = k;
      }
      break;
    case TG_PLUGINS:
      if (parse_plugins(cfg, p) < 0) goto failed;
      break;
    case TG_COMPILE_SERVERS:
      if (parse_compile_servers(cfg, p) < 0) goto failed;
      break;
    case TG_SERVE_PATH:
      break;
    case TG_HOSTS_OPTIONS:
      cfg->hosts_options = p;
      break;
    default:
      xml_err_elem_not_allowed(p);
      break;
    }
  }
static void
props_changed_cb (GDBusProxy *proxy,
                  GVariant *changed_properties,
                  GStrv invalidated_properties,
                  gpointer user_data)
{
	NMSupplicantInterface *self = NM_SUPPLICANT_INTERFACE (user_data);
	NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self);
	const char *s, **array, **iter;
	gboolean b = FALSE;
	gint32 i32;
	GVariant *v;

	g_object_freeze_notify (G_OBJECT (self));

	if (g_variant_lookup (changed_properties, "Scanning", "b", &b))
		set_scanning (self, b);

	if (   g_variant_lookup (changed_properties, "State", "&s", &s)
	    && priv->state >= NM_SUPPLICANT_INTERFACE_STATE_READY) {
		/* Only transition to actual wpa_supplicant interface states (ie,
		 * anything > READY) after the NMSupplicantInterface has had a
		 * chance to initialize, which is signalled by entering the READY
		 * state.
		 */
		set_state_from_string (self, s);
	}

	if (g_variant_lookup (changed_properties, "BSSs", "^a&s", &array)) {
		iter = array;
		while (*iter)
			handle_new_bss (self, *iter++);
		g_free (array);
	}

	if (g_variant_lookup (changed_properties, "CurrentBSS", "&o", &s)) {
		if (strcmp (s, "/") == 0)
			s = NULL;
		if (g_strcmp0 (s, priv->current_bss) != 0) {
			g_free (priv->current_bss);
			priv->current_bss = g_strdup (s);
			g_object_notify (G_OBJECT (self), NM_SUPPLICANT_INTERFACE_CURRENT_BSS);
		}
	}

	v = g_variant_lookup_value (changed_properties, "Capabilities", G_VARIANT_TYPE_VARDICT);
	if (v) {
		parse_capabilities (self, v);
		g_variant_unref (v);
	}

	if (g_variant_lookup (changed_properties, "DisconnectReason", "i", &i32)) {
		/* Disconnect reason is currently only given for deauthentication events,
		 * not disassociation; currently they are IEEE 802.11 "reason codes",
		 * defined by (IEEE 802.11-2007, 7.3.1.7, Table 7-22).  Any locally caused
		 * deauthentication will be negative, while authentications caused by the
		 * AP will be positive.
		 */
		priv->disconnect_reason = i32;
		if (priv->disconnect_reason != 0) {
			nm_log_warn (LOGD_SUPPLICANT, "Connection disconnected (reason %d)",
				         priv->disconnect_reason);
		}
	}

	g_object_thaw_notify (G_OBJECT (self));
}
Пример #3
0
/// Parses the response from the HSS.
int ICSCFRouter::parse_hss_response(Json::Value& rsp, bool queried_caps)
{
  int status_code = PJSIP_SC_OK;

  // Clear out any older response.
  _queried_caps = false;
  _hss_rsp.mandatory_caps.clear();
  _hss_rsp.optional_caps.clear();
  _hss_rsp.scscf = "";

  if ((!rsp.isMember("result-code")) ||
      ((rsp["result-code"].asString() != "2001") &&
       (rsp["result-code"].asString() != "2002") &&
       (rsp["result-code"].asString() != "2003")))
  {
    // Error from HSS, so respond with 404 Not Found.  (This may be changed
    // to 403 Forbidden if request is a REGISTER.)
    status_code = PJSIP_SC_NOT_FOUND;
  }
  else
  {
    // Successful response from HSS, so parse it.
    if ((rsp.isMember("scscf")) &&
        (rsp["scscf"].isString()))
    {
      // Response specifies a S-CSCF, so select this as the target.
      LOG_DEBUG("HSS returned S-CSCF %s as target", rsp["scscf"].asCString());
      _hss_rsp.scscf = rsp["scscf"].asString();
    }

    if ((rsp.isMember("mandatory-capabilities")) &&
        (rsp["mandatory-capabilities"].isArray()) &&
        (rsp.isMember("optional-capabilities")) &&
        (rsp["optional-capabilities"].isArray()))
    {
      // Response specifies capabilities - we might have explicitly queried capabilities
      // or implicitly because there was no server assigned.
      LOG_DEBUG("HSS returned capabilities");
      queried_caps = true;
      if ((!parse_capabilities(rsp["mandatory-capabilities"], _hss_rsp.mandatory_caps)) ||
          (!parse_capabilities(rsp["optional-capabilities"], _hss_rsp.optional_caps)))
      {
        // Failed to parse capabilities, so reject with 480 response.
        LOG_WARNING("Malformed required capabilities returned by HSS\n%s",
                    rsp.toStyledString().c_str());
        status_code = PJSIP_SC_TEMPORARILY_UNAVAILABLE;
      }
    }
  }

  // Record whether or not we got valid capabilities from the HSS.  This can
  // either be because we forced capabilities in the query (in this case, empty
  // capabilities means the HSS doesn't care which S-CSCF we select) or because
  // the HSS decided to return capabilities anyway.
  _queried_caps = (status_code == PJSIP_SC_OK) ? queried_caps : false;

  if (_acr != NULL)
  {
    // Pass the server capabilities to the ACR for reporting.
    _acr->server_capabilities(_hss_rsp);
  }

  return status_code;
}
Пример #4
0
/// Parses the response from the HSS.
int ICSCFRouter::parse_hss_response(rapidjson::Document*& rsp, bool queried_caps)
{
  int status_code = PJSIP_SC_OK;

  // Clear out any older response.
  _queried_caps = false;
  _hss_rsp.mandatory_caps.clear();
  _hss_rsp.optional_caps.clear();
  _hss_rsp.scscf = "";

  if ((!rsp->HasMember("result-code")) ||
      (!(*rsp)["result-code"].IsInt()))
  {
    // Error from HSS, so respond with 404 Not Found.  (This may be changed
    // to 403 Forbidden if request is a REGISTER.)
    status_code = PJSIP_SC_NOT_FOUND;
  }
  else
  {
    int rc = (*rsp)["result-code"].GetInt();
  
    if ((rc == 2001) ||
        (rc == 2002) ||
        (rc == 2003))
    {
      // Successful response from HSS, so parse it.
      if ((rsp->HasMember("scscf")) &&
          ((*rsp)["scscf"].IsString()))
      {
        // Response specifies a S-CSCF, so select this as the target.
        TRC_DEBUG("HSS returned S-CSCF %s as target", (*rsp)["scscf"].GetString());
        _hss_rsp.scscf = (*rsp)["scscf"].GetString();
      }

      if ((rsp->HasMember("mandatory-capabilities")) &&
          ((*rsp)["mandatory-capabilities"].IsArray()) &&
          (rsp->HasMember("optional-capabilities")) &&
          ((*rsp)["optional-capabilities"].IsArray()))
      {
        // Response specifies capabilities - we might have explicitly 
        // queried capabilities or implicitly because there was no 
        // server assigned.
        TRC_DEBUG("HSS returned capabilities");
        queried_caps = true;
  
        if ((!parse_capabilities((*rsp)["mandatory-capabilities"], 
                                 _hss_rsp.mandatory_caps)) ||
            (!parse_capabilities((*rsp)["optional-capabilities"], 
                                 _hss_rsp.optional_caps)))
        {
          // Failed to parse capabilities, so reject with 480 response.
          TRC_INFO("Malformed required capabilities returned by HSS\n");
          status_code = PJSIP_SC_TEMPORARILY_UNAVAILABLE;
        }
      }
    }
    else if (rc == 5003)
    {
      // Failure response from HSS indicating that a subscriber exists but is unregistered and
      // has no unregistered services, so respond with 480 Temporarily Unavailable.
      status_code = PJSIP_SC_TEMPORARILY_UNAVAILABLE;
    }
    else
    {
      // Error from HSS, so respond with 404 Not Found.  (This may be changed
      // to 403 Forbidden if request is a REGISTER.)
      status_code = PJSIP_SC_NOT_FOUND;
    }
  }

  // Record whether or not we got valid capabilities from the HSS.  This can
  // either be because we forced capabilities in the query (in this case, empty
  // capabilities means the HSS doesn't care which S-CSCF we select) or because
  // the HSS decided to return capabilities anyway.
  _queried_caps = (status_code == PJSIP_SC_OK) ? queried_caps : false;

  if (_acr != NULL)
  {
    // Pass the server capabilities to the ACR for reporting.
    _acr->server_capabilities(_hss_rsp);
  }

  return status_code;
}
Пример #5
0
svn_error_t *
svn_ra_neon__exchange_capabilities(svn_ra_neon__session_t *ras,
                                   apr_pool_t *pool)
{
  svn_ra_neon__request_t* req;
  svn_error_t *err = SVN_NO_ERROR;
  ne_xml_parser *parser = NULL;
  options_ctx_t oc = { 0 };
  const char *msg;
  int status_code;

  oc.pool = pool;
  oc.cdata = svn_stringbuf_create("", pool);

  req = svn_ra_neon__request_create(ras, "OPTIONS", ras->url->data, pool);

  /* ### Use a symbolic name somewhere for this MIME type? */
  ne_add_request_header(req->ne_req, "Content-Type", "text/xml");

  /* Create a parser to read the normal response body */
  parser = svn_ra_neon__xml_parser_create(req, ne_accept_2xx, start_element,
                                          svn_ra_neon__xml_collect_cdata,
                                          end_element, &oc);

  /* Run the request and get the resulting status code. */
  if ((err = svn_ra_neon__request_dispatch(&status_code, req, NULL,
                                           "<?xml version=\"1.0\" "
                                           "encoding=\"utf-8\"?>"
                                           "<D:options xmlns:D=\"DAV:\">"
                                           "<D:activity-collection-set/>"
                                           "</D:options>",
                                           200, 0, pool)))
    goto cleanup;

  /* Was there an XML parse error somewhere? */
  msg = ne_xml_get_error(parser);
  if (msg && *msg)
    {
      err = svn_error_createf(SVN_ERR_RA_DAV_REQUEST_FAILED, NULL,
                              _("The %s request returned invalid XML "
                                "in the response: %s (%s)"),
                              "OPTIONS", msg, ras->url->data);
      goto cleanup;
    }

  /* We asked for, and therefore expect, to have found an activity
     collection in the response.  */
  if (oc.activity_coll == NULL)
    {
      err = svn_error_create(SVN_ERR_RA_DAV_OPTIONS_REQ_FAILED, NULL,
                             _("The OPTIONS response did not include the "
                               "requested activity-collection-set; this often "
                               "means that the URL is not WebDAV-enabled"));
      goto cleanup;
    }

  ras->act_coll = apr_pstrdup(ras->pool, oc.activity_coll->data);
  parse_capabilities(req->ne_req, ras, pool);

 cleanup:
  svn_ra_neon__request_destroy(req);

  return err;
}