Esempio n. 1
0
static int  parseBody(Resolver * const me, xmlNodePtr cur)
{
        xmlChar *key;
        if ((!xmlStrcmp(cur->name, (const xmlChar *)"message")))
        {
                key = xmlGetProp(cur, (const xmlChar *)"code");
                printf("\tcode:%s\n", key);
                 /*������code�Ƿ�һ�£������������*/
                if (CheckGatewayCode(key) != 0)
                {
                        me->CMTID = -1; 
			PrintfRed("getway code error!");
                        XmlFree(key);
                        return -1;
                }
                me->CMTID = 0;
                XmlFree(key);
                cur = cur->xmlChildrenNode;
                while (cur != NULL)
                {   
                        if ((!xmlStrcmp(cur->name, (const xmlChar *)"config")))/*�������*/                
                        {
                                printf("%s:\n", cur->name);
                                
                                deviceMgmt->deletesensorconfig(deviceMgmt, UF_STATUS);
                                deviceMgmt->deletezigbeeconfig(deviceMgmt);
                                parseDevice(me, cur);
                                deviceMgmt->disablecom(deviceMgmt);
   
                        }
                        else if ((!xmlStrcmp(cur->name, (const xmlChar *)"control")))
                        {
                                printf("%s:\n", cur->name);
                                key = xmlGetProp(cur, (const xmlChar *)"action");
                                printf("action:%s\n", key);
                                XmlFree(key);
                                key = xmlGetProp(cur, (const xmlChar *)"cid");
                                printf("cid:%s\n", key);
                                XmlFree(key);
                                key = xmlGetProp(cur, (const xmlChar *)"object");
                                printf("object:%s\n", key);
                                XmlFree(key);
                                
                        }
                        cur = cur->next;
                }
        }
        
        return -1;
}
Esempio n. 2
0
Boolean
check_last_change_date (	XmlContent	*file_info_element,
				XmlDocument	*document )
/*
Input:
	file_info_element	- The last-change element will be read from this
				  element
	document		- file_info_element must located in this XmlDocument
Returns:
	TRUE if the date was succesfully read, otherwise FALSE.
Description:
	This function reads the last-change element that is located in
	file_info_element and checks if it is OK.
*/
{
	XmlElementType		*last_change_type;
	XmlContent		*last_change_element;
	XmlAttributeName	*format_attrname;
	char			*date_string,
				*format;
	Boolean			return_val;
	struct tm		date;
	
	/* Get the last-change element */
	if ((last_change_type = XmlGetElementType(ELEM_TYPE_LASTCHANGE, document, FALSE)) == NULL ||
	    (last_change_element =
	      XmlGetElementOfType(XmlElementContentList(file_info_element), last_change_type, 0)) == NULL)
	{
		return (FALSE);
	}
	/* Get the value of the format attribute */
	if ((format_attrname = XmlGetAttributeName(ATTR_NAME_FORMAT, document, FALSE)) == NULL ||
	    (format = XmlGetAttributeValue(format_attrname, last_change_element)) == NULL)
	{
		return (FALSE);
	}
	
	date_string = XmlGetElementString(last_change_element, "");
	/* Convert string to a time tm structure */
	return_val = (strptime(date_string, format, &date) != NULL);
	if (!return_val)
	{
		KTSetErrorMsg (_("The last-change-date \"%s\" of the keyboard file is not a valid date."), date_string);
	}
	XmlFree (date_string);
	
	return (return_val);
}
Esempio n. 3
0
static int  getZigbeeMac(Resolver * const me, xmlNodePtr cur)
{
        xmlChar *key;
        int ZigbeeNUM = 0;
        key = xmlGetProp(cur, (const xmlChar *)"mac");
        if(key != NULL)
        {
                strcpy(deviceMgmt->zigbeeconfig.mac,  (char *)key);
                deviceMgmt->savezigbeeconfig(deviceMgmt);
                ZigbeeNUM = deviceMgmt->mac2zigbeenum(deviceMgmt, (char *)key);
        }
        printf("mac:%s\n", key);
        XmlFree(key);

        return ZigbeeNUM;
}
Esempio n. 4
0
Boolean
syntax_version_ok (	XmlContent	*file_info_element,
			XmlDocument	*document,
			unsigned int	version_major,
			unsigned int	version_minor )
