예제 #1
0
파일: xml.c 프로젝트: FuangCao/cavan
char *cavan_xml_document_tostring(struct cavan_xml_document *doc, char *buff, size_t size)
{
	char *buff_end = buff + size - 1;
	struct cavan_xml_tag *tag;
	struct cavan_xml_attribute *attr;

	if (doc->attr != NULL) {
		for (tag = doc->attr; tag; tag = tag->next) {
			buff += snprintf(buff, buff_end - buff, "<?%s", tag->name);

			for (attr = tag->attr; attr; attr = attr->next) {
				buff = text_ncopy(buff, doc->word_sep, buff_end - buff);
				buff = cavan_xml_attribute_tostring(attr, buff, buff_end);
			}

			buff += snprintf(buff, buff_end - buff, "?>%s", doc->newline);
		}

		buff = text_ncopy(buff, doc->newline, buff_end - buff);
	}

	for (tag = doc->tag; tag; tag = tag->next) {
		buff = cavan_xml_tag_tostring(doc, tag, 0, buff, buff_end);
		buff = text_ncopy(buff, doc->newline, buff_end - buff);
	}

	*buff = 0;

	return buff;
}
예제 #2
0
static int cavan_ext4_find_file_handler(struct ext2_desc *desc, void *block, size_t count, struct cavan_ext2_traversal_option *_option)
{
	struct ext2_directory_entry *entry, *entry_end;
	struct cavan_ext4_find_file_option *option = (struct cavan_ext4_find_file_option *) _option;

	entry = block;
	entry_end = ADDR_ADD(entry, desc->block_size * count);

	while (entry < entry_end)
	{
		entry->name[entry->name_len] = 0;

#if CAVAN_EXT2_DEBUG
		show_ext2_directory_entry(entry);
#endif

		if (text_cmp(option->filename, entry->name) == 0)
		{
			mem_copy(option->entry, entry, EXT2_DIR_ENTRY_HEADER_SIZE);
			text_ncopy(option->entry->name, entry->name, entry->name_len);
			return CAVAN_EXT2_TRAVERSAL_FOUND;
		}

		entry = ADDR_ADD(entry, entry->rec_len);
	}

	return CAVAN_EXT2_TRAVERSAL_CONTINUE;
}
예제 #3
0
파일: xml.c 프로젝트: FuangCao/cavan
static char *cavan_xml_tag_get_line_prefix(const char *prefix, int level, char *buff, size_t size)
{
	char *buff_end;

	for (buff_end = buff + size - 1; level > 0; level--) {
		buff = text_ncopy(buff, prefix, buff_end - buff);
	}

	*buff = 0;

	return buff;
}
예제 #4
0
파일: ftp.c 프로젝트: Jack19881218/cavan
static char *ftp_get_abs_path(const char *curr_path, const char *path, char *abs_path, size_t size)
{
	if (*path == '/')
	{
		text_ncopy(abs_path, path, size);
	}
	else
	{
		text_path_cat(abs_path, size, curr_path, path);
	}

#if FTP_DEBUG
	println("curr_path = %s, abs_path = %s, path = %s", curr_path, abs_path, path);
#endif

	return abs_path;
}
예제 #5
0
static char *modem_read_new_version(const char *dirname, char *version, size_t size)
{
	ssize_t prop_count;
	struct modem_prop props[100];
	struct modem_prop *prop_tmp;

	prop_count = parse_string_list(dirname, props, ARRAY_SIZE(props));
	if (prop_count < 0)
	{
		error_msg("parse_string_list");
		return NULL;
	}

	prop_tmp = modem_find_prop(props, prop_count, MODEM_VERSION_PROP_NAME);
	if (prop_tmp == NULL)
	{
		return NULL;
	}

	text_ncopy(version, prop_tmp->value, size);

	return version;
}
예제 #6
0
파일: ftp.c 프로젝트: Jack19881218/cavan
int ftp_client_read_response(struct network_client *client, char *response, size_t size)
{
	int state;
	ssize_t rwlen;
	char buff[2048], *p = buff, *p_end = p + sizeof(buff);

	while (p < p_end)
	{
		char *q;

		rwlen = network_client_timed_recv(client, p, p_end - p, 5000);
		if (rwlen <= 0)
		{
			return -EFAULT;
		}

		for (q = p, p += rwlen; q < p; q++)
		{
			int step = 0;

			while (q < p && IS_NUMBER(*q))
			{
				q++;
			}

			if (q < p && *q != '-')
			{
				step++;
			}

			while (q < p)
			{
				if (*q == '\n')
				{
					step++;
					break;
				}

				q++;
			}

			if (step == 2)
			{
				goto label_read_complete;
			}
		}
	}

label_read_complete:
	*p = 0;
#if FTP_DEBUG
	print_ntext(buff, p - buff);
#endif
	state = text2value_unsigned(buff, (const char **) &p, 10);

	if (response && size > 0)
	{
		text_ncopy(response, p + 1, size);
	}

	return state;
}
예제 #7
0
파일: test_fifo.c 프로젝트: FuangCao/cavan
static ssize_t test_fifo_read(struct cavan_fifo *fifo, void *buff, size_t size)
{
	pr_pos_info();

	return text_ncopy(buff, "0123456789", size) - (char *) buff;
}
예제 #8
0
파일: xml.c 프로젝트: FuangCao/cavan
static char *cavan_xml_tag_tostring(struct cavan_xml_document *doc, struct cavan_xml_tag *tag, int level, char *buff, char *buff_end)
{
	char prefix[32];
	struct cavan_xml_attribute *attr;

	cavan_xml_tag_get_line_prefix(doc->line_prefix, level, prefix, sizeof(prefix));

	buff += snprintf(buff, buff_end - buff, "%s<%s", prefix, tag->name);

	for (attr = tag->attr; attr; attr = attr->next) {
		buff = text_ncopy(buff, doc->word_sep, buff_end - buff);
		buff = cavan_xml_attribute_tostring(attr, buff, buff_end);
	}

	if (tag->child) {
		struct cavan_xml_tag *child;

		buff += snprintf(buff, buff_end - buff, ">%s", doc->newline);

		for (child = tag->child; child; child = child->next) {
			buff = cavan_xml_tag_tostring(doc, child, level + 1, buff, buff_end);
			buff = text_ncopy(buff, doc->newline, buff_end - buff);
		}

		buff += snprintf(buff, buff_end - buff, "%s</%s>", prefix, tag->name);
	} else if (tag->content) {
		if ((tag->flags & CAVAN_XML_FLAG_CONTENT_MULTI_LINE)) {
			char *content, *p, *p_end;
			char *q, *q_end;
			size_t length;

			length = strlen(tag->content);
			content = alloca(length + 100);
			if (content == NULL) {
				pr_error_info("alloca");
				return buff;
			}

			p = content;
			p_end = p + length + 100;

			q = (char *) tag->content;
			q_end = q + length;
			q = text_skip_space_and_lf(q, q_end);

			while (q < q_end && p < p_end) {
				switch (*q) {
				case '\n':
					q = text_skip_space(q + 1, q_end);
					p += snprintf(p, p_end - p, "%s%s%s", doc->newline, prefix, doc->line_prefix);
					break;

				default:
					*p++ = *q++;
				}
			}

			p = text_skip_space_and_lf_invert(p - 1, content);
			p[1] = 0;

			buff += snprintf(buff, buff_end - buff, ">%s%s%s%s%s%s</%s>", doc->newline, prefix, doc->line_prefix, content, doc->newline, prefix, tag->name);
		} else {
			buff += snprintf(buff, buff_end - buff, ">%s</%s>", tag->content, tag->name);
		}
	} else {
		buff = text_ncopy(buff, "/>", buff_end - buff);
	}

	return buff;
}