Exemplo n.º 1
0
void Application::OnContextInitialized() {
    CefRefPtr<WindowClient> client(new WindowClient());

    CefWindowInfo info;
    //info.windowless_rendering_enabled = true;

    CefBrowserSettings settings;
    settings.web_security = STATE_DISABLED;

    CefCommandLine::ArgumentList arguments;
    CefCommandLine::GetGlobalCommandLine()->GetArguments(arguments);

    std::ostringstream content;
    content << "data:text/html,<!DOCTYPE html><html><head><title>Leprechauns are oh so magically delicious</title></head><body>\n";
    content << "<script>leprechaun.args = [";
    for (unsigned int i = 0; i < arguments.size(); ++i) {
        content << ((i > 0) ? "," : "") << '\"' << escapeQuotes(arguments[i]) << '\"';
    }
    content << "];</script>\n";
    content << "<script src=\"" << escapeQuotes(arguments[0]) << "\"></script>\n";
    content << "</body><html>";


    // The script to be run is read from disk and executed in the browser frame in bootstrap() above.
    CefBrowserHost::CreateBrowser(
        info,
        client.get(),
        content.str(),
        settings,
        NULL
    );
}
Exemplo n.º 2
0
//-----------------------------------------------------------------------------
QString KPIM::quoteNameIfNecessary( const QString &str )
{
  QString quoted = str;

  QRegExp needQuotes(  "[^ 0-9A-Za-z\\x0080-\\xFFFF]" );
  // avoid double quoting
  if ( ( quoted[0] == '"' ) && ( quoted[quoted.length() - 1] == '"' ) ) {
    quoted = "\"" + escapeQuotes( quoted.mid( 1, quoted.length() - 2 ) ) + "\"";
  }
  else if ( quoted.find( needQuotes ) != -1 ) {
    quoted = "\"" + escapeQuotes( quoted ) + "\"";
  }

  return quoted;
}
Exemplo n.º 3
0
char* AWSClient::headersToCurlRequest() {
    /* Add backslashes before quotes in json string */
    char* escapedPayload = escapeQuotes(payload.getCStr());

    /* Determine whether to use https or http curlEnd values. */
    int curlEndLen = httpS ? HTTPS_CURL_END_LEN : HTTP_CURL_END_LEN;
    const char* curlEnd = httpS ? HTTPS_CURL_END : HTTP_CURL_END;

    /* Calculate length of curl command. +6 for "-d", 2 spaces, 2 quotes. */
    int httpRequestLen = CURL_START_LEN + curlEndLen + strlen(awsService)
            + strlen(awsRegion) + strlen(awsEndpoint) + strlen(escapedPayload)
            + 6;
    for (int i = 0; i < headersCreated; i++) {
        /* +6 for "-H", 2 spaces, 2 quotes */
        httpRequestLen += *(headerLens + i) + 6;
    }

    /* Create and write to the httpRequest string. */
    char* httpRequest = new char[httpRequestLen + 1]();
    int httpRequestWritten = 0;
    httpRequestWritten += strlen(strcpy(httpRequest, CURL_START));
    for (int i = 0; i < headersCreated; i++) {
        httpRequestWritten += sprintf(httpRequest + httpRequestWritten,
                "-H \"%s\" ", *(headers + i));
    }
    httpRequestWritten += sprintf(httpRequest + httpRequestWritten,
            "-d \"%s\" ", escapedPayload);
    delete[] escapedPayload;
    httpRequestWritten += sprintf(httpRequest + httpRequestWritten, curlEnd,
            awsService, awsRegion, awsEndpoint);

    return httpRequest;
}
Exemplo n.º 4
0
static UString valueToSourceString(ExecState* exec, JSValue* val) 
{
    if (val->isString()) {
        UString result("\"");
        result += escapeQuotes(val->toString(exec)) + "\"";
        return result;
    } 

    return val->toString(exec);
}
Exemplo n.º 5
0
void endElement(void *userData, const char *ename)
{
	if (!strcmp(ename, "node")) {
		struct tag *cur;
		int i;
		char *_id = escapeQuotes(id);
		char *_version = escapeQuotes(version);
		char *_timestamp = escapeQuotes(timestamp);
		char *_lat = escapeQuotes(lat);
		char *_lon = escapeQuotes(lon);

		if (isPOI()) {

			fprintf(stdout, "INSERT IGNORE INTO node (id, version, timestamp, lat, lon) VALUES ('%s', '%s', '%s', '%s', '%s');\n", _id, _version, _timestamp, _lat, _lon);
			for (cur = tag_list; cur; cur = cur->next) {
				char *_k = escapeQuotes(cur->key);
				char *_v = escapeQuotes(cur->value);
				fprintf(stdout, "INSERT IGNORE INTO tag (node_id, k, v) VALUES ('%s', '%s', '%s');\n", _id, _k, _v);
				FREE(_k);
				FREE(_v);
			}
			fflush(stdout);

		}

		parsing_node = 0;

		FREE(id);
		FREE(version);
		FREE(timestamp);
		FREE(lat);
		FREE(lon);

		FREE(_id);
		FREE(_version);
		FREE(_timestamp);
		FREE(_lat);
		FREE(_lon);

		if (tag_list) {
			tag *cur;
			tag *old;

			cur = tag_list;

			while (cur) {
				FREE(cur->key);
				FREE(cur->value);

				old = cur;
				cur = cur->next;
				free(old);
			}

			tag_list = NULL;
		}
	}
}
Exemplo n.º 6
0
void chooseFileNative( char *title, char *path, int openingFile, char *okMsg, char *cancelMsg ) {
	char szFileName[MAX_PATH] = "";
	ZFileSpec fs( path );
	if( !openingFile ) {
		strcpy( szFileName, fs.getFile() );
	}

	// Windows changes the working folder when you choose a file to open or 
	// save.  This makes using relative paths in our apps a pain, so I'm going
	// to save the cwd and restore it to defeat this behavior.
	char cwd[1024];
	getcwd( cwd, 1024 );
	extern void trace( char *msg, ... );

	OPENFILENAME ofn;
	ZeroMemory(&ofn, sizeof(ofn));
	ofn.lStructSize = sizeof(ofn);
	ofn.hwndOwner = (HWND)glfwZBSExt_GetHWND();
	ofn.lpstrFilter = getWindowsFilterStringFromPath( path );
	ofn.lpstrFile = szFileName;
	ofn.lpstrTitle = title;

	// Windows will ignore out initDir request unless we use backslashes, and
	// ensure there is no trailing slash...
	extern char * convertSlashes( char *, char c=0 );
	extern char * stripTrailingSlashes( char * );
		// these are in ZFileSPec, and were static, but I changed that use use it here. (tfb)
	ofn.lpstrInitialDir = stripTrailingSlashes( convertSlashes( fs.getDir(), '\\' ) );
	ofn.nMaxFile = MAX_PATH;
	ofn.Flags = OFN_EXPLORER | OFN_HIDEREADONLY;
	if( openingFile ) {
		ofn.Flags = ofn.Flags | OFN_FILEMUSTEXIST;
	}
	ofn.lpstrDefExt = fs.getExt();

	int status = 0;
	if( openingFile ) {
		status = GetOpenFileName( &ofn );
	}
	else {
		status = GetSaveFileName( &ofn );
	}
	if( status ) {
		if( okMsg ) {
			zMsgQueue( "%s filespec='%s'", okMsg, escapeQuotes( convertSlashes( szFileName, '/' ) ) );
		}
	}
	else if( cancelMsg ) {
		zMsgQueue( cancelMsg );
	}

	zFileSpecChdir( cwd );
	getcwd( cwd, 1024 );
}
Exemplo n.º 7
0
 std::string jsonValue() const
 {
     std::string val;
     if (m_impl->m_type == "string" || m_impl->m_type == "base64Binary" ||
         m_impl->m_type == "uuid")
     {
         std::string val("\"");
         val += escapeQuotes(value()) + "\"";
         return val;
     }
     return value();
 }