/*
Input:
	file_info_element	- The syntax version will be read from this element
	document		- file_info_element must located in this XmlDocument
	version_major		- The compatible major syntax version number
	version_minor		- The latest compatible minor syntax version number
Output:
	-
Returns:
	TRUE if the syntax version was succesfully read, the major version number
	equals version_major and the minor version number is less than or equal to
	version_minor. Otherwise FALSE is returned.
Description:
	This function reads the syntax-version element that is located in 
	file_info_element. This function will return TRUE if this version is
	compatible with the version specified in the input variables (version_major
	and version_minor).
*/
{
	XmlElementType	*syntax_version_type;
	XmlContent	*syntax_version_element;
	char		*version_string;
	unsigned int	maj, min;
	
	if ((syntax_version_type = XmlGetElementType (ELEM_TYPE_SYNTAXVERSION, document, FALSE)) == NULL ||
	    (syntax_version_element =
	      XmlGetElementOfType (XmlElementContentList(file_info_element), syntax_version_type, 0)) == NULL)
	{
		return (FALSE);
	}
	
	version_string = XmlGetElementString (syntax_version_element, "");
	/* Convert the string to version numbers */
	if (sscanf(version_string, "%d.%d", &maj, &min) != 2)
	{
		maj = min = 0;
	}
	XmlFree (version_string);
	
	/* Return TRUE if the version is compatible */
	return (maj == version_major && min <= version_minor);
}
Esempio n. 5
0
static void loadQuest(const int var,
                      XmlNodeConstPtr node)
{
    if (node == nullptr)
        return;
    QuestItem *const quest = new QuestItem;
    // TRANSLATORS: quests window quest name
    quest->name = XML::langProperty(node, "name", _("unknown"));
    quest->group = XML::getProperty(node, "group", "");
    std::string incompleteStr = XML::getProperty(node, "incomplete", "");
    std::string completeStr = XML::getProperty(node, "complete", "");
    if (incompleteStr.empty() && completeStr.empty())
    {
        logger->log("complete flags incorrect");
        delete quest;
        return;
    }
    splitToIntSet(quest->incomplete, incompleteStr, ',');
    splitToIntSet(quest->complete, completeStr, ',');
    if (quest->incomplete.empty() && quest->complete.empty())
    {
        logger->log("complete flags incorrect");
        delete quest;
        return;
    }
    if (quest->incomplete.empty() || quest->complete.empty())
        quest->broken = true;

    for_each_xml_child_node(dataNode, node)
    {
        if (!xmlTypeEqual(dataNode, XML_ELEMENT_NODE))
            continue;
        XmlChar *const data = reinterpret_cast<XmlChar*>(
            XmlNodeGetContent(dataNode));
        if (data == nullptr)
            continue;
        std::string str = translator->getStr(data);
        XmlFree(data);

        for (int f = 1; f < 100; f ++)
        {
            const std::string key = strprintf("text%d", f);
            const std::string val = XML::getProperty(dataNode,
                key.c_str(),
                "");
            if (val.empty())
                break;
            const std::string param = strprintf("{@@%d}", f);
            replaceAll(str, param, val);
        }
        replaceItemLinks(str);
        if (xmlNameEqual(dataNode, "text"))
        {
            quest->texts.push_back(QuestItemText(str,
                QuestType::TEXT,
                std::string(),
                std::string()));
        }
        else if (xmlNameEqual(dataNode, "name"))
        {
            quest->texts.push_back(QuestItemText(str,
                QuestType::NAME,
                std::string(),
                std::string()));
        }
        else if (xmlNameEqual(dataNode, "reward"))
        {
            quest->texts.push_back(QuestItemText(str,
                QuestType::REWARD,
                std::string(),
                std::string()));
        }
        else if (xmlNameEqual(dataNode, "questgiver") ||
                 xmlNameEqual(dataNode, "giver"))
        {
            quest->texts.push_back(QuestItemText(str,
                QuestType::GIVER,
                std::string(),
                std::string()));
        }
        else if (xmlNameEqual(dataNode, "coordinates"))
        {
            const std::string str1 = toString(XML::getIntProperty(
                dataNode, "x", 0, 1, 1000));
            const std::string str2 = toString(XML::getIntProperty(
                dataNode, "y", 0, 1, 1000));
            quest->texts.push_back(QuestItemText(str,
                QuestType::COORDINATES,
                str1,
                str2));
        }
        else if (xmlNameEqual(dataNode, "npc"))
        {
            quest->texts.push_back(QuestItemText(str,
                QuestType::NPC,
                std::string(),
                std::string()));
        }
    }
    quest->var = var;
    mQuests[var].push_back(quest);
}
Esempio n. 6
0
Boolean
check_keyboard_file (XmlDocument *keyboard_file)
/*
Input:
	keyboard_file	- The contents of the keyboard file to check
Returns:
	TRUE if 'keyboard_file' is valid, otherwise FALSE.
Desciption:
	This function checks if the contents of 'keyboard_file' are valid according
	the "keyTouch 2.1 file documentation". If 'keyboard_file' is not valid then
	an error message describing why it is invalid can be retrieved using
	KTGetErrorMsg().
*/
{
	XmlContent		*keyboard_element,
				*file_info_element,
				*keylist_element,
				*keyboard_name_element,
				*keyboard_info_element;
	XmlElementType		*keyboard_type,
				*file_info_type,
				*keylist_type,
				*key_type,
				*keyname_type,
				*scancode_type,
				*event_descr_type,
				*keycode_type,
				*default_action_type,
				*pluginname_type,
				*pluginfunction_type,
				*keyboard_name_type,
				*keyboard_info_type,
				*model_type,
				*manufacturer_type;
	XmlAttributeName	*action_type_attrname,
				*key_type_attrname;
	Boolean			error, valid;
	unsigned int		index, num_keys;
	char			*key_names[MAX_NUM_KEYS];
	Boolean			keycode_used[NUM_KEYCODES] = {[0 ... NUM_KEYCODES-1] = 0};
	
	error = FALSE;
	
	event_descr_type = XmlGetElementType (ELEM_TYPE_ACPI_EVENT_DESCR, keyboard_file, TRUE);
	scancode_type = XmlGetElementType (ELEM_TYPE_SCANCODE, keyboard_file, TRUE);
	
	if ((keyboard_type = XmlGetElementType (ELEM_TYPE_KEYBOARD, keyboard_file, FALSE)) == NULL ||
	    (keyboard_element = XmlGetElementOfType (XmlDocumentContentList(keyboard_file), keyboard_type, 0)) == NULL)
	{
		KTSetErrorMsg (_("The keyboard file does not contain a keyboard element."), "");
		error = TRUE;
	}
	else if ((keyboard_info_type = XmlGetElementType(ELEM_TYPE_KEYBOARDINFO, keyboard_file, FALSE)) == NULL ||
	         (keyboard_name_type = XmlGetElementType(ELEM_TYPE_KEYBOARDNAME, keyboard_file, FALSE)) == NULL ||
	         (model_type = XmlGetElementType(ELEM_TYPE_MODEL, keyboard_file, FALSE)) == NULL ||
	         (manufacturer_type = XmlGetElementType(ELEM_TYPE_MANUFACTURER, keyboard_file, FALSE)) == NULL ||
	         (keyboard_info_element =
	           XmlGetElementOfType (XmlElementContentList(keyboard_element), keyboard_info_type, 0)) == NULL ||
	         (keyboard_name_element =
	           XmlGetElementOfType (XmlElementContentList(keyboard_info_element), keyboard_name_type, 0)) == NULL ||
	         XmlGetElementOfType (XmlElementContentList(keyboard_name_element), model_type, 0) == NULL ||
	         XmlGetElementOfType (XmlElementContentList(keyboard_name_element), manufacturer_type, 0) == NULL)
	{
		KTSetErrorMsg (_("The keyboard file does provide enough information about the keyboard model."), "");
		error = TRUE;
	}
	else if ((keylist_type = XmlGetElementType(ELEM_TYPE_KEYLIST, keyboard_file, FALSE)) == NULL ||
		 (keylist_element =
		   XmlGetElementOfType(XmlElementContentList(keyboard_element), keylist_type, 0)) == NULL)
	{
		KTSetErrorMsg (_("The keyboard file does not contain a key-list element."), "");
		error = TRUE;
	}
	else if ((file_info_type = XmlGetElementType(ELEM_TYPE_FILEINFO, keyboard_file, FALSE)) == NULL ||
	         (file_info_element =
		     XmlGetElementOfType(XmlElementContentList(keyboard_element), file_info_type, 0)) == NULL)
	{
		KTSetErrorMsg (_("The \"keyboard\" element in the keyboard file does not contain a %s element."), ELEM_TYPE_FILEINFO);
		error = TRUE;
	}
	else if (!syntax_version_ok (file_info_element, keyboard_file, SYNTAX_VERSION_MAJOR, SYNTAX_VERSION_MINOR))
	{
		KTSetErrorMsg (_("The syntax version of the keyboard file is not compatible with this version of keyTouch."), SYNTAX_VERSION_STRING);
		error = TRUE;
	}
	else if (!check_last_change_date (file_info_element, keyboard_file))
	{
		/* NOTE: KTSetErrorMsg() is already called by check_last_change_date() */
		error = TRUE;
	}
	else if ((default_action_type = XmlGetElementType(ELEM_TYPE_DEFAULTACTION, keyboard_file, FALSE)) == NULL)
	{
		KTSetErrorMsg (_("The keyboard file does not contain any %s element."), ELEM_TYPE_DEFAULTACTION);
		error = TRUE;
	}
	else if ((key_type = XmlGetElementType(ELEM_TYPE_KEY, keyboard_file, FALSE)) == NULL)
	{
		KTSetErrorMsg (_("The keyboard file does not contain any %s element."), ELEM_TYPE_KEY);
		error = TRUE;
	}
	else if ((keyname_type = XmlGetElementType(ELEM_TYPE_KEYNAME, keyboard_file, FALSE)) == NULL)
	{
		KTSetErrorMsg (_("The keyboard file does not contain any %s element."), ELEM_TYPE_KEYNAME);
		error = TRUE;
	}
	else if ((keycode_type = XmlGetElementType(ELEM_TYPE_KEYCODE, keyboard_file, FALSE)) == NULL)
	{
		KTSetErrorMsg (_("The keyboard file does not contain any %s element."), ELEM_TYPE_KEYCODE);
		error = TRUE;
	}
	else
	{
		action_type_attrname = XmlGetAttributeName (ATTR_NAME_ACTIONTYPE, keyboard_file, TRUE);
		key_type_attrname = XmlGetAttributeName (ATTR_NAME_KEYTYPE, keyboard_file, TRUE);
		/* Create the element types "plugin-name" and "plugin-function" if they
		 * do not appear in the document, because these element do not necessary
		 * appear in the document */
		pluginname_type = XmlGetElementType (ELEM_TYPE_PLUGINNAME, keyboard_file, TRUE);
		pluginfunction_type = XmlGetElementType (ELEM_TYPE_PLUGINFUNCTION, keyboard_file, TRUE);
		
		num_keys = 0;
		for (index = 0;
		     check_key_settings (keylist_element, index, key_type, keyname_type, keycode_type,
		                         scancode_type, event_descr_type, default_action_type,
		                         pluginname_type, pluginfunction_type, action_type_attrname,
		                         key_type_attrname, &num_keys, key_names, keycode_used, &valid);
		     index++)
		{
			if (!valid)
			{
				error = TRUE;
				break;
			}
		}
		while (num_keys--)
		{
			XmlFree (key_names[num_keys]);
		}
	}
	
	return !error;
}
Esempio n. 7
0
Boolean
check_key_settings (	XmlContent		*keylist_element,
			int			index,
			XmlElementType		*key_type,
			XmlElementType		*keyname_type,
			XmlElementType		*keycode_type,
			XmlElementType		*scancode_type,
			XmlElementType		*acpi_event_descr_type,
			XmlElementType		*default_action_type,
			XmlElementType		*pluginname_type,
			XmlElementType		*pluginfunction_type,
			XmlAttributeName	*action_type_attrname,
			XmlAttributeName	*key_type_attrname,
			unsigned int		*num_keys,
			char			*key_names[MAX_NUM_KEYS],
			Boolean			keycode_used[NUM_KEYCODES],
			Boolean			*valid )
