示例#1
0
文件: cfgfile.c 项目: xaiki/IceCast
static void _parse_relay(xmlDocPtr doc, xmlNodePtr node,
        ice_config_t *configuration)
{
    char *tmp;
    relay_server *relay = acalloc(1, sizeof(relay_server));
    relay_server *current = configuration->relay;
    relay_server *last=NULL;

    while(current) {
        last = current;
        current = current->next;
    }

    if(last)
        last->next = relay;
    else
        configuration->relay = relay;

    relay->next = NULL;
    relay->mp3metadata = 1;
    relay->on_demand = configuration->on_demand;
    relay->server = (char *)xmlCharStrdup ("127.0.0.1");
    relay->mount = (char *)xmlCharStrdup ("/");

    do {
        if (node == NULL) break;
        if (xmlIsBlankNode(node)) continue;

        if (xmlStrcmp (node->name, XMLSTR("server")) == 0) {
            if (relay->server) xmlFree (relay->server);
            relay->server = (char *)xmlNodeListGetString(
                    doc, node->xmlChildrenNode, 1);
        }
        else if (xmlStrcmp (node->name, XMLSTR("port")) == 0) {
            tmp = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
            relay->port = atoi(tmp);
            if(tmp) xmlFree(tmp);
        }
        else if (xmlStrcmp (node->name, XMLSTR("mount")) == 0) {
            if (relay->mount) xmlFree (relay->mount);
            relay->mount = (char *)xmlNodeListGetString(
                    doc, node->xmlChildrenNode, 1);
        }
        else if (xmlStrcmp (node->name, XMLSTR("local-mount")) == 0) {
            if (relay->localmount) xmlFree (relay->localmount);
            relay->localmount = (char *)xmlNodeListGetString(
                    doc, node->xmlChildrenNode, 1);
        }
        else if (xmlStrcmp (node->name, XMLSTR("relay-shoutcast-metadata")) == 0) {
            tmp = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
            relay->mp3metadata = atoi(tmp);
            if(tmp) xmlFree(tmp);
        }
        else if (xmlStrcmp (node->name, XMLSTR("username")) == 0) {
            if (relay->username) xmlFree (relay->username);
            relay->username = (char *)xmlNodeListGetString(doc,
                    node->xmlChildrenNode, 1);
        }
        else if (xmlStrcmp (node->name, XMLSTR("password")) == 0) {
            if (relay->password) xmlFree (relay->password);
            relay->password = (char *)xmlNodeListGetString(doc,
                    node->xmlChildrenNode, 1);
        }
        else if (xmlStrcmp (node->name, XMLSTR("on-demand")) == 0) {
            tmp = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
            relay->on_demand = atoi(tmp);
            if (tmp) xmlFree(tmp);
        }
        else if (xmlStrcmp (node->name, XMLSTR("bind")) == 0) {
            if (relay->bind) xmlFree (relay->bind);
            relay->bind = (char *)xmlNodeListGetString (doc, node->xmlChildrenNode, 1);
        }
    } while ((node = node->next));
    if (relay->localmount == NULL)
        relay->localmount = (char *)xmlStrdup (XMLSTR(relay->mount));
}
示例#2
0
void Nokogiri_marshal_xpath_funcall_and_return_values(xmlXPathParserContextPtr ctx, int nargs, VALUE handler, const char* function_name)
{
  int i;
  VALUE result, doc;
  VALUE *argv;
  VALUE node_set = Qnil;
  xmlNodeSetPtr xml_node_set = NULL;
  xmlXPathObjectPtr obj;

  assert(ctx->context->doc);
  assert(DOC_RUBY_OBJECT_TEST(ctx->context->doc));

  argv = (VALUE *)calloc((size_t)nargs, sizeof(VALUE));
  for (i = 0 ; i < nargs ; ++i) {
    rb_gc_register_address(&argv[i]);
  }

  doc = DOC_RUBY_OBJECT(ctx->context->doc);

  if (nargs > 0) {
    i = nargs - 1;
    do {
      obj = valuePop(ctx);
      switch(obj->type) {
        case XPATH_STRING:
          argv[i] = NOKOGIRI_STR_NEW2(obj->stringval);
          break;
        case XPATH_BOOLEAN:
          argv[i] = obj->boolval == 1 ? Qtrue : Qfalse;
          break;
        case XPATH_NUMBER:
          argv[i] = rb_float_new(obj->floatval);
          break;
        case XPATH_NODESET:
          argv[i] = Nokogiri_wrap_xml_node_set(obj->nodesetval, doc);
          break;
        default:
          argv[i] = NOKOGIRI_STR_NEW2(xmlXPathCastToString(obj));
      }
      xmlXPathFreeNodeSetList(obj);
    } while(i-- > 0);
  }

  result = rb_funcall2(handler, rb_intern((const char*)function_name), nargs, argv);

  for (i = 0 ; i < nargs ; ++i) {
    rb_gc_unregister_address(&argv[i]);
  }
  free(argv);

  switch(TYPE(result)) {
    case T_FLOAT:
    case T_BIGNUM:
    case T_FIXNUM:
      xmlXPathReturnNumber(ctx, NUM2DBL(result));
      break;
    case T_STRING:
      xmlXPathReturnString(
          ctx,
          xmlCharStrdup(StringValuePtr(result))
      );
      break;
    case T_TRUE:
      xmlXPathReturnTrue(ctx);
      break;
    case T_FALSE:
      xmlXPathReturnFalse(ctx);
      break;
    case T_NIL:
      break;
    case T_ARRAY:
      {
        VALUE args[2];
        args[0] = doc;
        args[1] = result;
        node_set = rb_class_new_instance(2, args, cNokogiriXmlNodeSet);
        Data_Get_Struct(node_set, xmlNodeSet, xml_node_set);
        xmlXPathReturnNodeSet(ctx, xmlXPathNodeSetMerge(NULL, xml_node_set));
      }
    break;
    case T_DATA:
      if(rb_obj_is_kind_of(result, cNokogiriXmlNodeSet)) {
        Data_Get_Struct(result, xmlNodeSet, xml_node_set);
        /* Copy the node set, otherwise it will get GC'd. */
        xmlXPathReturnNodeSet(ctx, xmlXPathNodeSetMerge(NULL, xml_node_set));
        break;
      }
    default:
      rb_raise(rb_eRuntimeError, "Invalid return type");
    }
}
示例#3
0
static GList *
anjuta_profile_read_plugins_from_xml (AnjutaProfile *profile,
									  GFile *file,
									  GError **error)
{
	gchar *read_buf;
	gsize size;
	xmlDocPtr xml_doc;
	GList *descs_list = NULL;
	GList *not_found_names = NULL;
	GList *not_found_urls = NULL;
	gboolean parse_error;

	/* Read xml file */
	if (!g_file_load_contents (file, NULL, &read_buf, &size, NULL, error))
	{
		return NULL;
	}
	
	/* Parse xml file */
	parse_error = TRUE;
	xml_doc = xmlParseMemory (read_buf, size);
	g_free (read_buf);
	if (xml_doc != NULL)
	{
		xmlNodePtr xml_root;
		
		xml_root = xmlDocGetRootElement(xml_doc);
		if (xml_root &&
			(xml_root->name) &&
			xmlStrEqual(xml_root->name, (const xmlChar *)"anjuta"))
		{
			xmlNodePtr xml_node;

			parse_error = FALSE;
			for (xml_node = xml_root->xmlChildrenNode; xml_node; xml_node = xml_node->next)
			{
				GList *groups = NULL;
				GList *attribs = NULL;
				GList *values = NULL;
				xmlChar *name, *url, *mandatory_text;
				xmlNodePtr xml_require_node;
				gboolean mandatory;

				if (!xml_node->name ||
					!xmlStrEqual (xml_node->name, (const xmlChar*)"plugin"))
				{
					continue;
				}
	
				name = xmlGetProp (xml_node, (const xmlChar*)"name");
				url = xmlGetProp (xml_node, (const xmlChar*)"url");
		
				/* Ensure that both name is given */
				if (!name)
				{
					g_warning ("XML error: Plugin name should be present in plugin tag");
					parse_error = TRUE;
					break;
				}
				if (!url)
					url = xmlCharStrdup ("http://anjuta.org/plugins/");
									 
				/* Check if the plugin is mandatory */
				mandatory_text = xmlGetProp (xml_node, (const xmlChar*)"mandatory");
				mandatory = mandatory_text && (xmlStrcasecmp (mandatory_text, (const xmlChar *)"yes") == 0);
				xmlFree(mandatory_text);
										 
				/* For all plugin attribute conditions */
				for (xml_require_node = xml_node->xmlChildrenNode;
			 		xml_require_node;
			 		xml_require_node = xml_require_node->next)
				{
					xmlChar *group;
					xmlChar *attrib;
					xmlChar *value;
		
					if (!xml_require_node->name ||
						!xmlStrEqual (xml_require_node->name,
									  (const xmlChar*)"require"))
					{
						continue;
					}
					group = xmlGetProp (xml_require_node,
										(const xmlChar *)"group");
					attrib = xmlGetProp(xml_require_node,
										(const xmlChar *)"attribute");
					value = xmlGetProp(xml_require_node,
									   (const xmlChar *)"value");
			
					if (group && attrib && value)
					{
						groups = g_list_prepend (groups, group);
						attribs = g_list_prepend (attribs, attrib);
						values = g_list_prepend (values, value);
					}
					else
					{
						if (group) xmlFree (group);
						if (attrib) xmlFree (attrib);
						if (value) xmlFree (value);
						parse_error = TRUE;
						g_warning ("XML parse error: group, attribute and value should be defined in require");
						break;
					}
				}

				if (!parse_error)
				{
					if (g_list_length (groups) == 0)
					{
						parse_error = TRUE;
						g_warning ("XML Error: No attributes to match given");
					}
					else
					{
						GList *plugin_descs;
						
						plugin_descs =
							anjuta_plugin_manager_list_query (profile->priv->plugin_manager,
															  groups,
															  attribs,
															  values);
						if (plugin_descs)
						{
							descs_list = g_list_prepend (descs_list, plugin_descs);
						}
						else if (mandatory)
						{
							not_found_names = g_list_prepend (not_found_names, g_strdup ((const gchar *)name));
							not_found_urls = g_list_prepend (not_found_urls, g_strdup ((const gchar *)url));
						}
					}
				}
				g_list_foreach (groups, (GFunc)xmlFree, NULL);
				g_list_foreach (attribs, (GFunc)xmlFree, NULL);
				g_list_foreach (values, (GFunc)xmlFree, NULL);
				g_list_free (groups);
				g_list_free (attribs);
				g_list_free (values);
				xmlFree (name);
				xmlFree (url);
			}
		}
		xmlFreeDoc(xml_doc);
	}
	
	if (parse_error)
	{
		/* Error during parsing */
		gchar *uri = g_file_get_uri (file);

		g_set_error (error, ANJUTA_PROFILE_ERROR,
					 ANJUTA_PROFILE_ERROR_URI_READ_FAILED,
					 _("Failed to read '%s': XML parse error. "
					   "Invalid or corrupted Anjuta plugins profile."),
			 		uri);
		g_free (uri);
		
		g_list_foreach (descs_list, (GFunc)g_list_free, NULL);
		g_list_free (descs_list);
		descs_list = NULL;
	}
	else if (not_found_names)
	{
		/*
	 	* FIXME: Present a nice dialog box to promt the user to download
		* the plugin from corresponding URLs, install them and proceed.
 		*/	
		GList *node_name, *node_url;
		GString *mesg = g_string_new ("");
		gchar *uri = g_file_get_uri (file);
			
		not_found_names = g_list_reverse (not_found_names);
		not_found_urls = g_list_reverse (not_found_urls);
		
		node_name = not_found_names;
		node_url = not_found_urls;
		while (node_name)
		{
			/* <Pluginname>: Install it from <some location on the web> */
			g_string_append_printf (mesg, _("%s: Install it from '%s'\n"),
											(char *)node_name->data,
											(char*)node_url->data);
			node_name = g_list_next (node_name);
			node_url = g_list_next (node_url);
		}
		g_set_error (error, ANJUTA_PROFILE_ERROR,
					 ANJUTA_PROFILE_ERROR_URI_READ_FAILED,
					 _("Failed to read '%s': Following mandatory plugins are missing:\n%s"),
					 uri, mesg->str);
		g_free (uri);
		g_string_free (mesg, TRUE);
		
		g_list_foreach (descs_list, (GFunc)g_list_free, NULL);
		g_list_free (descs_list);
		descs_list = NULL;
	}
	g_list_foreach (not_found_names, (GFunc)g_free, NULL);
	g_list_free (not_found_names);
	g_list_foreach (not_found_urls, (GFunc)g_free, NULL);
	g_list_free (not_found_urls);

	return descs_list;
}
示例#4
0
static void
gss_config_dump_object (GObject * object, xmlNsPtr ns, xmlNodePtr parent)
{
  xmlNodePtr node;
  GParamSpec **pspecs;
  int n_properties;
  int i;
  char *object_name;
  xmlChar *name;
  xmlChar *content;
  char *s;

  g_return_if_fail (G_IS_OBJECT (object));

  pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (object),
      (guint *) & n_properties);

  s = get_xml_class_name (object);
  name = xmlCharStrdup (s);
  g_free (s);
  node = xmlNewChild (parent, ns, name, NULL);
  xmlFree (name);

  g_object_get (object, "name", &object_name, NULL);
  name = xmlCharStrdup ("name");
  content = xmlCharStrdup (object_name);
  g_free (object_name);
  xmlNewTextChild (node, ns, name, content);
  xmlFree (name);
  xmlFree (content);

  for (i = 0; i < n_properties; i++) {
    const GParamSpec *pspec = pspecs[i];
    char *s;

    if (strcmp (pspec->name, "name") == 0)
      continue;
    if (!(pspec->flags & G_PARAM_READABLE))
      continue;
    if (!(pspec->flags & G_PARAM_WRITABLE))
      continue;

    s = g_object_get_as_string (object, pspec);

    name = xmlCharStrdup (pspec->name);
    content = xmlCharStrdup (s);
    xmlNewTextChild (node, ns, name, content);
    xmlFree (name);
    xmlFree (content);
    g_free (s);
  }