Exemplo n.º 8
0
void CsvFile::writeToString(std::string& str) const
{
    for (const Row& r: rows)
    {
        for (size_t i = 0; i < r.size(); ++i)
        {
            str += escapeQuotes(r[i]);
            if (i < r.size() - 1)
                str += ',';
        }
        str += '\n';
    }
}
Exemplo n.º 9
0
void GetSaveFileFromUser( char *title, char *path, char *okMsg, char *cancelMsg ) {
	// Allow the user to specify a name to save a file - the file need not already
	// exist.
	
	NavDialogCreationOptions dialogOptions;
	NavDialogRef dialog;
	NavReplyRecord replyRecord;
	CFURLRef fileAsCFURLRef = NULL;
	FSRef fileAsFSRef;
	OSStatus status;
	UInt8 output_dir_name[1024];
	UniChar output_filename[255];
	CFIndex len = 255;
	int i,pathlen;
	
	ZFileSpec fs( path );
	//char *debug = fs.getFile();

	
	// Get the standard set of defaults
	status = NavGetDefaultDialogCreationOptions(&dialogOptions);
	require_noerr( status, CantGetNavOptions );
	
	// Make the window app-wide modal
	dialogOptions.modality = kWindowModalityAppModal;
	
	dialogOptions.windowTitle = CFStringCreateWithCString( NULL, title, 0 );
	dialogOptions.saveFileName = CFStringCreateWithCString( NULL, fs.getFile(), 0 ); 
	//dialogOptions.optionFlags |= kNavPreserveSaveFileExtension;
	dialogOptions.optionFlags |= kNavNoTypePopup;
	
	// Create the dialog
	status = NavCreatePutFileDialog(&dialogOptions, NULL, NULL, NULL, NULL, &dialog);
	require_noerr( status, CantCreateDialog );
	
	// Show it
	status = NavDialogRun(dialog);
	require_noerr( status, CantRunDialog );
	
	// Get the reply
	status = NavDialogGetReply(dialog, &replyRecord);
	require( ((status == noErr) || (status == userCanceledErr)), CantGetReply );
	
	// If the user clicked "Cancel", just bail
	if ( status == userCanceledErr ) {
		if( cancelMsg ) {
			zMsgQueue( cancelMsg );
			NavDialogDispose( dialog );
			return;
		}
	}
	
	// Get the file
	status = AEGetNthPtr(&(replyRecord.selection), 1, typeFSRef, NULL, NULL, &fileAsFSRef, sizeof(FSRef), NULL);
	require_noerr( status, CantExtractFSRef );
	
	// Get folder name
	FSRefMakePath( &fileAsFSRef, output_dir_name, 1024 );
	pathlen = strlen( (const char *)output_dir_name );
	output_dir_name[ pathlen++ ] = '/';
	
	
	// Get filename
	len = CFStringGetLength( replyRecord.saveFileName);
	for( i=0; i<len && pathlen < 1023; i++ ) {
		output_dir_name[ pathlen++ ] = CFStringGetCharacterAtIndex( replyRecord.saveFileName, i );
	}
	output_dir_name[ pathlen ] = 0;
	if( okMsg ) {
		zMsgQueue( "%s overwriteExisting=1 osx=1 filespec='%s'", okMsg, escapeQuotes( (char*)output_dir_name ) );
			// on OSX, the confirm to overwrite existing files happens as part of the native dialog 
	}
	
	
	// Cleanup
CantExtractFSRef:
	verify_noerr( NavDisposeReply(&replyRecord) );
CantGetReply:
CantRunDialog:
	NavDialogDispose(dialog);
CantCreateDialog:
CantGetNavOptions:
	return;
}
Exemplo n.º 10
0
void GetOpenFileFromUser( char *title, char *path, char *okMsg, char *cancelMsg ) {
	// Allow the user to choose an existing file
	
	NavDialogCreationOptions dialogOptions;
	NavDialogRef dialog;
	NavReplyRecord replyRecord;
	CFURLRef fileAsCFURLRef = NULL;
	FSRef fileAsFSRef;
	OSStatus status;
	UInt8 output_dir_name[1024];
	
	ZFileSpec fs( path );
	
	
	// Get the standard set of defaults
	status = NavGetDefaultDialogCreationOptions(&dialogOptions);
	require_noerr( status, CantGetNavOptions );
	
	// Make the window app-wide modal
	dialogOptions.modality = kWindowModalityAppModal;

	dialogOptions.windowTitle = CFStringCreateWithCString( NULL, title, 0 );
	dialogOptions.saveFileName = CFStringCreateWithCString( NULL, fs.getFile(), 0 ); 
	
	// Create the dialog
	status = NavCreateGetFileDialog(&dialogOptions, NULL, NULL, NULL, NULL, NULL, &dialog);
	require_noerr( status, CantCreateDialog );
	
	// Show it
	status = NavDialogRun(dialog);
	require_noerr( status, CantRunDialog );
	
	// Get the reply
	status = NavDialogGetReply(dialog, &replyRecord);
	require( ((status == noErr) || (status == userCanceledErr)), CantGetReply );
	
	// If the user clicked "Cancel", just bail
	if ( status == userCanceledErr ) {
		if( cancelMsg ) {
			zMsgQueue( cancelMsg );
			NavDialogDispose( dialog );
			return;
		}
	}
	
	// Get the file
	status = AEGetNthPtr(&(replyRecord.selection), 1, typeFSRef, NULL, NULL, &fileAsFSRef, sizeof(FSRef), NULL);
	require_noerr( status, CantExtractFSRef );
	
	FSRefMakePath( &fileAsFSRef, output_dir_name, 1024 );
	if( okMsg ) {
		zMsgQueue( "%s osx=1 filespec='%s'", okMsg, escapeQuotes( (char*)output_dir_name ) );
	}
	
	// Cleanup
CantExtractFSRef:
UserCanceled:
	verify_noerr( NavDisposeReply(&replyRecord) );
CantGetReply:
CantRunDialog:
	NavDialogDispose(dialog);
CantCreateDialog:
CantGetNavOptions:
	return;
}