/*
Input:
	keylist_element		- The parent of the element to check.
	index			- Read the index'th key element
	key_type		- The XmlElementType for the key element
	keyname_type		- The XmlElementType for the key-name element
	keycode_type		- The XmlElementType for the keycode element
	scancode_type		- The XmlElementType for the scancode element
	acpi_event_descr_type	- The XmlElementType for the event-descr element
	default_action_type	- The XmlElementType for the default-action element
	pluginname_type		- The XmlElementType for the plugin-name element
	pluginfunction_type	- The XmlElementType for the plugin-function element
	action_type_attrname	- The XmlElementName for the action-type attribute
	key_type_attrname	- The XmlElementName for the key-type attribute
	num_keys		- The number of elements used in 'key_names'
	key_names		- Array of pointers to key names that are in the
				  keyboard file.
	keycode_used		- For keycode i, keycode_used[i] indicates if it is
				  used already in the keyboard file.
Output:
	valid			- Will be TRUE if the index'th element of 'key_type'
				  in 'keylist_element', is valid (otherwise FALSE).
	num_keys		- If '*valid' is TRUE then 'num_keys' will be
				  increased with 1 if it is smaller than
				  MAX_NUM_KEYS-1.
	key_names		- If '*valid' is TRUE then the (*num_key-1)'th (if
				  *num_keys < MAX_NUM_KEYS) element of this array,
				  will point to the key name of the checked key
				  setting. The memory of this name is allocated and
				  should be freed if it is no longer needed.
	keycode_used		- For keycode i, keycode_used[i] indicates if it is
				  used already in the keyboard file.
Returns:
	TRUE if the index'th element of 'key_type' in 'keylist_element' exist.
Desciption:
	This function checks if the key_name and default_action member, of the
	index'th key element of 'keylist_element', are valid.
*/
{
	XmlContent	*key_element,
			*event_descr_element,
			*keyname_element,
			*keycode_element,
			*scancode_element,
			*default_action_element;
	unsigned int	i, keycode;
	char		*key_name,
			*key_type_str,
			*end_pointer,
			*keycode_string,
			*scancode_string;
	Boolean		is_acpi_hotkey;
	
	*valid = TRUE;
	key_element = XmlGetElementOfType(XmlElementContentList(keylist_element), key_type, index);
	if (key_element)
	{
		key_type_str = XmlGetAttributeValue (key_type_attrname, key_element);
		is_acpi_hotkey = (key_type_str && !strcmp(key_type_str, ATTR_VAL_ACPIHOTKEY));
		if ((keyname_element = XmlGetElementOfType(XmlElementContentList(key_element), keyname_type, 0)) == NULL ||
		    (default_action_element = XmlGetElementOfType(XmlElementContentList(key_element), default_action_type, 0)) == NULL ||
		    (keycode_element = XmlGetElementOfType(XmlElementContentList(key_element), keycode_type, 0)) == NULL ||
		    (is_acpi_hotkey ?
		       (event_descr_element = XmlGetElementOfType(XmlElementContentList(key_element), acpi_event_descr_type, 0)) == NULL :
		       (scancode_element = XmlGetElementOfType(XmlElementContentList(key_element), scancode_type, 0)) == NULL) )
		{
			KTSetErrorMsg (_("The keyboard file contains an incomplete key element."), "");
			*valid = FALSE;
		}
		else
		{
			key_name = XmlGetElementString (keyname_element, "");
			if (*key_name == '\0')
			{
				KTSetErrorMsg (_("The keyboard file contains an empty key-name element."), "");
				*valid = FALSE;
			}
			else
			{
				for (i = 0; i < *num_keys && strcmp (key_name, key_names[i]) != 0; i++)
					; /* NULL Statement */
				if (i < *num_keys)
				{
					KTSetErrorMsg (_("The keyboard file contains more than once a key named '%s'."), key_name);
					*valid = FALSE;
				}
				else if ( !check_action (default_action_element, pluginname_type,
					                 pluginfunction_type, action_type_attrname) )
				{
					*valid = FALSE;
				}
				
			}
			if (*valid)
			{
				if (!is_acpi_hotkey)
				{
					/** Check the scancode **/
					scancode_string = XmlGetElementString(scancode_element, "");
					/* Convert the string of the scancode to a integer */
					strtol (scancode_string, &end_pointer, 0);
					/* If the scancode string is not a vallid scancode */
					if (*end_pointer != '\0')
					{
						KTSetErrorMsg (_("'%s' is an invalid scancode."), scancode_string);
						*valid = FALSE;
					}
					XmlFree (scancode_string);
				}
				
				if (*valid)
				{
					/** Check the keycode **/
					keycode_string = XmlGetElementString (keycode_element, "");
					keycode = string_to_kernel_keycode (keycode_string);
					if (keycode)
					{
						if (keycode_used[keycode])
						{
							KTSetErrorMsg (_("Keycode %s is used more than once."), keycode_string);
							*valid = FALSE;
						}
						else
						{
							keycode_used[keycode] = TRUE;
						}
					}
					else
					{
						if (keycode_string[0] == '\0')
						{
							KTSetErrorMsg (_("The keyboard file contains an empty keycode."), "");
						}
						else
						{
							KTSetErrorMsg (_("'%s' is an invalid keycode."), keycode_string);
						}
						*valid = FALSE;
					}
					XmlFree (keycode_string);
					
					if (*valid && *num_keys < MAX_NUM_KEYS-1)
					{
						key_names[*num_keys] = key_name;
						(*num_keys)++;
					}
					else
					{
						XmlFree (key_name);
					}
				}
			}
		}
	}
	
	return (key_element != NULL);
}
Esempio n. 8
0
static int  getConfig(Resolver * const me, xmlNodePtr cur, int ZigbeeNUM)
{
        xmlChar *key;
		int Interface;

        memset(&me->config, 0, sizeof(me->config));
        
        key = xmlGetProp(cur, (const xmlChar *)"code");
        
        if(key != NULL)
        {
                me->config.code = atol((char *)key);    
        }
        
        printf("code:%ld\n", me->config.code);
        XmlFree(key);

        key = xmlGetProp(cur, (const xmlChar *)"type");
        
        if(key != NULL)
        {
              strcpy(me->config.type, (char *)key);
		Interface = atol((char *)key); 
        }
        
        printf("type:%s\n", me->config.type);
        XmlFree(key);

        key = xmlGetProp(cur, (const xmlChar *)"sleeptime");
        
        if(key != NULL)
        {
                me->config.sleeptime = atol((char *)key);
        }
        
        printf("sleeptime:%ld\n", me->config.sleeptime);
        XmlFree(key);

        key = xmlGetProp(cur, (const xmlChar *)"ratio");
        
        if(key != NULL)
        {
                me->config.ratio = atof((char *)key);
        }
        
        printf("ratio:%lf\n", me->config.ratio);
        XmlFree(key);

        deviceMgmt->sensorconfig.code = me->config.code;
	/*	
	Interface = deviceMgmt->type2interface(deviceMgmt, me->config.type);
	if(Interface < 0)
	{
		PrintfRed("unknow sensor name!");
		return 0;
	}
//ÐÞ¸ÄÔ­Òò£¬È¡Ïû·¢ËÍ´«¸ÐÆ÷Ãû³Æ£¬¸ÄΪֱ½Ó·¢ËÍinterface

	*/
	
	deviceMgmt->sensorconfig.interface = Interface;
	if(me->config.sleeptime < 0)
	{
		PrintfRed("sleeptime illegal!");
		return 0;
	}
	
        deviceMgmt->sensorconfig.sleeptime = me->config.sleeptime;
		
        deviceMgmt->sensorconfig.ratio = me->config.ratio;
        deviceMgmt->sensorconfig.zigbeenum = ZigbeeNUM;
        deviceMgmt->savesensorconfig(deviceMgmt);
        
        return 0;

}