Exemplo n.º 1
0
pplx::task<std::string> websocket_incoming_message::extract_string() const
{
    if (_m_impl->message_type() == websocket_message_type::binary_message)
    {
        return pplx::task_from_exception<std::string>(websocket_exception(_XPLATSTR("Invalid message type")));
    }

    auto m_impl = _m_impl;

    return pplx::create_task(_m_impl->_get_data_available()).then([m_impl]() { return m_impl->_extract_string(); });
}
Exemplo n.º 2
0
static void
_get_macro_value(name_t *name, string_t *dest, replacement_t *rpl,
    extraction_type_t ext, boolean_t cmd)
{
	property_t *prop;
	macro_t *macro;
	string_t str;
	wchar_t buf[STRING_BUFFER_LENGTH];

	/*
	 * Locate the macro property for this name:
	 */
	prop = get_prop(name->n_prop, PT_MACRO);
	if (prop == NULL) {
		/*
		 * The macro property does not exist at all, so skip out.
		 */
		goto exit;
	}
	if (prop->p_type != PT_MACRO)
		abort();
	macro = (macro_t *)prop->p_body;
	switch (macro->m_daemon) {
	case DN_NO_DAEMON:
		if (macro->m_value == NULL)
			goto exit;
		break;
	case DN_CHAIN_DAEMON:
		if (macro->m_chain == NULL)
			goto exit;
		break;
	default:
		abort();
	}

	if (macro->m_is_conditional == B_TRUE) {
		conditional_macro_used = B_TRUE;
		/*
		 * Add this conditional macro to the beginning of the global
		 * list.
		 */
		add_macro_to_global_list(name);
		if (makefile_type == MFT_READING_MAKEFILE) {
			warning_mksh(catgets(libmksdmsi18n_catd, 1, 164,
			    "Conditional macro `%ls' referenced in file "
			    "`%ls', line %d"), name->n_key, file_being_read,
			    line_number);
		}
	}

	if (rpl->rpl_type == RT_SHELL) {
		/*
		 * This is a shell replacement, so expand the command and
		 * process it.
		 */
		INIT_STRING_FROM_STACK(str, buf);

		expand_value_with_daemon(name, macro, &str, cmd);
		sh_command2string(&str, dest);

	} else if (rpl->rpl_type != RT_NONE || ext != EXT_NO) {
		wchar_t *p;
		wchar_t *block_start;
		wchar_t save;

		/*
		 * There are replacements or extractions.  Process them.
		 */
		INIT_STRING_FROM_STACK(str, buf);

		expand_value_with_daemon(name, macro, &str, cmd);
		/*
		 * Scan the expanded string:
		 */
		p = str.str_buf_start;
		while (*p != L'\0') {
			string_t exstr;
			wchar_t exbuf[MAXPATHLEN];

			/*
			 * First, skip over any whitespace and append that
			 * to the destination string.
			 */
			block_start = p;
			while (*p != L'\0' && iswspace(*p))
				p++;
			append_string_wide(block_start, dest, p - block_start);
			/*
			 * Then, find the end of the next word:
			 */
			block_start = p;
			while (*p != L'\0' && !iswspace(*p))
				p++;
			/*
			 * If we do not find another word, we are done.
			 */
			if (block_start == p)
				break;
			/*
			 * Process the requested extraction:
			 */
			INIT_STRING_FROM_STACK(exstr, exbuf);

			save = *p;
			*p = L'\0';
			_extract_string(ext, block_start, &exstr);
			*p = save;

			/*
			 * Process the requested replacement:
			 */
			_replace_string(rpl, &exstr, dest);
			if (exstr.str_free_after_use == B_TRUE)
				free(exstr.str_buf_start);
		}
	} else {
		/*
		 * There are no replacements or extractions.
		 */
		if (wcscmp(name->n_key, L"GET") == 0) {
			dollarget_seen = B_TRUE;
		}
		dollarless_flag = B_FALSE;
		if (wcscmp(name->n_key, L"<") && dollarget_seen == B_TRUE) {
			dollarless_flag = B_TRUE;
			dollarget_seen = B_FALSE;
		}
		expand_value_with_daemon(name, macro, dest, cmd);
	}

exit:
	if (str.str_free_after_use == B_TRUE)
		free(str.str_buf_start);
}