コード例 #1
0
bool InjectedBundle::booleanForKey(WKDictionaryRef dictionary, const char* key)
{
    WKRetainPtr<WKStringRef> wkKey(AdoptWK, WKStringCreateWithUTF8CString(key));
    WKTypeRef value = WKDictionaryGetItemForKey(dictionary, wkKey.get());
    if (WKGetTypeID(value) != WKBooleanGetTypeID()) {
        stringBuilder()->appendLiteral("Boolean value for key \"");
        stringBuilder()->append(key);
        stringBuilder()->appendLiteral("\" not found in dictionary\n");
        return false;
    }
    return WKBooleanGetValue(static_cast<WKBooleanRef>(value));
}
コード例 #2
0
ファイル: server_protocol.c プロジェクト: gitkaste/sysprak11
int statusAction(struct actionParameters *ap,
		union additionalActionParameters *aap) {
  (void) aap;
	char *msg;
	msg = stringBuilder("WTF %s\n", ap->comword.buf);
	reply(ap->comfd, ap->logfd, ap->semid, REP_WARN, msg);
	free(msg);
	return 1;
}
コード例 #3
0
ファイル: server_protocol.c プロジェクト: gitkaste/sysprak11
int browseAction(struct actionParameters *ap, 
		union additionalActionParameters *aap) {
  (void) aap;
	unsigned long i =0;
	struct flEntry *f; 

	logmsg(ap->semid, ap->logfd, LOGLEVEL_DEBUG, 
			"(browseAction) invoked with %s\n", ap->comline.buf);
	reply(ap->comfd, ap->logfd, ap->semid, REP_TEXT, "share");
	while ((f = iterateArray(aap->cap->results, &i) )){
		char *msg = stringBuilder("%d: %d \t - %s\n",i,  f->size, f->filename);
		reply(ap->comfd, ap->logfd, ap->semid, REP_TEXT, msg);
		free(msg);
	}
	return 1;
}
コード例 #4
0
ファイル: server_protocol.c プロジェクト: gitkaste/sysprak11
int unknownCommandAction(struct actionParameters *ap,
		union additionalActionParameters *aap) {
  (void) aap;
	char *msg;
	int ret = 1;
	if (strcasecmp((char *)ap->comline.buf, "")){
		msg = stringBuilder("(server) Command \"%s\" not understood.\n",
			ap->comline.buf);
		logmsg(ap->semid, ap->logfd, LOGLEVEL_WARN, 
			"f**k unknown command \"%s\"", ap->comword.buf);
		ret =  reply(ap->comfd, ap->logfd, ap->semid, REP_WARN, msg);
		free(msg);
		return ret;
	}
	return 1;
}
コード例 #5
0
ファイル: server_protocol.c プロジェクト: gitkaste/sysprak11
int helpAction(struct actionParameters *ap,
		union additionalActionParameters *aap) {
  (void) aap;
	char * msg;
	struct protocol * p = ap->prot;
	for (int i =0; i < p->actionCount; i++){
		msg = stringBuilder("server: %s %s\n", p->actions[i].actionName, 
				p->actions[i].description);
		if ( -1 == reply(ap->comfd, ap->logfd, ap->semid, REP_TEXT,msg)){
			free(msg);
		  return -1;
		}
		free(msg);
	}
	return 1;
}
コード例 #6
0
ファイル: server_protocol.c プロジェクト: gitkaste/sysprak11
int searchAction(struct actionParameters *ap,
		union additionalActionParameters *aap) {
	uint16_t port = 0;
	pid_t pid;
	int sockfd = 0;

  (void) aap;
	if (iswhitespace((char *)ap->comline.buf)) return 1;
	switch (pid = fork()) {

		case -1:
			logmsg(ap->semid, ap->logfd, LOGLEVEL_FATAL, 
					"(searchAction) Problem forking\n");
			return -3;

		case 0:
			sockfd = createPassiveSocket(&port);
			if (sockfd<=0) return -3;
			if ( -1 == getTokenFromBuffer(&ap->comline, &ap->comword, "\n","\r\n",NULL))
				return -3;
			logmsg(ap->semid, ap->logfd, LOGLEVEL_VERBOSE, 
					"(searchAction) called upon to search for %s\n", ap->comword.buf);
			logmsg(ap->semid, ap->logfd, LOGLEVEL_VERBOSE, 
					"created port %d to send search results\n", port);
			char *msg = stringBuilder("RESULT SOCKET %d\n", port);
			if ( -1 == reply(ap->comfd, ap->logfd, ap->semid, REP_COMMAND, msg)){
				free(msg);
				return -3;
			}
			free(msg);

			setFdBlocking(sockfd);
			socklen_t addrlen = sizeof(ap->comip);
			if ((ap->comfd = accept(sockfd, &ap->comip, &addrlen)) == -1 ) {
				logmsg(ap->semid, ap->logfd, LOGLEVEL_FATAL, 
						"(searchAction) Problem accepting connection\n");
				return -3;
			}
			int ret = (sendResult(ap->comfd, ap, aap->sap));
			close (ap->comfd);
			return (ret == -1)? -3: -2;

		default:
			return 1;
	}
}
コード例 #7
0
ファイル: saxhandler.cpp プロジェクト: wolski/bibliospec2.0
bool SAXHandler::parse()
{
    FILE* pfIn = fopen(m_strFileName_.data(), "r");
    if (pfIn == NULL) {
        throw BlibException(true, "Failed to open input file '%s'.",
                            m_strFileName_.c_str());
    }

    bool success = true;
    string message;

    try {
        // HACK!! I have no idea why this is, but without this string
        // declaration, the MSVC optimizer removes the catch block below.
        // Very mysterious.
        string temp;

        char buffer[8192];
        int readBytes = 0;

        while (success && (readBytes = (int) fread(buffer, 1, sizeof(buffer), pfIn)) != 0) {
            success = (XML_Parse(m_parser_, buffer, readBytes, false) != 0);
        }
        success = success && (XML_Parse(m_parser_, buffer, 0, true) != 0);
    }
    catch(string thrown_msg) { // from parsers
        message = thrown_msg;
        success = false;
    }
    catch(BlibException e) { // probably from BuildParser
        if( e.hasFilename() ) {
            throw e;
        } else {
            message = e.what();
            success = false;
        }
    }
    catch(std::exception e) {  // other runtime errors (e.g. memory)
        message = e.what();
        success = false;
    }

    fclose(pfIn);

    if (!success) {
        XML_Error error = XML_GetErrorCode(m_parser_);
        int lineNum = XML_GetCurrentLineNumber(m_parser_);
        ostringstream stringBuilder(ostringstream::out);

        stringBuilder << m_strFileName_
                      << "(line " << lineNum
                      << "): " << message << flush;

        if (message.length() == 0) {
            switch (error) {
            case XML_ERROR_SYNTAX:
                stringBuilder << "Syntax error parsing XML.";
                break;
            case XML_ERROR_INVALID_TOKEN:
                stringBuilder << "Invalid token error parsing XML.";
                break;
            case XML_ERROR_UNCLOSED_TOKEN:
                stringBuilder << "Unclosed token error parsing XML.";
                break;
            case XML_ERROR_NO_ELEMENTS:
                stringBuilder << "No elements error parsing XML.";
                break;
            case XML_ERROR_TAG_MISMATCH:
                stringBuilder << "Tag mismatch error parsing XML.";
                break;
            case XML_ERROR_DUPLICATE_ATTRIBUTE:
                stringBuilder << "Duplicate attribute error parsing XML.";
                break;
            case XML_ERROR_UNKNOWN_ENCODING:
            case XML_ERROR_INCORRECT_ENCODING:
                stringBuilder << "Unknown or incorrect encoding XML error.";
                break;
            case XML_ERROR_UNCLOSED_CDATA_SECTION:
                stringBuilder << "Unclosed data section error parsing XML.";
                break;

            default:
                stringBuilder << "XML parsing error.";
                break;
            }
        }

        string er_msg = stringBuilder.str();
        throw BlibException(true, er_msg.c_str());
    }

    return true;
}
コード例 #8
0
ファイル: AcceptStringImpls.hpp プロジェクト: anibalanto/hyp
 void operator()(Slice const& word) const { stringBuilder(word); }
コード例 #9
0
ファイル: AcceptStringImpls.hpp プロジェクト: anibalanto/hyp
 void operator()(std::string const& str) const { stringBuilder(str); }