Beispiel #1
0
void stream(T4C* t4c, sds url, Parameters* paramsArgument, size_t (*callback)(void*, size_t, size_t, void*)) {
  Parameters* oauthParams = new_parameters();
  genOAuthParams(t4c, oauthParams);
  Parameters* params = new_parameters();
  buildParams(params, oauthParams, paramsArgument);

  sds oauthSignature   = signature(t4c->consumerSecret, t4c->accessTokenSecret, GET, url, params);
  sds encodedSignature = url_encode(oauthSignature);

  add_parameter(oauthParams, sdsnew("oauth_signature"), encodedSignature);
  add_parameter(params,      sdsnew("oauth_signature"), encodedSignature);

  sds authorizeChild = join_parameters(oauthParams, ",");
  sds authorize      = sdscatprintf(sdsempty(), "Authorization: OAuth %s", authorizeChild);

  sds path = join_parameters(params, "&");

  if (DEBUG) {
    printf("----------------------------\n");
    printf("STREAMING API");
    printf("URL: %s\n", url);
    printf("path: %s\n", path);
    printf("authorize: %s\n", authorize);
    printf("----------------------------\n");
  }

  CURL* curl;
  curl = curl_easy_init();

  sds reqURL = sdscatprintf(sdsempty(), "%s?%s", url, path);

  curl_easy_setopt(curl, CURLOPT_URL, reqURL);

  struct curl_slist *headers = NULL;
  headers = curl_slist_append(headers, authorize);

  curl_easy_setopt(curl, CURLOPT_HEADER, headers);
  curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
  curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, callback);
  curl_easy_setopt(curl, CURLOPT_TIMEOUT, 0);

  curl_easy_perform(curl);
  curl_easy_cleanup(curl);

  sdsfree(oauthSignature);
  sdsfree(encodedSignature);
  sdsfree(reqURL);
  sdsfree(url);
  sdsfree(path);
  sdsfree(authorize);
  sdsfree(authorizeChild);

  free_parameters(oauthParams);
}
void ServerDefinitionDialog::testConnection()
{
	buildParams( m_params );
	QString	error;
	if ( ! m_params.check( error ))	{
		QMessageBox::critical( this, tr( "Parameters error"), error );
		return;
	}
		QMessageBox::information( this, tr( "Test Connection" ),
					  tr( "This function is not implemented yet" ));
}
void ServerDefinitionDialog::done( int retCode )
{
	if ( retCode == QDialog::Accepted )	{
		buildParams( m_params );
		QString	error;
		if ( ! m_params.check( error ))
			QMessageBox::critical( this, tr( "Parameters error"), error );
		else
			QDialog::done( retCode );
	}
	else
		QDialog::done( retCode );
}
//--------------------------------------------------------------------------------------------------
void ApplicationBuilder_t::Build
(
    legato::App& app,
    std::string outputDirPath   ///< Directory into which the generated app bundle should be put.
)
//--------------------------------------------------------------------------------------------------
{
    CheckForLimitsConflicts(app);

    // Construct the working directory structure, which consists of an "work" directory and
    // a "staging" directory.  Inside the "staging" directory, there is "lib", "bin", and any
    // other directories required to hold files bundled by the application or one of its components.
    // The "work" directory is for intermediate build output, like generated .c files and .o files.
    // The "staging" directory will get tar-compressed to become the actual application file.

    if (m_Params.IsVerbose())
    {
        std::cout << "Creating working directories under '" << m_Params.ObjOutputDir() << "'."
                  << std::endl;
    }

    legato::BuildParams_t buildParams(m_Params);

    const std::string& stagingDirPath = m_Params.StagingDir();
    buildParams.LibOutputDir(stagingDirPath + "/lib");
    buildParams.ExeOutputDir(stagingDirPath + "/bin");
    buildParams.ObjOutputDir(m_Params.ObjOutputDir() + "/work");

    // Clean the staging area.
    legato::CleanDir(stagingDirPath);

    // Create directories.
    legato::MakeDir(buildParams.ObjOutputDir());
    legato::MakeDir(buildParams.LibOutputDir());
    legato::MakeDir(buildParams.ExeOutputDir());

    // Build all the components in the application, each with its own working directory
    // to avoid file name conflicts between .o files in different components, and copy all
    // generated and bundled files into the application staging area.
    // NOTE: Components have to be built before any other components that depend on them.
    //       They also need to be bundled into the app in the same order, so that higher-layer
    //       components can override files bundled by lower-layer components.
    ComponentBuilder_t componentBuilder(buildParams);
    auto& map = app.ComponentMap();
    for (auto& mapEntry : map)
    {
        auto& componentPtr = mapEntry.second;

        BuildAndBundleComponent(*componentPtr, componentBuilder, buildParams.ObjOutputDir());
    }

    // Build all the executables and their IPC libs.
    BuildExecutables(app, buildParams);

    // Copy in any bundled files and directories from the "bundles:" section of the .adef.
    // Note: do the directories first, in case the files list adds files to those directories.
    for (auto& fileMapping : app.BundledDirs())
    {
        mk::CopyToStaging(  fileMapping.m_SourcePath,
                            stagingDirPath,
                            fileMapping.m_DestPath,
                            m_Params.IsVerbose()    );
    }
    for (auto& fileMapping : app.BundledFiles())
    {
        mk::CopyToStaging(  fileMapping.m_SourcePath,
                            stagingDirPath,
                            fileMapping.m_DestPath,
                            m_Params.IsVerbose()    );
    }

    // Generate the app-specific configuration data that tells the framework what limits to place
    // on the app when it is run, etc.
    GenerateSystemConfig(stagingDirPath, app, m_Params);

    // TODO: Generate the application's configuration tree (containing all its pool sizes,
    //       and anything else listed under the "config:" section of the .adef.)

    // TODO: Copy in the metadata (.adef and Component.cdef) files so they can be retrieved
    //       by Developer Studio.

    // Zip it all up.
    std::string outputPath = legato::CombinePath(   outputDirPath,
                                                    app.Name() + "." + buildParams.Target() );
    if (!legato::IsAbsolutePath(outputPath))
    {
        outputPath = legato::GetWorkingDir() + "/" + outputPath;
    }
    std::string tarCommandLine = "tar cjf \"" + outputPath + "\" -C \"" + stagingDirPath + "\" .";
    if (m_Params.IsVerbose())
    {
        std::cout << "Packaging application into '" << outputPath << "'." << std::endl;
        std::cout << std::endl << "$ " << tarCommandLine << std::endl << std::endl;
    }

    mk::ExecuteCommandLine(tarCommandLine);
}
Beispiel #5
0
sds request(T4C* t4c, METHOD method, sds endPoint, Parameters* paramsArgument) {
  sds result;

  Parameters* oauthParams = new_parameters();
  genOAuthParams(t4c, oauthParams);
  Parameters* params = new_parameters();
  buildParams(params, oauthParams, paramsArgument);

  sds url = sdscatprintf(sdsempty(), "%s%s", baseUrl, endPoint);
  sds oauthSignature   = signature(t4c->consumerSecret, t4c->accessTokenSecret, method, url, params);
  sds encodedSignature = url_encode(oauthSignature);

  add_parameter(oauthParams, sdsnew("oauth_signature"), encodedSignature);
  add_parameter(params,     sdsnew("oauth_signature"),  encodedSignature);

  sds authorizeChild = join_parameters(oauthParams, ",");
  sds authorize      = sdscatprintf(sdsempty(), "Authorization: OAuth %s", authorizeChild);

  sds path = join_parameters(params, "&");

  if (DEBUG) {
    printf("----------------------------\n");
    printf("URL: %s\n", url);
    printf("endPoint: %s\n", endPoint);
    printf("path: %s\n", path);
    printf("authorize: %s\n", authorize);
    printf("----------------------------\n");
  }

  CURL* curl;
  curl = curl_easy_init();

  sds reqURL;

  if (method == GET) {
    reqURL = sdscatprintf(sdsempty(), "%s?%s", url, path);
    curl_easy_setopt(curl, CURLOPT_URL, reqURL);
  } else if (method == POST) {
    curl_easy_setopt(curl, CURLOPT_POST, 1);
    curl_easy_setopt(curl, CURLOPT_POSTFIELDS, path);
    curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, sdslen(path));
    curl_easy_setopt(curl, CURLOPT_URL, url);
  }

  struct curl_slist *headers = NULL;
  headers = curl_slist_append(headers, authorize);

  curl_easy_setopt(curl, CURLOPT_HEADER, headers);
  curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curl_result_stringlize_callback);
  curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)&result);

  curl_easy_perform(curl);
  curl_easy_cleanup(curl);

  sdsfree(oauthSignature);
  sdsfree(encodedSignature);
  sdsfree(reqURL);
  sdsfree(url);
  sdsfree(path);
  sdsfree(authorize);
  sdsfree(authorizeChild);
  free_parameters(oauthParams);

  return result;
}