Example #1
0
static void updateCallstack(CallstackData* data, PDReader* reader) {
    PDReaderIterator it;

    if (PDRead_find_array(reader, &it, "callstack", 0) == PDReadStatus_NotFound)
        return;

    for (CallstackEntry& entry : data->callstack) {
        free((void*)entry.address);
        free((void*)entry.module);
        free((void*)entry.filename);
    }

    data->callstack.clear();

    // TODO: Have a "spec" for the callstack to be used

    while (PDRead_get_next_entry(reader, &it)) {
        const char* filename = "";
        const char* module = "";
        char address[64] = { 0 };
        uint32_t line = (uint32_t) ~0;

        CallstackEntry entry = { 0 };

        getAddressString(address, reader, it);

        PDRead_find_string(reader, &filename, "filename", it);
        PDRead_find_string(reader, &module, "module_name", it);
        PDRead_find_u32(reader, &line, "line", it);

        entry.address = strdup(address);
        entry.line = -1;

        if (filename) {
            int fSep = findSeparator(filename);
            entry.filename = strdup(&filename[fSep]);
        }

        if (module) {
            int mSep = findSeparator(module);
            entry.module = strdup(&module[mSep]);
        }

        if (line != (uint32_t) ~0)
            entry.line = (int)line;

        data->callstack.push_back(entry);
    }
}
Example #2
0
const Symbol*
Symbol::findSymbolByQualifiedName(Name name, bool restricted) const
{
    size_t p;
    const String& sname = name;

//     const Symbol* s = context()->globalScope()->findSymbol(name);

//     if (s && s->scope() == context()->globalScope())
//     {
//         return s;
//     }

    if ((p = findSeparator(sname)) != String::npos)
    {
        Mu::String first = sname.substr(0, p);
        Mu::String rest  = sname.substr(p + 1);

	if (Name name0 = context()->lookupName(first.c_str()))
	{
	    if (const Symbol* sym = findSymbol(name0))
	    {
		if (rest != "")
		{
                    Name n = context()->internName(rest.c_str());

		    for (const Symbol *s = sym->firstOverload();
			 s;
			 s = s->nextOverload())
		    {
			if (!restricted || s->_searchable)
			{
                            if (const Symbol* child =
                                s->findSymbolByQualifiedName(n, restricted))
                            {
                                return child;
                            }
			}
		    }
		}
		else
		{
		    return sym;
		}
	    }
	}
    }
    else
    {
	return findSymbol(name);
    }

    return 0;
}
Example #3
0
void TrackData_linkTrack(int index, const char* name, TrackData* trackData)
{
	int found;
	char group_name[256];
	Group* group;
	Group* groups = trackData->groups;
	Track* track = &trackData->tracks[index];

	if (track->group)
		return;

	found = findSeparator(name);

	if (found == -1)
	{
		Group* group = &groups[trackData->groupCount++];
		memset(group, 0, sizeof(Group));
		
		group->tracks = (Track**)malloc(sizeof(Track**));
		group->tracks[0] = track;
		group->type = GROUP_TYPE_TRACK;
		group->trackCount = 1;
		track->group = group;
		track->displayName = strdup(name); 
		group->groupIndex = trackData->groupCount - 1;

		printf("Linking track %s to group %s\n", name, name); 

		return;
	}

	memset(group_name, 0, sizeof(group_name));
	memcpy(group_name, name, found + 1); 

	group = findOrCreateGroup(group_name, trackData); 

	if (group->trackCount == 0)
		group->tracks = (Track**)malloc(sizeof(Track**));
	else
		group->tracks = (Track**)realloc(group->tracks, sizeof(Track**) * (group->trackCount + 1));

	printf("Linking track %s to group %s\n", name, group_name); 

	track->groupIndex = group->trackCount;
	group->tracks[group->trackCount++] = track;

	track->group = group;
	track->displayName = strdup(&name[found + 1]);

	printf("groupDisplayName %s\n", group->displayName);
}
Example #4
0
am_status_t Properties::parseBuffer(char *buffer)
{
    am_status_t status = AM_SUCCESS;
    char *nextLine;
#if defined(_AMD64_)
    size_t len;
#else
    int len;
#endif

    try {
	for (buffer = skipWhitespaceAndComments(buffer);
	     *buffer;
	     buffer = skipWhitespaceAndComments(nextLine)) {

	    char *start = buffer;
	    nextLine = terminateLine(buffer);

	    // XXX - Should handle backslash escapes in the key
	    buffer = findSeparator(start);
	    if (start == buffer) {
		break;
	    }

	    std::string key(start, buffer - start);

	    buffer = skipWhitespace(buffer);
	    if (*buffer && isSeparator(*buffer)) {
		buffer += 1;
		buffer = skipWhitespace(buffer);
	    }

	    len = strlen(buffer) -1;
	    while ((len > 0) && (buffer[len] == ' ')) {
		buffer[len--] = '\0';
	    }
            
            // XXX - Should handle backslash escapes in the value
            set(key, buffer);
	}
	if (*buffer) {
	    status = AM_FAILURE;
	}
    } catch (const std::bad_alloc&) {
	status = AM_NO_MEMORY;
    }

    return status;
}
Example #5
0
bool LLMimeParser::Impl::parseIndex(
	std::istream& istr,
	S32 limit,
	const std::string& separator,
	bool is_subpart,
	LLMimeIndex& index)
{
	LLSD headers;
	bool parsed_something = false;
	if(parseHeaders(istr, limit, headers))
	{
		parsed_something = true;
		LLMimeIndex mime(headers, mScanCount);
		index = mime;
		if(index.isMultipart())
		{
			// Figure out the separator, scan past it, and recurse.
			std::string ct = headers[CONTENT_TYPE].asString();
			std::string sep = findSeparator(ct);
			scanPastSeparator(istr, limit, sep);
			while(continueParse() && parseIndex(istr, limit, sep, true, mime))
			{
				index.attachSubPart(mime);
			}
		}
		else
		{
			// Scan to the end of content.
			scanPastContent(istr, limit, headers, separator);
			if(is_subpart)
			{
				scanPastSeparator(istr, limit, separator);
			}
		}
	}
	if(mError) return false;
	return parsed_something;
}
void HTTPMessage::parse(
    String& startLine,
    Array<HTTPHeader>& headers,
    Uint32& contentLength) const
{
    startLine.clear();
    headers.clear();
    contentLength = 0;

    char* data = (char*)message.getData();
    Uint32 size = message.size();
    char* line = data;
    char* sep;
    Boolean firstTime = true;

    while ((sep = findSeparator(line, (Uint32)(size - (line - data)))))
    {
        // Look for double separator which terminates the header?

        if (line == sep)
        {
            // Establish pointer to content (account for "\n" and "\r\n").

            char* content = line + ((*sep == '\r') ? 2 : 1);

            // Determine length of content:

            contentLength = (Uint32)(message.size() - (content - data));
            break;
        }

        Uint32 lineLength = (Uint32)(sep - line);

        if (firstTime)
            startLine.assign(line, lineLength);
        else
        {
            // Find the colon:

            char* colon = 0;

            for (Uint32 i = 0; i < lineLength; i++)
            {
                if (line[i] == ':')
                {
                    colon = &line[i];
                    break;
                }
            }

            // This should always be true:

            if (colon)
            {
                // Get the name part:

                char* end;

                for (end = colon - 1; end > line && isspace(*end); end--)
                    ;

                end++;

                String name(line, (Uint32)(end - line));

                // Get the value part:

                char* start;

                for (start = colon + 1; start < sep && isspace(*start); start++)
                    ;

                String value(start, (Uint32)(sep - start));

                // From the HTTP/1.1 specification (RFC 2616) section 4.2
                // Message Headers:
                //
                // Multiple message-header fields with the same field-name
                // MAY be present in a message if and only if the entire
                // field-value for that header field is defined as a
                // comma-separated list [i.e., #(values)]. It MUST be
                // possible to combine the multiple header fields into one
                // "field-name: field-value" pair, without changing the
                // semantics of the message, by appending each subsequent
                // field-value to the first, each separated by a comma.  The
                // order in which header fields with the same field-name are
                // received is therefore significant to the interpretation
                // of the combined field value, and thus a proxy MUST NOT
                // change the order of these field values when a message is
                // forwarded.

                // This implementation concatenates duplicate header values,
                // with a comma separator.  If the resulting value is invalid,
                // that should be detected when the value is used.

                Uint32 headerIndex = 0;
                for (; headerIndex < headers.size(); headerIndex++)
                {
                    if (headers[headerIndex].first == name)
                    {
                        break;
                    }
                }

                if (headerIndex == headers.size())
                {
                    headers.append(HTTPHeader(name, value));
                }
                else
                {
                    headers[headerIndex].second.append(", ").append(value);
                }
            }
        }

        line = sep + ((*sep == '\r') ? 2 : 1);
        firstTime = false;
    }
}