#if 0
  if (GSS_IS_ENCODER (object)) {
    GssEncoder *encoder = GSS_ENCODER (object);
    GList *g;
    for (g = encoder->program.streams; g; g = g_list_next (g)) {
      gss_config_dump_object (g->data, ns, node);
    }
  }
#endif

  g_free (pspecs);
}
示例#5
0
int DEFAULT_CC
send_logoff(int client, int session_id)
{
	struct session_item* sess;
	xmlNodePtr node, node2;
	xmlDocPtr doc;
	xmlChar* version;
	xmlChar* response;
	xmlChar* session;
	xmlChar* username;
	xmlChar* username_value;
	xmlChar* id;
	xmlChar* id_value;
	xmlChar* status;
	xmlChar* status_value;


	char prop[128];
	int display;

	if (session_id == 0) {
		log_message(&(g_cfg->log), LOG_LEVEL_WARNING, "sesman[send_logoff]: "
				"%i is not a valid session id", session_id);
		return 1;
	}

	log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, "sesman[send_logoff]: "
			"request session %i logoff", session_id);

	lock_chain_acquire();
	sess = session_get_by_display(session_id);
	lock_chain_release();

	if( sess == NULL)
	{
		log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, "sesman[send_logoff]: "
				"The session %i did not exist", session_id);
		xml_send_error(client, "the session id of the request did not exist");
		return 1;
	}

	session_update_status_by_user(sess->name, SESMAN_SESSION_STATUS_TO_DESTROY);
	version = xmlCharStrdup("1.0");
	doc = xmlNewDoc(version);
	if (doc == NULL)
	{
		log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, "sesman[send_logoff]: "
				"Unable to create the document");
		g_free(sess);
		xmlFree(version);
		xmlFreeDoc(doc);
		return 1;
	}
	doc->encoding = xmlCharStrdup("UTF-8");
	response = xmlCharStrdup("response");
	session = xmlCharStrdup("session");
	node = xmlNewNode(NULL, response);
	node2 = xmlNewNode(NULL, session);
	sprintf(prop, "%i", display);

	id = xmlCharStrdup("id");
	id_value = xmlCharStrdup(prop);
	username = xmlCharStrdup("username");
	username_value = xmlCharStrdup(sess->name);
	status = xmlCharStrdup("status");
	status_value = xmlCharStrdup("CLOSED");
	xmlSetProp(node2, id, id_value);
	xmlSetProp(node2, username, username_value);
	xmlSetProp(node2, status, status_value);
	xmlAddChild(node, node2);
	xmlDocSetRootElement(doc, node);
	xml_send_info(client, doc);

	xmlFreeDoc(doc);
	xmlFree(version);
	xmlFree(response);
	xmlFree(session);
	xmlFree(username);
	xmlFree(username_value);
	xmlFree(id);
	xmlFree(id_value);
	xmlFree(status);
	xmlFree(status_value);
	g_free(sess);
	return 0;
}
示例#6
0
文件: cfgfile.c 项目: miksago/icecast
static void _set_defaults(ice_config_t *configuration)
{
    configuration->location = (char *)xmlCharStrdup (CONFIG_DEFAULT_LOCATION);
    configuration->server_id = (char *)xmlCharStrdup (ICECAST_VERSION_STRING);
    configuration->admin = (char *)xmlCharStrdup (CONFIG_DEFAULT_ADMIN);
    configuration->client_limit = CONFIG_DEFAULT_CLIENT_LIMIT;
    configuration->source_limit = CONFIG_DEFAULT_SOURCE_LIMIT;
    configuration->queue_size_limit = CONFIG_DEFAULT_QUEUE_SIZE_LIMIT;
    configuration->workers_count = 1;
    configuration->client_timeout = CONFIG_DEFAULT_CLIENT_TIMEOUT;
    configuration->header_timeout = CONFIG_DEFAULT_HEADER_TIMEOUT;
    configuration->source_timeout = CONFIG_DEFAULT_SOURCE_TIMEOUT;
    configuration->source_password = (char *)xmlCharStrdup (CONFIG_DEFAULT_SOURCE_PASSWORD);
    configuration->shoutcast_mount = (char *)xmlCharStrdup (CONFIG_DEFAULT_SHOUTCAST_MOUNT);
    configuration->ice_login = CONFIG_DEFAULT_ICE_LOGIN;
    configuration->fileserve = CONFIG_DEFAULT_FILESERVE;
    configuration->touch_interval = CONFIG_DEFAULT_TOUCH_FREQ;
    configuration->on_demand = 0;
    configuration->dir_list = NULL;
    configuration->hostname = (char *)xmlCharStrdup (CONFIG_DEFAULT_HOSTNAME);
    configuration->port = 0;
    configuration->master_server = NULL;
    configuration->master_server_port = 0;
    configuration->master_update_interval = CONFIG_MASTER_UPDATE_INTERVAL;
    configuration->master_username = (char*)xmlCharStrdup (CONFIG_DEFAULT_MASTER_USERNAME);
    configuration->master_password = NULL;
    configuration->master_bind = NULL;
    configuration->master_relay_auth = 0;
    configuration->base_dir = (char *)xmlCharStrdup (CONFIG_DEFAULT_BASE_DIR);
    configuration->log_dir = (char *)xmlCharStrdup (CONFIG_DEFAULT_LOG_DIR);
    configuration->webroot_dir = (char *)xmlCharStrdup (CONFIG_DEFAULT_WEBROOT_DIR);
    configuration->adminroot_dir = (char *)xmlCharStrdup (CONFIG_DEFAULT_ADMINROOT_DIR);
    configuration->playlist_log.name = (char *)xmlCharStrdup (CONFIG_DEFAULT_PLAYLIST_LOG);
    configuration->access_log.name = (char *)xmlCharStrdup (CONFIG_DEFAULT_ACCESS_LOG);
    configuration->access_log.log_ip = 1;
    configuration->error_log.name = (char *)xmlCharStrdup (CONFIG_DEFAULT_ERROR_LOG);
    configuration->error_log.level = CONFIG_DEFAULT_LOG_LEVEL;
    configuration->chroot = CONFIG_DEFAULT_CHROOT;
    configuration->chuid = CONFIG_DEFAULT_CHUID;
    configuration->user = NULL;
    configuration->group = NULL;
    configuration->num_yp_directories = 0;
    configuration->slaves_count = 0;
    configuration->relay_username = (char *)xmlCharStrdup (CONFIG_DEFAULT_MASTER_USERNAME);
    configuration->relay_password = NULL;
    /* default to a typical prebuffer size used by clients */
    configuration->min_queue_size = 0;
    configuration->burst_size = CONFIG_DEFAULT_BURST_SIZE;
}
示例#7
0
place_t *parse_place_element(xmlNode *plNode) {
    int num = 1;
    int did = 0;
    xmlChar *numStr = xmlGetProp(plNode, xmlCharStrdup("num"));
    xmlChar *didStr = xmlGetProp(plNode, xmlCharStrdup("did"));
    xmlChar *typeStr = xmlGetProp(plNode, xmlCharStrdup("type"));
    xmlChar *sizeStr = xmlGetProp(plNode, xmlCharStrdup("size"));
    xmlChar *unitSize = xmlGetProp(plNode, xmlCharStrdup("unitSize"));
    xmlChar *info = xmlGetProp(plNode, xmlCharStrdup("info"));

    if (numStr != NULL) {
        num = atoi((char *)numStr);
    }

    if (didStr != NULL) {
        did = atoi((char *)didStr);
    }

    short type = CACHE_PLACE;
    if (typeStr != NULL) {
        if (!xmlStrcmp(typeStr, (const xmlChar *) "mem")) {
            type = MEM_PLACE;
        } else if (!xmlStrcmp(typeStr, (const xmlChar *) "cache")) {
            type = CACHE_PLACE;
        } else if (!xmlStrcmp(typeStr, (const xmlChar *) "nvgpu")) {
            type = NVGPU_PLACE;
        } else if (!xmlStrcmp(typeStr, (const xmlChar *) "amgpu")) {
            type = AMGPU_PLACE;
        } else if (!xmlStrcmp(typeStr, (const xmlChar *) "fpga")) {
            type = FPGA_PLACE;
        } else if (!xmlStrcmp(typeStr, (const xmlChar *) "pgas")) {
            type = PGAS_PLACE;
        } else {
            /* warning, unknown type specified */
        }
    } else {
        /* default to be cache type */
        type = CACHE_PLACE;
    }

    // Not supported yet
    HASSERT(type != AMGPU_PLACE && type != FPGA_PLACE);

    xmlFree(numStr);
    xmlFree(didStr);
    xmlFree(typeStr);
    xmlFree(sizeStr);
    xmlFree(unitSize);
    xmlFree(info);

    place_t *pl = (place_t *) malloc(sizeof(place_t));
    HASSERT(pl);
    memset(pl, 0x00, sizeof(place_t));
    pl->id = num;
    pl->did = did;
    pl->type = type;
    pl->psize = (sizeStr == NULL) ? 0 : atoi((char *)sizeStr);
    pl->unitSize = (unitSize == NULL) ? 0 : atoi((char *)unitSize);

    xmlNode *child = plNode->xmlChildrenNode;

    place_t *pllast = NULL;
    hclib_worker_state *wslast = NULL;

#ifdef HC_ASSERTION_CHECK
    unsigned nchildren = 0;
#endif
    while (child != NULL) {
        if (!xmlStrcmp(child->name, (const xmlChar *) "place")) {
            place_t *tmp = parse_place_element(child);
            tmp->parent = pl;
            if (pl->child == NULL) pl->child = tmp;
            else pllast->nnext = tmp;
            pllast = tmp;
#ifdef HC_ASSERTION_CHECK
            nchildren++;
#endif
        } else if (!xmlStrcmp(child->name, (const xmlChar *) "worker")) {
            hclib_worker_state *tmp = parse_worker_element(child);
            tmp->pl = pl;
            if (pl->workers == NULL) pl->workers = tmp;
            else wslast->next_worker = tmp;
            wslast = tmp;
#ifdef HC_ASSERTION_CHECK
            nchildren++;
#endif
        }
        child = child->next;
    }

    if (type == NVGPU_PLACE) HASSERT(nchildren == 0);

    return pl;
}
示例#8
0
int DEFAULT_CC
send_sessions(int client)
{
	struct session_item* sess;
	xmlNodePtr node, node2, node3;
	xmlDocPtr doc;
	int count, i;
	xmlChar* version;
	xmlChar* encoding;
	xmlChar* s_node;
	xmlChar* s_node2;

	log_message(&(g_cfg->log), LOG_LEVEL_DEBUG_PLUS, "sesman[send_sessions]: "
			"request for sessions list");

	lock_chain_acquire();
	sess = (struct session_item*)session_list_session(&count);
	lock_chain_release();

	log_message(&(g_cfg->log), LOG_LEVEL_DEBUG_PLUS, "sesman[send_sessions]: "
			"%i count sessions",count);
	version = xmlCharStrdup("1.0");
	doc = xmlNewDoc(version);
	if (doc ==NULL)
	{
		log_message(&(g_cfg->log), LOG_LEVEL_DEBUG_PLUS, "sesman[send_sessions]: "
				"Unable to create the document");
		return 1;
	}
	doc->encoding = xmlCharStrdup("UTF-8");
	s_node = xmlCharStrdup("response");
	node = xmlNewNode(NULL, s_node);
	s_node2 = xmlCharStrdup("sessions");
	node2 = xmlNewNode(NULL, s_node2);
	xmlAddChild(node, node2);
	char prop[128];

	for ( i=0 ; i<count ; i++)
	{
		g_sprintf(prop, "%i", sess[i].display);
		xmlChar* s_session = xmlCharStrdup("session");
		xmlChar* s_id = xmlCharStrdup("id");
		xmlChar* s_id_value = xmlCharStrdup(prop);
		xmlChar* s_username = xmlCharStrdup("username");
		xmlChar* s_username_value = xmlCharStrdup(sess[i].name);
		xmlChar* s_status = xmlCharStrdup("status");
		xmlChar* s_status_value = xmlCharStrdup(session_get_status_string(sess[i].status));

		node3 = xmlNewNode(NULL, s_session);
		xmlSetProp(node3, s_id, s_id_value );
		xmlSetProp(node3, s_username,	s_username_value);
		xmlSetProp(node3, s_status, s_status_value );
		xmlAddChild(node2, node3);
		xmlFree(s_session);
		xmlFree(s_id);
		xmlFree(s_id_value);
		xmlFree(s_username);
		xmlFree(s_username_value);
		xmlFree(s_status);
		xmlFree(s_status_value);
	}
	xmlAddChild(node, node2);
	xmlDocSetRootElement(doc, node);
	xml_send_info(client, doc);

	xmlFree(version);
	xmlFree(s_node);
	xmlFree(s_node2);
	g_free(sess);
	xmlFreeDoc(doc);
	return 0;
}
示例#9
0
int GetGameXML(ConfigSettings *cs, GameInfo *game, char *emulator) {
	int c1=0;
	FILE *pi;
	char temp[20000]={'\x00'};
	char c;
	char *ptr;
	xmlDocPtr xmlbuffer = NULL;
	char cmd[255];

	if (!strcmp(game->name, ""))
		return 1;

	/* Windows needs a kludge I guess */
	if (IS_WIN) {
		char* argv[25];
		FILE *fp = NULL;
		char file[255];
        	pid_t cpid;
        	pid_t child_pid;

		sprintf(file, "%s.xml", game->name);
		
		//system(cmd);
		sprintf(cmd, "%s", emulator);
		argv[0] = emulator;
		argv[1] = "-listxml";
		argv[2] = game->name;
		argv[3] = NULL;

        	/* Fork and run mame, wait for pid to exit */
        	cpid = fork();
        	switch (cpid) {
                	case -1: printf("Failed running %s\n", emulator);
                	break;
        	case 0: child_pid = getpid();
			fp = freopen(file, "w", stdout);
                	execvp(emulator, argv);
			{
				char *path = NULL;
				char *envp = getenv("PATH");
				path = strtok(envp, ":");
				while(path != NULL) {
					char executable[255];
					sprintf(executable, "%s/%s", path, emulator);
                			execvp(executable, argv);
					if (cs->verbose > 2)
						sr_fprintf(stderr, "Failed running %s\n", executable);
					path = strtok(NULL, ":");
				}
			}
			sr_fprintf(stderr, "%s exited or failed running with PATH=%s\n", emulator, getenv("PATH"));
                	exit(1); // Failed
        	default:
                	waitpid(cpid, NULL, 0);
                	break;
        	}
		if (fp)
			fclose(fp);

		xmlbuffer = xmlParseFile(file);
		unlink(file);
		if (xmlbuffer == NULL)
			return -1;
		ParseXML(xmlbuffer, game, cs);
		xmlFreeDoc(xmlbuffer);
		if (game->width <= 0 || game->height <= 0 || game->refresh <= 0)
			return -1;
		return 0;
	} else
		sprintf(cmd, "%s -listxml %s", emulator, game->name);

	pi=popen(cmd, "r");
	if(pi != NULL) {
		int i = 0;
        	c=fgetc(pi);
        	while(c != '\xff' && i < 20000) {
                	temp[c1]=c;
                	c=fgetc(pi);
                	c1++;
                }
        	temp[c1]='\x00';
        	pclose(pi);

		if (cs->verbose > 3)
			sr_fprintf(stderr, "Game XML is: %s\n", temp);

		/* Turn into an XML buffer */
		ptr = (char *) &temp;
		xmlbuffer = xmlParseDoc(xmlCharStrdup(ptr));
		if (xmlbuffer == NULL) {
			sr_fprintf(stderr, "Error getting XML info for %s from %s\n",
				emulator, game->name);
			return -1;
		}
		ParseXML(xmlbuffer, game, cs);

		xmlFreeDoc(xmlbuffer);
        }

	if (game->width <= 0 || game->height <= 0 || game->refresh <= 0) {
		if (cs->verbose > 2)
			sr_fprintf(stderr, "Didn't get width/height/refresh from mame\n");
		return -1;
	}

	return 0;
}
示例#10
0
static void addSelectionCopyMove(mdsSelectionList_t* selectionList)
{
    gboolean found;
    int      selIdx;

    int                 selNum    = selectionList->num_selections;
    mdsSelection_t*     selection = NULL;
    mdsSelectionItem_t* item      = NULL;

    // check whether copy/move selection present
    found     = FALSE;
    selection = (mdsSelection_t*) selectionList->selections;  // const_cast
    for (selIdx = 0 ; selIdx < selNum ; selIdx++, selection++)
    {
        if (strcmp(selection->id, SELECTION_TRANSFER_MODE) == 0)
        {
            found = TRUE;
        }
    }

    // add copy/move selection
    if ( !found )
    {
        // allocate one more selection
        selection = (mdsSelection_t*) selectionList->selections;  // const_cast
        selection = g_renew(mdsSelection_t, selection, selNum + 1);
        selectionList->selections = selection;
        selectionList->num_selections++;

        // free up the first selection
        selection  = (mdsSelection_t*) selectionList->selections;  // const_cast
        selection += selNum;
        for (selIdx = 0 ; selIdx < selNum ; selIdx++, selection--)
        {
            *selection = *(selection - 1);
        }
        memset((void*)selection, 0x00, sizeof(*selection));

        // make first selection a copy/move list
        selection = (mdsSelection_t*) selectionList->selections;  // const_cast
        selection->constant    = FALSE;
        selection->hide        = FALSE;
        selection->display_as  = xmlCharStrdup("textbutton");
        selection->title       = xmlCharStrdup( _("Transfer mode") );
        selection->instruction = xmlCharStrdup( _("Please select how to add this document to your outbox") );
        selection->min_selected = 1;
        selection->max_selected = 1;
        selection->num_items    = 2;
        selection->items        = NULL;
        selection->id           = xmlCharStrdup(SELECTION_TRANSFER_MODE);
        selection->sequence     = 0;

        // add items to this selection
        selection->items = g_new0(mdsSelectionItem_t, 2);
        //   item[0] = copy
        item = (mdsSelectionItem_t*) selection->items;  // const_cast
        item->name     = xmlCharStrdup( _("Copy") );
        item->id       = xmlCharStrdup( "copy" );
        item->sequence = 1;
        item->state    = TRUE;
        //   item[1] = move
        item++;
        item->name     = xmlCharStrdup( _("Move") );
        item->id       = xmlCharStrdup( "move" );
        item->sequence = 2;
        item->state    = FALSE;
    }
}
示例#11
0
static int _parse_relay (xmlNodePtr node, void *arg)
{
    ice_config_t *config = arg;
    relay_server *relay = calloc(1, sizeof(relay_server));
    relay_server_host *host = calloc (1, sizeof (relay_server_host));
    int on_demand = config->on_demand, icy_metadata = 1, running = 1;

    struct cfg_tag icecast_tags[] =
    {
        { "master",                     _relay_host,        relay },
        { "host",                       _relay_host,        relay },
        { "server",                     config_get_str,     &host->ip },
        { "ip",                         config_get_str,     &host->ip },
        { "bind",                       config_get_str,     &host->bind },
        { "port",                       config_get_port,    &host->port },
        { "mount",                      config_get_str,     &host->mount },
        { "timeout",                    config_get_int,     &host->timeout },
        { "local-mount",                config_get_str,     &relay->localmount },
        { "on-demand",                  config_get_bool,    &on_demand },
        { "run-on",                     config_get_int,     &relay->run_on },
        { "retry-delay",                config_get_int,     &relay->interval },
        { "relay-icy-metadata",         config_get_bool,    &icy_metadata },
        { "relay-shoutcast-metadata",   config_get_bool,    &icy_metadata },
        { "username",                   config_get_str,     &relay->username },
        { "password",                   config_get_str,     &relay->password },
        { "enable",                     config_get_bool,    &running },
        { NULL, NULL, NULL },
    };

    relay->interval = config->master_update_interval;
    relay->run_on = 30;
    relay->hosts = host;
    /* default settings */
    host->port = config->port;
    host->ip = (char *)xmlCharStrdup ("127.0.0.1");
    host->mount = (char*)xmlCharStrdup ("/");
    host->timeout = 4;

    if (parse_xml_tags (node, icecast_tags))
        return -1;

    if (on_demand)      relay->flags |= RELAY_ON_DEMAND;
    if (icy_metadata)   relay->flags |= RELAY_ICY_META;
    if (running)        relay->flags |= RELAY_RUNNING;

    /* check for unspecified entries */
    if (relay->localmount == NULL)
        relay->localmount = (char*)xmlCharStrdup (host->mount);

    /* if master is set then remove the default entry at the head of the list */ 
    if (relay->hosts->next)
    {
        relay->hosts = relay->hosts->next;
        if (host->mount)  xmlFree (host->mount);
        if (host->ip)     xmlFree (host->ip);
        if (host->bind)   xmlFree (host->bind);
        free (host);
    }

    relay->new_details = config->relays;
    config->relays = relay;

    return 0;
}
示例#12
0
int EBC_Provider_XchgHiaRequest_H003(AB_PROVIDER *pro,
                                     GWEN_HTTP_SESSION *sess,
                                     AB_USER *u)
{
  int rv;
  GWEN_CRYPT_TOKEN *ct;
  const GWEN_CRYPT_TOKEN_CONTEXT *ctx;
  uint32_t kid;
  const GWEN_CRYPT_TOKEN_KEYINFO *cryptKeyInfo=NULL;
  const GWEN_CRYPT_TOKEN_KEYINFO *authKeyInfo=NULL;
  xmlNsPtr ns;
  EB_MSG *msg;
  const char *userId;
  const char *partnerId;
  EB_MSG *mRsp;
  EB_RC rc;
  xmlDocPtr doc;
  xmlNodePtr root_node = NULL;
  xmlNodePtr node = NULL;
  /*xmlNodePtr nodeX = NULL;*/
  GWEN_BUFFER *mbuf;
  GWEN_BUFFER *tbuf;
  const char *s;

  userId=AB_User_GetUserId(u);
  partnerId=AB_User_GetCustomerId(u);

  /* get crypt token and context */
  rv=EBC_Provider_MountToken(pro, u, &ct, &ctx);
  if (rv<0) {
    DBG_INFO(AQEBICS_LOGDOMAIN, "here (%d)", rv);
    return rv;
  }

  /* get crypt key info */
  kid=GWEN_Crypt_Token_Context_GetDecipherKeyId(ctx);
  if (kid) {
    cryptKeyInfo=GWEN_Crypt_Token_GetKeyInfo(ct, kid,
                                             GWEN_CRYPT_TOKEN_KEYFLAGS_HASMODULUS |
                                             GWEN_CRYPT_TOKEN_KEYFLAGS_HASEXPONENT |
                                             GWEN_CRYPT_TOKEN_KEYFLAGS_HASKEYVERSION |
                                             GWEN_CRYPT_TOKEN_KEYFLAGS_HASKEYNUMBER,
                                             0);
    if (cryptKeyInfo==NULL) {
      DBG_ERROR(AQEBICS_LOGDOMAIN, "Crypt key info not found on crypt token");
      GWEN_Gui_ProgressLog(0,
                           GWEN_LoggerLevel_Error,
                           I18N("Crypt key info not found on crypt token"));
      return GWEN_ERROR_NOT_FOUND;
    }
  }

  /* get auth sign key info */
  kid=GWEN_Crypt_Token_Context_GetAuthSignKeyId(ctx);
  if (kid) {
    authKeyInfo=GWEN_Crypt_Token_GetKeyInfo(ct, kid,
                                            GWEN_CRYPT_TOKEN_KEYFLAGS_HASMODULUS |
                                            GWEN_CRYPT_TOKEN_KEYFLAGS_HASEXPONENT |
                                            GWEN_CRYPT_TOKEN_KEYFLAGS_HASKEYVERSION |
                                            GWEN_CRYPT_TOKEN_KEYFLAGS_HASKEYNUMBER,
                                            0);
    if (authKeyInfo==NULL) {
      DBG_ERROR(AQEBICS_LOGDOMAIN, "Auth key info not found on crypt token");
      GWEN_Gui_ProgressLog(0,
                           GWEN_LoggerLevel_Error,
                           I18N("Auth key info not found on crypt token"));
      return GWEN_ERROR_NOT_FOUND;
    }
  }

  /* create HIARequestOrderData */
  doc=xmlNewDoc(BAD_CAST "1.0");
  doc->encoding=xmlCharStrdup("UTF-8");
  root_node=xmlNewNode(NULL, BAD_CAST "HIARequestOrderData");
  xmlDocSetRootElement(doc, root_node);
  ns=xmlNewNs(root_node,
              BAD_CAST "http://www.ebics.org/H003",
              NULL);
  assert(ns);
  ns=xmlNewNs(root_node,
              BAD_CAST "http://www.w3.org/2000/09/xmldsig#",
              BAD_CAST "ds");
  assert(ns);
  ns=xmlNewNs(root_node,
              BAD_CAST "http://www.w3.org/2001/XMLSchema-instance",
              BAD_CAST "xsi");
  xmlNewNsProp(root_node,
               ns,
               BAD_CAST "schemaLocation", /* xsi:schemaLocation */
               BAD_CAST "http://www.ebics.org/H003 "
               "http://www.ebics.org/H003/ebics_orders.xsd");

  /* create auth key tree */
  node=xmlNewChild(root_node, NULL,
                   BAD_CAST "AuthenticationPubKeyInfo", NULL);
  rv=EB_Key_Info_toXml(authKeyInfo, node);
  if (rv<0) {
    DBG_ERROR(AQEBICS_LOGDOMAIN, "Error response: (%d)", rv);
    xmlFreeDoc(doc);
    return GWEN_ERROR_INVALID;
  }
  xmlNewChild(node, NULL,
              BAD_CAST "AuthenticationVersion",
              BAD_CAST "X002");

  /* create crypt key tree */
  node=xmlNewChild(root_node, NULL,
                   BAD_CAST "EncryptionPubKeyInfo", NULL);
  rv=EB_Key_Info_toXml(cryptKeyInfo, node);
  if (rv<0) {
    DBG_ERROR(AQEBICS_LOGDOMAIN, "Error response: (%d)", rv);
    xmlFreeDoc(doc);
    return rv;
  }
  xmlNewChild(node, NULL,
              BAD_CAST "EncryptionVersion",
              BAD_CAST "E002");

  /* store partner id and user id */
  node=xmlNewChild(root_node, NULL,
                   BAD_CAST "PartnerID",
                   BAD_CAST partnerId);

  node=xmlNewChild(root_node, NULL,
                   BAD_CAST "UserID",
                   BAD_CAST userId);

  /* compress and base64 doc */
  mbuf=GWEN_Buffer_new(0, 512, 0, 1);
  rv=EB_Xml_Compress64Doc(doc, mbuf);
  if (rv<0) {
    DBG_ERROR(AQEBICS_LOGDOMAIN, "Error compressing/encoding doc (%d)", rv);
    xmlFreeDoc(doc);
    return rv;
  }
  xmlFreeDoc(doc);

  /* create request */
  msg=EB_Msg_new();
  doc=EB_Msg_GetDoc(msg);
  root_node=xmlNewNode(NULL, BAD_CAST "ebicsUnsecuredRequest");
  xmlDocSetRootElement(doc, root_node);
  ns=xmlNewNs(root_node,
              BAD_CAST "http://www.ebics.org/H003",
              NULL);
  assert(ns);
  ns=xmlNewNs(root_node,
              BAD_CAST "http://www.w3.org/2000/09/xmldsig#",
              BAD_CAST "ds");
  assert(ns);
  ns=xmlNewNs(root_node,
              BAD_CAST "http://www.w3.org/2001/XMLSchema-instance",
              BAD_CAST "xsi");
  xmlNewNsProp(root_node,
               ns,
               BAD_CAST "schemaLocation", /* xsi:schemaLocation */
               BAD_CAST "http://www.ebics.org/H003 "
               "http://www.ebics.org/H003/ebics_keymgmt_request.xsd");
  xmlNewProp(root_node, BAD_CAST "Version", BAD_CAST "H003");
  xmlNewProp(root_node, BAD_CAST "Revision", BAD_CAST "1");

  /* header */
  node=xmlNewChild(root_node, NULL, BAD_CAST "header", NULL);
  xmlNewProp(node, BAD_CAST "authenticate", BAD_CAST "true");
  xmlNewChild(node, NULL, BAD_CAST "static", NULL);
  xmlNewChild(node, NULL, BAD_CAST "mutable", NULL);

  /* body */
  node=xmlNewChild(root_node, NULL, BAD_CAST "body", NULL);

  /* fill */
  s=EBC_User_GetPeerId(u);
  if (s)
    EB_Msg_SetCharValue(msg, "header/static/HostID", s);
  s=AB_User_GetCustomerId(u);
  if (s)
    EB_Msg_SetCharValue(msg, "header/static/PartnerID", s);
  EB_Msg_SetCharValue(msg, "header/static/UserID",
                      AB_User_GetUserId(u));
  EB_Msg_SetCharValue(msg, "header/static/OrderDetails/OrderType", "HIA");
  tbuf=GWEN_Buffer_new(0, 16, 0, 1);
  rv=EBC_Provider_Generate_OrderId(pro, tbuf);
  if (rv<0) {
    DBG_ERROR(AQEBICS_LOGDOMAIN, "Error exchanging messages (%d)", rv);
    GWEN_Buffer_free(tbuf);
    GWEN_Buffer_free(mbuf);
    EB_Msg_free(msg);
    return rv;
  }
  EB_Msg_SetCharValue(msg, "header/static/OrderDetails/OrderID",
                      GWEN_Buffer_GetStart(tbuf));
  GWEN_Buffer_free(tbuf);
  EB_Msg_SetCharValue(msg,
                      "header/static/OrderDetails/OrderAttribute",
                      "DZNNN");
  EB_Msg_SetCharValue(msg, "header/static/SecurityMedium", "0200");
  EB_Msg_SetCharValue(msg, "body/DataTransfer/OrderData",
                      GWEN_Buffer_GetStart(mbuf));
  GWEN_Buffer_free(mbuf);

  /* exchange requests */
  rv=EBC_Dialog_ExchangeMessages(sess, msg, &mRsp);
  if (rv<0 || rv>=300) {
    DBG_ERROR(AQEBICS_LOGDOMAIN, "Error exchanging messages (%d)", rv);
    EB_Msg_free(msg);
    return rv;
  }
  EB_Msg_free(msg);

  /* check response */
  assert(mRsp);

  /* log results */
  EBC_Provider_LogRequestResults(pro, mRsp, NULL);

  rc=EB_Msg_GetResultCode(mRsp);
  if ((rc & 0xff0000)==0x090000 ||
      (rc & 0xff0000)==0x060000) {
    DBG_ERROR(AQEBICS_LOGDOMAIN, "Error response: (%06x)", rc);
    EB_Msg_free(mRsp);
    return AB_ERROR_SECURITY;
  }
  rc=EB_Msg_GetBodyResultCode(mRsp);
  if (rc) {
    if ((rc & 0xff0000)==0x090000 ||
        (rc & 0xff0000)==0x060000) {
      DBG_ERROR(AQEBICS_LOGDOMAIN, "Error response: (%06x)", rc);
      EB_Msg_free(mRsp);
      if ((rc & 0xfff00)==0x091300 ||
          (rc & 0xfff00)==0x091200)
        return AB_ERROR_SECURITY;
      else
        return GWEN_ERROR_GENERIC;
    }
  }

  EB_Msg_free(mRsp);

  /* adjust user status and flags */
  DBG_NOTICE(AQEBICS_LOGDOMAIN, "Adjusting user flags");
  EBC_User_AddFlags(u, EBC_USER_FLAGS_HIA);
  if ((EBC_User_GetFlags(u) & (EBC_USER_FLAGS_INI | EBC_USER_FLAGS_HIA))
      ==
      (EBC_USER_FLAGS_INI | EBC_USER_FLAGS_HIA))
    EBC_User_SetStatus(u, EBC_UserStatus_Init2);
  else
    EBC_User_SetStatus(u, EBC_UserStatus_Init1);

  return 0;
}
 SDOXMLString::SDOXMLString(const char* localString)
 {
     xmlForm = xmlCharStrdup(localString);
 }
