コード例 #1
0
    std::shared_ptr<odata_entity_value> odata_test_service::get_single_people(::odata::utility::string_t name)
    {
        if (name != U("russellwhyte"))
        {
            return std::shared_ptr<odata_entity_value>();
        }
        auto people_type = m_model->find_entity_type(U("Person"));
        
        auto people1 = std::make_shared<odata_entity_value>(people_type);
        people1->set_value(U("UserName"), U("russellwhyte"));
        people1->set_value(U("FirstName"), U("Russell"));
        people1->set_value(U("LastName"),U("Whyte"));

        auto string_collection_type = std::make_shared<edm_collection_type>(::odata::edm::edm_primitive_type::STRING());
        auto emails_value = std::make_shared<odata_collection_value>(string_collection_type);

        emails_value->add_collection_value(std::make_shared<odata_primitive_value>(::odata::edm::edm_primitive_type::STRING(), U("*****@*****.**")));
        emails_value->add_collection_value(std::make_shared<odata_primitive_value>(::odata::edm::edm_primitive_type::STRING(), U("*****@*****.**")));
        people1->set_value(U("Emails"),emails_value);

        auto location_type = m_model->find_complex_type(U("Location"));
        auto location_collection_type = std::make_shared<edm_collection_type>( location_type);
        auto location_collection = std::make_shared<odata_collection_value>(location_collection_type);
        auto location1 = std::make_shared<odata_complex_value>(location_type);
        location1->set_value(U("Address"), U("187 Suffolk Ln."));

        auto city_type = m_model->find_complex_type(U("City"));
        auto city1 = std::make_shared<odata_complex_value>(city_type);
        city1->set_value(U("CountryRegion"), U("United States"));
        city1->set_value(U("Name"), U("Boise"));
        city1->set_value(U("Region"), U("ID"));
        location1->set_value(U("City"), city1);
        location_collection->add_collection_value(location1);
        people1->set_value(U("AddressInfo"), location_collection);

        auto gender_type = m_model->find_enum_type(U("PersonGender"));
        auto gender = std::make_shared<odata_enum_value>(gender_type, U("Male"));
        people1->set_value(U("Gender"),gender);
        people1->set_value(U("Concurrency"),635435960069149000L);

        people1->set_etag(U("test etag"));


        return people1;
    }
コード例 #2
0
ファイル: download.c プロジェクト: AurelienTT/viking
static DownloadResult_t download( const char *hostname, const char *uri, const char *fn, DownloadFileOptions *options, gboolean ftp, void *handle)
{
  FILE *f;
  int ret;
  gchar *tmpfilename;
  gboolean failure = FALSE;
  CurlDownloadOptions cdo = {0, NULL, NULL};

  /* Check file */
  if ( g_file_test ( fn, G_FILE_TEST_EXISTS ) == TRUE )
  {
    if (options == NULL || (!options->check_file_server_time &&
                            !options->use_etag)) {
      /* Nothing to do as file already exists and we don't want to check server */
      return DOWNLOAD_NOT_REQUIRED;
    }

    time_t tile_age = a_preferences_get(VIKING_PREFERENCES_NAMESPACE "download_tile_age")->u;
    /* Get the modified time of this file */
    GStatBuf buf;
    (void)g_stat ( fn, &buf );
    time_t file_time = buf.st_mtime;
    if ( (time(NULL) - file_time) < tile_age ) {
      /* File cache is too recent, so return */
      return DOWNLOAD_NOT_REQUIRED;
    }

    if (options != NULL && options->check_file_server_time) {
      cdo.time_condition = file_time;
    }
    if (options != NULL && options->use_etag) {
      get_etag(fn, &cdo);
    }

  } else {
    gchar *dir = g_path_get_dirname ( fn );
    if ( g_mkdir_with_parents ( dir , 0777 ) != 0)
      g_warning ("%s: Failed to mkdir %s", __FUNCTION__, dir );
    g_free ( dir );
  }

  tmpfilename = g_strdup_printf("%s.tmp", fn);
  if (!lock_file ( tmpfilename ) )
  {
    g_debug("%s: Couldn't take lock on temporary file \"%s\"\n", __FUNCTION__, tmpfilename);
    g_free ( tmpfilename );
    if (options->use_etag)
      g_free ( cdo.etag );
    return DOWNLOAD_FILE_WRITE_ERROR;
  }
  f = g_fopen ( tmpfilename, "w+b" );  /* truncate file and open it */
  if ( ! f ) {
    g_warning("Couldn't open temporary file \"%s\": %s", tmpfilename, g_strerror(errno));
    g_free ( tmpfilename );
    if (options->use_etag)
      g_free ( cdo.etag );
    return DOWNLOAD_FILE_WRITE_ERROR;
  }

  /* Call the backend function */
  ret = curl_download_get_url ( hostname, uri, f, options, ftp, &cdo, handle );

  DownloadResult_t result = DOWNLOAD_SUCCESS;

  if (ret != CURL_DOWNLOAD_NO_ERROR && ret != CURL_DOWNLOAD_NO_NEWER_FILE) {
    g_debug("%s: download failed: curl_download_get_url=%d", __FUNCTION__, ret);
    failure = TRUE;
    result = DOWNLOAD_HTTP_ERROR;
  }

  if (!failure && options != NULL && options->check_file != NULL && ! options->check_file(f)) {
    g_debug("%s: file content checking failed", __FUNCTION__);
    failure = TRUE;
    result = DOWNLOAD_CONTENT_ERROR;
  }

  fclose ( f );
  f = NULL;

  if (failure)
  {
    g_warning(_("Download error: %s"), fn);
    if ( g_remove ( tmpfilename ) != 0 )
      g_warning( ("Failed to remove: %s"), tmpfilename);
    unlock_file ( tmpfilename );
    g_free ( tmpfilename );
    if ( options != NULL && options->use_etag ) {
      g_free ( cdo.etag );
      g_free ( cdo.new_etag );
    }
    return result;
  }

  if (ret == CURL_DOWNLOAD_NO_NEWER_FILE)  {
    (void)g_remove ( tmpfilename );
     // update mtime of local copy
     // Not security critical, thus potential Time of Check Time of Use race condition is not bad
     // coverity[toctou]
     if ( g_utime ( fn, NULL ) != 0 )
       g_warning ( "%s couldn't set time on: %s", __FUNCTION__, fn );
  } else {
    if ( options != NULL && options->convert_file )
      options->convert_file ( tmpfilename );

    if ( options != NULL && options->use_etag ) {
      if ( cdo.new_etag ) {
        /* server returned an etag value */
        set_etag(fn, tmpfilename, &cdo);
      }
    }

     /* move completely-downloaded file to permanent location */
     if ( g_rename ( tmpfilename, fn ) )
        g_warning ("%s: file rename failed [%s] to [%s]", __FUNCTION__, tmpfilename, fn );
  }
  unlock_file ( tmpfilename );
  g_free ( tmpfilename );

  if ( options != NULL && options->use_etag ) {
    g_free ( cdo.etag );
    g_free ( cdo.new_etag );
  }
  return DOWNLOAD_SUCCESS;
}