示例#14
0
static void writeDNAComponent(DNAComponent* com) {
	if (!com)
		return;
	xmlTextWriterStartElement(WRITER, xmlCharStrdup(NSPREFIX_SBOL ":" NODENAME_DNACOMPONENT));
	if (!alreadyProcessed((void *)com)) {
		markProcessed((void *)com);
		xmlTextWriterWriteAttribute(WRITER, xmlCharStrdup(NSPREFIX_RDF ":" NODENAME_ABOUT), xmlCharStrdup(getDNAComponentURI(com)));
		
		// properties
		char* data;
		data = getDNAComponentDisplayID(com);
		if (data)
			xmlTextWriterWriteElement(WRITER, xmlCharStrdup(NSPREFIX_SBOL ":" NODENAME_DISPLAYID), xmlCharStrdup(data));
		data = getDNAComponentName(com);
		if (data)
			xmlTextWriterWriteElement(WRITER, xmlCharStrdup(NSPREFIX_SBOL ":" NODENAME_NAME), xmlCharStrdup(data));
		data = getDNAComponentDescription(com);
		if (data)
			xmlTextWriterWriteElement(WRITER, xmlCharStrdup(NSPREFIX_SBOL ":" NODENAME_DESCRIPTION), xmlCharStrdup(data));
        data = getDNAComponentType(com);
        if (data) {
            xmlTextWriterStartElement(WRITER, xmlCharStrdup(NSPREFIX_RDF ":" NODENAME_TYPE));
            xmlTextWriterWriteAttribute(WRITER, xmlCharStrdup(NSPREFIX_RDF ":" NODENAME_RESOURCE), xmlCharStrdup(data));
            xmlTextWriterEndElement(WRITER);
        }
        
        
		// sequence
		if (com->dnaSequence) {
			xmlTextWriterStartElement(WRITER, xmlCharStrdup(NSPREFIX_SBOL ":" NODENAME_DNASEQUENCE_REF));
			indentMore();
			/// @todo sometimes no contents?
			writeDNASequence(com->dnaSequence);
			markProcessed(com->dnaSequence);
			indentLess();
			xmlTextWriterEndElement(WRITER);
		}
		
		// annotations
		int n;
		int num = getNumSequenceAnnotationsFor(com);
		SequenceAnnotation* ann;
		indentMore();
		if (num>0) {
			for (n=0; n<num; n++) {
				ann = getNthSequenceAnnotationFor(com, n);
				indentMore();
				xmlTextWriterStartElement(WRITER, xmlCharStrdup(NSPREFIX_SBOL ":" NODENAME_ANNOTATION));
				writeSequenceAnnotation(ann);
				xmlTextWriterEndElement(WRITER);
				indentLess();
			}
		}
		indentLess();
		
	} else
		xmlTextWriterWriteAttribute(WRITER, xmlCharStrdup(NSPREFIX_RDF ":" NODENAME_RESOURCE), xmlCharStrdup(getDNAComponentURI(com)));
	xmlTextWriterEndElement(WRITER);
}
示例#15
0
//-----------------------------------------
void LegacyParser::processNode(xmlTextReaderPtr reader, const xmlChar* name) {
//-----------------------------------------
    if( !isProcessableNode(reader) ) return;
    
    if( xmlStrEqual(name, xmlCharStrdup("gexf")) == 1 ) {
        processGEXFNode(reader);
    }
    else if( xmlStrEqual(name, xmlCharStrdup("meta")) == 1 ) {
        processMetaNode(reader);
    }
    else if( xmlStrEqual(name, xmlCharStrdup("creator")) == 1 ) {
        processCreatorNode(reader);
    }
    else if( xmlStrEqual(name, xmlCharStrdup("description")) == 1 ) {
        processDescriptionNode(reader);
    }
    else if( xmlStrEqual(name, xmlCharStrdup("graph")) == 1 ) {
        processGraphNode(reader);
    }
    else if( xmlStrEqual(name, xmlCharStrdup("node")) == 1 ) {
        processNodeNode(reader);
    }
    else if( xmlStrEqual(name, xmlCharStrdup("edges")) == 1 ) {
        processEdgesNode(reader);
    }
    else if( xmlStrEqual(name, xmlCharStrdup("edge")) == 1 ) {
        processEdgeNode(reader);
    }
    else if( xmlStrEqual(name, xmlCharStrdup("attributes")) == 1 ) {
        processAttributesNode(reader);
    }
    else if( xmlStrEqual(name, xmlCharStrdup("attribute")) == 1 ) {
        processAttributeNode(reader);
    }
    else if( xmlStrEqual(name, xmlCharStrdup("default")) == 1 ) {
        processAttributeDefaultNode(reader);
    }
    else if( xmlStrEqual(name, xmlCharStrdup("attvalue")) == 1 ) {
        processAttvalueNode(reader);
    }
}
示例#16
0
static void createSBOLWriter() {
	INDENT = 0;
	WRITER = xmlNewTextWriterDoc(&OUTPUT, 0);
	xmlTextWriterSetIndentString(WRITER,xmlCharStrdup("\t"));
	xmlTextWriterSetIndent(WRITER, INDENT);
}
示例#17
0
文件: utils.c 项目: UIKit0/libgrss
gchar*
xhtml_extract (xmlNodePtr xml, gint xhtmlMode, const gchar *defaultBase)
{
	xmlBufferPtr buf;
	xmlChar *xml_base = NULL;
	gchar *result = NULL;
	xmlNs *ns;

	/* Create the new document and add the div tag*/
	xmlDocPtr newDoc = xmlNewDoc (BAD_CAST "1.0" );
	xmlNodePtr divNode = xmlNewNode (NULL, BAD_CAST "div");
	xmlDocSetRootElement (newDoc, divNode);
	xmlNewNs (divNode, BAD_CAST "http://www.w3.org/1999/xhtml", NULL);

	/* Set the xml:base  of the div tag */
	xml_base = xmlNodeGetBase (xml->doc, xml);
	if (xml_base) {
		xmlNodeSetBase (divNode, xml_base );
		xmlFree (xml_base);
	}
	else if (defaultBase)
		xmlNodeSetBase (divNode, BAD_CAST defaultBase);

	if (xhtmlMode == 0) { /* Read escaped HTML and convert to XHTML, placing in a div tag */
		xmlDocPtr oldDoc;
		xmlNodePtr copiedNodes = NULL;
		xmlChar *escapedhtml;

		/* Parse the HTML into oldDoc*/
		escapedhtml = xmlNodeListGetString (xml->doc, xml->xmlChildrenNode, 1);
		if (escapedhtml) {
			escapedhtml = BAD_CAST g_strstrip ((gchar*) escapedhtml);	/* stripping whitespaces to make empty string detection easier */
			if (*escapedhtml) {						/* never process empty content, xmlDocCopy() doesn't like it... */
				xmlNodePtr body;
				oldDoc = xhtml_parse ((gchar*) escapedhtml, strlen ((gchar*) escapedhtml));
				body = xhtml_find_body (oldDoc);

				/* Copy namespace from original documents root node. This is
				   ro determine additional namespaces for item content. For
				   example to handle RSS 2.0 feeds as provided by LiveJournal:

				   <rss version='2.0' xmlns:lj='http://www.livejournal.org/rss/lj/1.0/'>
				   <channel>
				      ...
				      <item>
	        			 ...
  	        			 <description>... &lt;span class=&apos;ljuser&apos; lj:user=&apos;someone&apos; style=&apos;white-space: nowrap;&apos;&gt;&lt;a href=&apos;http://community.livejournal.com/someone/profile&apos;&gt;&lt;img src=&apos;http://stat.livejournal.com/img/community.gif&apos; alt=&apos;[info]&apos; width=&apos;16&apos; height=&apos;16&apos; style=&apos;vertical-align: bottom; border: 0; padding-right: 2px;&apos; /&gt;&lt;/a&gt;&lt;a href=&apos;http://community.livejournal.com/someone/&apos;&gt;&lt;b&gt;someone&lt;/b&gt;&lt;/a&gt;&lt;/span&gt; ...</description>
					 ...
				      </item>
				      ...
				   </channel>

				   Then we will want to extract <description> and need to
				   honour the xmlns:lj definition...
				*/
				ns = (xmlDocGetRootElement (xml->doc))->nsDef;
				while (ns) {
					xmlNewNs (divNode, ns->href, ns->prefix);
					ns = ns->next;
				}

				if (body) {
					/* Copy in the html tags */
					copiedNodes = xmlDocCopyNodeList (newDoc, body->xmlChildrenNode);
					// FIXME: is the above correct? Why only operate on the first child node?
					// It might be unproblematic because all content is wrapped in a <div>...
					xmlAddChildList (divNode, copiedNodes);
				}
				xmlFreeDoc (oldDoc);
				xmlFree (escapedhtml);
			}
		}
	}
	else if (xhtmlMode == 1 || xhtmlMode == 2) { /* Read multiple XHTML tags and embed in div tag */
		xmlNodePtr copiedNodes = xmlDocCopyNodeList (newDoc, xml->xmlChildrenNode);
		xmlAddChildList (divNode, copiedNodes);
	}

	buf = xmlBufferCreate ();
	xmlNodeDump (buf, newDoc, xmlDocGetRootElement (newDoc), 0, 0 );

	if (xmlBufferLength (buf) > 0)
		result = (gchar*) xmlCharStrdup ((gchar*) xmlBufferContent (buf));

	xmlBufferFree (buf);
	xmlFreeDoc (newDoc);
	return result;
}
示例#18
0
int DEFAULT_CC
send_session(int client, int session_id, char* user)
{
	struct session_item* sess = NULL;
	xmlNodePtr node, node2;
	xmlDocPtr doc;
	xmlChar* version;
	xmlChar* response;
	xmlChar* session;
	xmlChar* id;
	xmlChar* id_value;
	xmlChar* username;
	xmlChar* username_value;
	xmlChar* status;
	xmlChar* status_value;

	log_message(&(g_cfg->log), LOG_LEVEL_DEBUG_PLUS, "sesman[send_session]: "
			"request for session\n");

	lock_chain_acquire();
	if (user == NULL || user[0] == '\0')
	{
		sess = session_get_by_display(session_id);
	}
	else
	{
		sess = session_get_bydata(user);
	}
	lock_chain_release();

	if( sess == NULL && session_id != 0)
	{
		log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, "sesman[send_session]: "
				"the session %i did not exist",session_id);

		sess = g_malloc(sizeof(struct session_item), 1);
		sess->display = session_id;
		sess->status = SESMAN_SESSION_STATUS_UNKNOWN;
		g_snprintf(sess->name, sizeof(sess->name), "UNKNOW");
	}
	version = xmlCharStrdup("1.0");
	doc = xmlNewDoc(version);
	if (doc == NULL)
	{
		log_message(&(g_cfg->log), LOG_LEVEL_DEBUG_PLUS, "sesman[send_session]: "
				"Unable to create the document");
		if (sess != NULL)
		{
			g_free(sess);
		}
		return 1;
	}
	doc->encoding = xmlCharStrdup("UTF-8");
	response = xmlCharStrdup("response");
	session = xmlCharStrdup("session");
	node = xmlNewNode(NULL, response);
	node2 = xmlNewNode(NULL, session);

	if (sess != NULL)
	{
		char prop[128] = {0};
		g_sprintf(prop, "%i", sess->display);
		id = xmlCharStrdup("id");
		id_value = xmlCharStrdup(prop);
		username = xmlCharStrdup("username");
		username_value = xmlCharStrdup(sess->name);
		status = xmlCharStrdup("status");
		status_value = xmlCharStrdup(session_get_status_string(sess->status));

		xmlSetProp(node2, id, id_value);
		xmlSetProp(node2, username, username_value);
		xmlSetProp(node2, status, status_value );
		xmlAddChild(node, node2);
	}

	xmlDocSetRootElement(doc, node);
	xml_send_info(client, doc);

	xmlFree(response);
	xmlFree(session);
	xmlFree(version);

	xmlFreeDoc(doc);
	if (sess != NULL)
	{
		xmlFree(id);
		xmlFree(id_value);
		xmlFree(username);
		xmlFree(username_value);
		xmlFree(status);
		xmlFree(status_value);
		g_free(sess);
	}
	return 0;
}
示例#19
0
int ddcci_add_controls_to_subgroup(xmlNodePtr control, xmlNodePtr mon_control, 
		struct subgroup_db *current_group, struct vcp_entry** vcp, char* defined, char *matchedcontrols, int faulttolerance) {
	xmlNodePtr cur;
	xmlChar *mon_ctrlid;
	xmlChar *options_ctrlid, *options_ctrlname;
	enum refresh_type options_refresh;
	xmlChar *tmp;
	char *endptr;
	int i;
	
	struct control_db *current_control = malloc(sizeof(struct control_db));
	struct control_db **last_control_ref = &current_group->control_list;	
	memset(current_control, 0, sizeof(struct control_db));
	
	/* TODO: fix it, don't break order. */
	/* This might break control order, but it is no big deal... */
	while (*last_control_ref) {
		last_control_ref = &(*last_control_ref)->next;
	}
	
	/* List controls in group (options.xml) */
	while (control != NULL)
	{
		if (!xmlStrcmp(control->name, (const xmlChar *) "control")) {
			options_ctrlid   = xmlGetProp(control, BAD_CAST "id");
			DDCCI_DB_RETURN_IF(options_ctrlid == NULL, 0, _("Can't find id property."), control);
			options_ctrlname = xmlGetProp(control, BAD_CAST "name");
			DDCCI_DB_RETURN_IF(options_ctrlname == NULL, 0, _("Can't find name property."), control);
			
			tmp = xmlGetProp(control, BAD_CAST "refresh");
			if (tmp) {
				if (!xmlStrcmp(tmp, BAD_CAST "none")) {
					options_refresh = none;
				}
				else if (!xmlStrcmp(tmp, BAD_CAST "all")) {
					options_refresh = all;
				}
				else {
					DDCCI_DB_RETURN_IF(1, 0, _("Invalid refresh type (!= none, != all)."), control);
				}
				xmlFree(tmp);
			}
			else {
				options_refresh = none;
			}
			
			//printf("!!control id=%s group=%s name=%s\n", options_ctrlid, options_groupname, options_ctrlname);
			
			/* Find the related control in monitor specifications */
			i = 0;
			cur = mon_control->xmlChildrenNode;
			while (1)
			{
				if (cur == NULL) {
					/* Control not found */
					/* TODO: return */
					break;
				}
				if (!(xmlStrcmp(cur->name, (const xmlChar *)"control"))) {
					mon_ctrlid = xmlGetProp(cur, BAD_CAST "id");
					if (!xmlStrcmp(mon_ctrlid, options_ctrlid)) {
						tmp = xmlGetProp(cur, BAD_CAST "address");
						DDCCI_DB_RETURN_IF(tmp == NULL, 0, _("Can't find address property."), cur);
						current_control->address = strtol((char*)tmp, &endptr, 0);
						DDCCI_DB_RETURN_IF(*endptr != 0, 0, _("Can't convert address to int."), cur);
						xmlFree(tmp);
						
						matchedcontrols[i] = 1;
						
						if (vcp[current_control->address] == NULL) {
							if (get_verbosity()) {
								printf(_("Control %s has been discarded by the caps string.\n"), options_ctrlid);
							}
							memset(current_control, 0, sizeof(struct control_db));
							break;
						}
						
						if (defined[current_control->address]) {
							if (get_verbosity() > 1) {
								printf(_("Control %s (0x%02x) has already been defined.\n"), options_ctrlid, current_control->address);
							}
							memset(current_control, 0, sizeof(struct control_db));
							break;
						}
						
						current_control->id   = xmlStrdup(options_ctrlid);
						current_control->name = _D((char*)options_ctrlname);
						current_control->refresh = options_refresh;
						
						tmp = xmlGetProp(cur, BAD_CAST "delay");
						if (tmp) {
							current_control->delay = strtol((char*)tmp, &endptr, 10);
							DDCCI_DB_RETURN_IF(*endptr != 0, 0, _("Can't convert delay to int."), cur);
							xmlFree(tmp);
						}
						else {
							current_control->delay = -1;
						}
						
						tmp = xmlGetProp(control, BAD_CAST "type");
						DDCCI_DB_RETURN_IF(tmp == NULL, 0, _("Can't find type property."), control);
						if (!(xmlStrcmp(tmp, (const xmlChar *)"value"))) {
							current_control->type = value;
						}
						else if (!(xmlStrcmp(tmp, (const xmlChar *)"command"))) {
							current_control->type = command;
							if (ddcci_get_value_list(control, cur, current_control, 1, faulttolerance) < 0) {
								return 0;
							}
							if (current_control->value_list == NULL) { /* No value defined, use the default 0x01 value */
								struct value_db *current_value = malloc(sizeof(struct value_db));
								current_value->id = xmlCharStrdup("default");
								current_value->name = _D((char*)options_ctrlname);
								current_value->value = 0x01;
								current_value->next = NULL;
								current_control->value_list = current_value;
							}
						}
						else if (!(xmlStrcmp(tmp, (const xmlChar *)"list"))) {
							current_control->type = list;
							if (ddcci_get_value_list(control, cur, current_control, 0, faulttolerance) < 0) {
								return 0;
							}
						}
						else {
							DDCCI_DB_RETURN_IF(1, 0, _("Invalid type."), control);
						}
						xmlFree(tmp);
						
						/*printf("**control id=%s group=%s name=%s address=%s\n", 
						options_ctrlid, options_groupname, options_ctrlname, mon_address);*/
						
						defined[current_control->address] = 1;
						
						*last_control_ref = current_control;
						last_control_ref = &current_control->next;
						current_control = malloc(sizeof(struct control_db));
						memset(current_control, 0, sizeof(struct control_db));
						
						xmlFree(mon_ctrlid);
						break;
					}
					else {
						xmlFree(mon_ctrlid);
					}
				}
				if (cur->type == XML_ELEMENT_NODE) i++;
				cur = cur->next;
			}
		
			xmlFree(options_ctrlid);
			xmlFree(options_ctrlname);
		}
		
		control = control->next;
	} // controls loop
	
	free(current_control);
	
	return 1;
}
示例#20
0
xmlDoc *marcmap_apply(struct marcmap *marcmap, xmlDoc *xml_in)
{
    char mergekey[1024];
    char medium[32];
    char *s;
    NMEM nmem;
    xmlNsPtr ns_pz;
    xmlDocPtr xml_out;
    xmlNodePtr xml_out_root;
    xmlNodePtr rec_node;
    xmlNodePtr meta_node; 
    struct marchash *marchash;
    struct marcfield *field;
    struct marcsubfield *subfield;
    struct marcmap *mmcur;
     
    xml_out = xmlNewDoc(BAD_CAST "1.0");
    xml_out->encoding = xmlCharStrdup("UTF-8");
    xml_out_root = xmlNewNode(NULL, BAD_CAST "record");
    xmlDocSetRootElement(xml_out, xml_out_root);
    ns_pz = xmlNewNs(xml_out_root, BAD_CAST "http://www.indexdata.com/pazpar2/1.0", BAD_CAST "pz"); 
    xmlSetNs(xml_out_root, ns_pz);
    nmem = nmem_create();
    rec_node = xmlDocGetRootElement(xml_in);
    marchash = marchash_create(nmem);
    marchash_ingest_marcxml(marchash, rec_node);

    mmcur = marcmap;
    while (mmcur != NULL)
    {
        field = 0;
        while ((field = marchash_get_field(marchash, mmcur->field, field)) != 0)
        {
            // field value
            if ((mmcur->subfield == '$') && (s = field->val))
            {
                meta_node = xmlNewChild(xml_out_root, ns_pz, BAD_CAST "metadata", BAD_CAST s);
                xmlSetProp(meta_node, BAD_CAST "type", BAD_CAST mmcur->pz); 
            }
            // catenate all subfields
            else if ((mmcur->subfield == '*') && (s = marchash_catenate_subfields(field, " ", nmem)))
            {
                meta_node = xmlNewChild(xml_out_root, ns_pz, BAD_CAST "metadata", BAD_CAST s);
                xmlSetProp(meta_node, BAD_CAST "type", BAD_CAST mmcur->pz);
            }
            // subfield value
            else if (mmcur->subfield) 
            {
                subfield = 0;
                while ((subfield = 
                        marchash_get_subfield(mmcur->subfield,
                                              field, subfield)) != 0)
                {
                    if ((s = subfield->val) != 0)
                    {
                        meta_node = xmlNewChild(xml_out_root, ns_pz, BAD_CAST "metadata", BAD_CAST s);
                        xmlSetProp(meta_node, BAD_CAST "type", BAD_CAST mmcur->pz);
                    }
                }
            }
            
        }
        mmcur = mmcur->next;
    }

    // hard coded mappings

    // medium
    if ((field = marchash_get_field(marchash, "245", NULL)) && (subfield = marchash_get_subfield('h', field, NULL)))
    {
       strncpy(medium, subfield->val, 32);
    }
    else if ((field = marchash_get_field(marchash, "900", NULL)) && (subfield = marchash_get_subfield('a', field, NULL)))
       strcpy(medium, "electronic resource");
    else if ((field = marchash_get_field(marchash, "900", NULL)) && (subfield = marchash_get_subfield('b', field, NULL)))
       strcpy(medium, "electronic resource");
    else if ((field = marchash_get_field(marchash, "773", NULL)) && (subfield = marchash_get_subfield('t', field, NULL)))
       strcpy(medium, "article");
    else
       strcpy(medium, "book");

    meta_node = xmlNewChild(xml_out_root, ns_pz, BAD_CAST "metadata", BAD_CAST medium);
    xmlSetProp(meta_node, BAD_CAST "type", BAD_CAST "medium");

    // merge key
    memset(mergekey, 0, 1024);
    strcpy(mergekey, "title ");
    if ((field = marchash_get_field(marchash, "245", NULL)) && (subfield = marchash_get_subfield('a', field, NULL)))
        strncat(mergekey, subfield->val, 1023 - strlen(mergekey));
    strncat(mergekey, " author ", 1023 - strlen(mergekey));
    if ((field = marchash_get_field(marchash, "100", NULL)) && (subfield = marchash_get_subfield('a', field, NULL)))
        strncat(mergekey, subfield->val, 1023 - strlen(mergekey));
    strncat(mergekey, " medium ", 1023 - strlen(mergekey));
    strncat(mergekey, medium, 1023 - strlen(mergekey));

//    xmlSetProp(xml_out_root, BAD_CAST "mergekey", BAD_CAST mergekey);

    nmem_destroy(nmem);
    return xml_out;
}
示例#21
0
void xslt_transform(xmlDocPtr doc, const char *xslfilename, client_t *client)
{
    xmlDocPtr    res;
    xsltStylesheetPtr cur;
    xmlChar *string;
    int len, problem = 0;
    const char *mediatype = NULL;
    const char *charset = NULL;

    xmlSetGenericErrorFunc ("", log_parse_failure);
    xsltSetGenericErrorFunc ("", log_parse_failure);

    thread_mutex_lock(&xsltlock);
    cur = xslt_get_stylesheet(xslfilename);

    if (cur == NULL)
    {
        thread_mutex_unlock(&xsltlock);
        ICECAST_LOG_ERROR("problem reading stylesheet \"%s\"", xslfilename);
        client_send_404 (client, "Could not parse XSLT file");
        return;
    }

    res = xsltApplyStylesheet(cur, doc, NULL);

    if (xsltSaveResultToString (&string, &len, res, cur) < 0)
        problem = 1;

    /* lets find out the content type and character encoding to use */
    if (cur->encoding)
       charset = (char *)cur->encoding;

    if (cur->mediaType)
        mediatype = (char *)cur->mediaType;
    else
    {
        /* check method for the default, a missing method assumes xml */
        if (cur->method && xmlStrcmp (cur->method, XMLSTR("html")) == 0)
            mediatype = "text/html";
        else
            if (cur->method && xmlStrcmp (cur->method, XMLSTR("text")) == 0)
                mediatype = "text/plain";
            else
                mediatype = "text/xml";
    }
    if (problem == 0)
    {
        ssize_t ret;
        int failed = 0;
        refbuf_t *refbuf;
        size_t full_len = strlen (mediatype) + len + 1024;
        if (full_len < 4096)
            full_len = 4096;
        refbuf = refbuf_new (full_len);

        if (string == NULL)
            string = xmlCharStrdup ("");
        ret = util_http_build_header(refbuf->data, full_len, 0, 0, 200, NULL, mediatype, charset, NULL, NULL);
        if (ret == -1) {
            ICECAST_LOG_ERROR("Dropping client as we can not build response headers.");
            client_send_500(client, "Header generation failed.");
        } else {
            if ( full_len < (ret + len + 64) ) {
                void *new_data;
                full_len = ret + len + 64;
                new_data = realloc(refbuf->data, full_len);
                if (new_data) {
                    ICECAST_LOG_DEBUG("Client buffer reallocation succeeded.");
                    refbuf->data = new_data;
                    refbuf->len = full_len;
                    ret = util_http_build_header(refbuf->data, full_len, 0, 0, 200, NULL, mediatype, charset, NULL, NULL);
                    if (ret == -1) {
                        ICECAST_LOG_ERROR("Dropping client as we can not build response headers.");
                        client_send_500(client, "Header generation failed.");
                        failed = 1;
                    }
                } else {
                    ICECAST_LOG_ERROR("Client buffer reallocation failed. Dropping client.");
                    client_send_500(client, "Buffer reallocation failed.");
                    failed = 1;
                }
            }

            if (!failed) {
                  snprintf(refbuf->data + ret, full_len - ret, "Content-Length: %d\r\n\r\n%s", len, string);

                client->respcode = 200;
                client_set_queue (client, NULL);
                client->refbuf = refbuf;
                refbuf->len = strlen (refbuf->data);
                fserve_add_client (client, NULL);
            }
        }
        xmlFree (string);
    }
    else
    {
        ICECAST_LOG_WARN("problem applying stylesheet \"%s\"", xslfilename);
        client_send_404 (client, "XSLT problem");
    }
    thread_mutex_unlock (&xsltlock);
    xmlFreeDoc(res);
}
示例#22
0
文件: xslt.c 项目: dcorbe/icecast
void xslt_transform(xmlDocPtr doc, const char *xslfilename, client_t *client)
{
    xmlDocPtr    res;
    xsltStylesheetPtr cur;
    xmlChar *string;
    int len, problem = 0;
    const char *mediatype = NULL;

    xmlSetGenericErrorFunc ("", log_parse_failure);
    xsltSetGenericErrorFunc ("", log_parse_failure);

    thread_mutex_lock(&xsltlock);
    cur = xslt_get_stylesheet(xslfilename);

    if (cur == NULL)
    {
        thread_mutex_unlock(&xsltlock);
        ERROR1 ("problem reading stylesheet \"%s\"", xslfilename);
        client_send_404 (client, "Could not parse XSLT file");
        return;
    }

    res = xsltApplyStylesheet(cur, doc, NULL);

    if (xsltSaveResultToString (&string, &len, res, cur) < 0)
        problem = 1;

    /* lets find out the content type to use */
    if (cur->mediaType)
        mediatype = (char *)cur->mediaType;
    else
    {
        /* check method for the default, a missing method assumes xml */
        if (cur->method && xmlStrcmp (cur->method, XMLSTR("html")) == 0)
            mediatype = "text/html";
        else
            if (cur->method && xmlStrcmp (cur->method, XMLSTR("text")) == 0)
                mediatype = "text/plain";
            else
                mediatype = "text/xml";
    }
    if (problem == 0)
    {
        /* the 100 is to allow for the hardcoded headers */
        unsigned int full_len = strlen (mediatype) + len + 256;
        refbuf_t *refbuf = refbuf_new (full_len);
	ssize_t ret;

        if (string == NULL)
            string = xmlCharStrdup ("");
        ret = util_http_build_header(refbuf->data, full_len, 0, 0, 200, NULL, mediatype, NULL, NULL);
	snprintf (refbuf->data + ret, full_len - ret,
                "Content-Length: %d\r\n\r\n%s",
                len, string);

        client->respcode = 200;
        client_set_queue (client, NULL);
        client->refbuf = refbuf;
        refbuf->len = strlen (refbuf->data);
        fserve_add_client (client, NULL);
        xmlFree (string);
    }
    else
    {
        WARN1 ("problem applying stylesheet \"%s\"", xslfilename);
        client_send_404 (client, "XSLT problem");
    }
    thread_mutex_unlock (&xsltlock);
    xmlFreeDoc(res);
}
示例#23
0
int EBC_Provider_XchgPubRequest_H002(AB_PROVIDER *pro,
				     GWEN_HTTP_SESSION *sess,
				     AB_USER *u,
				     const char *signVersion) {
  EBC_PROVIDER *dp;
  int rv;
  const char *userId;
  const char *partnerId;
  GWEN_BUFFER *bufKey;
  GWEN_CRYPT_TOKEN *ct;
  const GWEN_CRYPT_TOKEN_CONTEXT *ctx;
  uint32_t kid;
  const GWEN_CRYPT_TOKEN_KEYINFO *signKeyInfo=NULL;

  assert(pro);
  dp=GWEN_INHERIT_GETDATA(AB_PROVIDER, EBC_PROVIDER, pro);
  assert(dp);

  userId=AB_User_GetUserId(u);
  partnerId=AB_User_GetCustomerId(u);

  /* get crypt token and context */
  rv=EBC_Provider_MountToken(pro, u, &ct, &ctx);
  if (rv<0) {
    DBG_INFO(AQEBICS_LOGDOMAIN, "here (%d)", rv);
    return rv;
  }

  /* get crypt key info */
  kid=GWEN_Crypt_Token_Context_GetTempSignKeyId(ctx);
  if (kid) {
    signKeyInfo=GWEN_Crypt_Token_GetKeyInfo(ct, kid,
					    GWEN_CRYPT_TOKEN_KEYFLAGS_HASMODULUS |
					    GWEN_CRYPT_TOKEN_KEYFLAGS_HASEXPONENT |
					    GWEN_CRYPT_TOKEN_KEYFLAGS_HASKEYVERSION |
					    GWEN_CRYPT_TOKEN_KEYFLAGS_HASKEYNUMBER,
					    0);
    if (signKeyInfo==NULL) {
      DBG_ERROR(AQEBICS_LOGDOMAIN, "Sign key info not found on crypt token");
      GWEN_Gui_ProgressLog(0,
			   GWEN_LoggerLevel_Error,
			   I18N("Sign key info not found on crypt token"));
      return GWEN_ERROR_NOT_FOUND;
    }
  }

  if (strcasecmp(signVersion, "A004")==0) {
    EB_RC rc;

    /* encode according to "DFUE-Abkommen" */
    bufKey=GWEN_Buffer_new(0, 512, 0, 1);
    rc=EB_Key_Info_toBin(signKeyInfo, userId, "A004", 1024, bufKey);
    if (rc) {
      DBG_ERROR(AQEBICS_LOGDOMAIN, "Error writing key (rc=%06x)", rc);
      GWEN_Buffer_free(bufKey);
      return GWEN_ERROR_GENERIC;
    }
  }
  else {
    xmlDocPtr doc;
    xmlNodePtr root_node = NULL;
    xmlNodePtr node = NULL;
    xmlNsPtr ns;

    /* create INIRequestOrderData */
    doc=xmlNewDoc(BAD_CAST "1.0");
    doc->encoding=xmlCharStrdup("UTF-8");
    root_node=xmlNewNode(NULL, BAD_CAST "PUBRequestOrderData");
    xmlDocSetRootElement(doc, root_node);
    ns=xmlNewNs(root_node,
		BAD_CAST "http://www.ebics.org/H002",
		NULL);
    assert(ns);
    ns=xmlNewNs(root_node,
		BAD_CAST "http://www.w3.org/2000/09/xmldsig#",
		BAD_CAST "ds");
    assert(ns);
    ns=xmlNewNs(root_node,
		BAD_CAST "http://www.w3.org/2001/XMLSchema-instance",
		BAD_CAST "xsi");
    xmlNewNsProp(root_node,
		 ns,
		 BAD_CAST "schemaLocation", /* xsi:schemaLocation */
		 BAD_CAST "http://www.ebics.org/H002 "
		 "http://www.ebics.org/H002/ebics_orders.xsd");
  
    /* create sign key tree */
    node=xmlNewChild(root_node, NULL,
		     BAD_CAST "SignaturePubKeyInfo", NULL);
    rv=EB_Key_Info_toXml(signKeyInfo, node);
    if (rv<0) {
      DBG_ERROR(AQEBICS_LOGDOMAIN, "Error response: (%d)", rv);
      xmlFreeDoc(doc);
      return GWEN_ERROR_INVALID;
    }
    xmlNewChild(node, NULL,
                BAD_CAST "SignatureVersion",
                BAD_CAST signVersion);

    /* store partner id and user id */
    node=xmlNewChild(root_node, NULL,
		     BAD_CAST "PartnerID",
		     BAD_CAST partnerId);
  
    node=xmlNewChild(root_node, NULL,
		     BAD_CAST "UserID",
		     BAD_CAST userId);
  
    /* compress and base64 doc */
    bufKey=GWEN_Buffer_new(0, 4096, 0, 1);
    rv=EB_Xml_Compress64Doc(doc, bufKey);
    if (rv<0) {
      DBG_ERROR(AQEBICS_LOGDOMAIN, "Error compressing/encoding doc (%d)", rv);
      xmlFreeDoc(doc);
      return rv;
    }
    xmlFreeDoc(doc);
  }

  rv=EBC_Provider_XchgUploadRequest(pro, sess, u, "PUB",
				    (const uint8_t*)GWEN_Buffer_GetStart(bufKey),
				    GWEN_Buffer_GetUsedBytes(bufKey));
  if (rv<0) {
    DBG_INFO(AQEBICS_LOGDOMAIN, "here (%d)", rv);
    GWEN_Buffer_free(bufKey);
    return rv;
  }

  GWEN_Buffer_free(bufKey);
  return 0;
}