int main(int argc, char *argv[]) { LOGINREC *login; DBPROCESS *dbproc; int ret_code; int num_cols; int num_res; set_malloc_options(); read_login_info(argc, argv); printf("Starting %s\n", argv[0]); dbinit(); dberrhandle(syb_err_handler); dbmsghandle(syb_msg_handler); printf("About to logon\n"); login = dblogin(); DBSETLPWD(login, PASSWORD); DBSETLUSER(login, USER); DBSETLAPP(login, "t0012"); dbproc = dbopen(login, SERVER); if (strlen(DATABASE)) { dbuse(dbproc, DATABASE); } dbloginfree(login); printf("After logon\n"); /* select */ sql_cmd(dbproc); dbsqlexec(dbproc); num_res = 0; while ((ret_code = dbresults(dbproc)) == SUCCEED) { num_cols = dbnumcols(dbproc); printf("Result %d has %d columns\n", num_res, num_cols); if (!(num_res % 2) && num_cols) set_failed(); while(dbnextrow(dbproc) != NO_MORE_ROWS) {}; num_res++; } if (ret_code == FAIL) set_failed(); dbclose(dbproc); dbexit(); printf("%s %s\n", __FILE__, (failed ? "failed!" : "OK")); return failed ? 1 : 0; }
int PPInstance::LoadPlugin( const std::string& dllFilename ) { if ( !m_pluginLoaded ) { ref_plugin(); m_pluginLoaded = true; } int error = 0; if (!is_plugin_loaded()) { std::string pathname = dllFilename; #ifdef P3D_PLUGIN_P3D_PLUGIN // This is a convenience macro for development. If defined and // nonempty, it indicates the name of the plugin DLL that we will // actually run, even after downloading a possibly different // (presumably older) version. Its purpose is to simplify iteration // on the plugin DLL. string override_filename = P3D_PLUGIN_P3D_PLUGIN; if (!override_filename.empty()) { pathname = override_filename; } #endif // P3D_PLUGIN_P3D_PLUGIN nout << "Attempting to load core API from " << pathname << "\n"; string contents_filename = m_rootDir + "/contents.xml"; if (!load_plugin(pathname, contents_filename, PANDA_PACKAGE_HOST_URL, P3D_VC_normal, "", "", "", false, false, m_rootDir, "", nout)) { nout << "Unable to launch core API in " << pathname << "\n"; error = 1; } else { // Format the coreapi_timestamp as a string, for passing as a // parameter. ostringstream stream; stream << _coreapi_dll.get_timestamp(); string coreapi_timestamp = stream.str(); #ifdef PANDA_OFFICIAL_VERSION static const bool official = true; #else static const bool official = false; #endif P3D_set_plugin_version_ptr(P3D_PLUGIN_MAJOR_VERSION, P3D_PLUGIN_MINOR_VERSION, P3D_PLUGIN_SEQUENCE_VERSION, official, PANDA_DISTRIBUTOR, PANDA_PACKAGE_HOST_URL, coreapi_timestamp.c_str(), _coreapi_set_ver.c_str()); } } if (error) { set_failed(); } return error ; }
static void * thread_test(void * arg) { int i; int num = ptr2int(arg); DBPROCESS *dbproc; LOGINREC *login; login = dblogin(); DBSETLPWD(login, PASSWORD); DBSETLUSER(login, USER); DBSETLAPP(login, "thread"); dbproc = dbopen(login, SERVER); if (!dbproc) { dbloginfree(login); fprintf(stderr, "Unable to connect to %s\n", SERVER); set_failed(); return NULL; } dbloginfree(login); if (strlen(DATABASE)) dbuse(dbproc, DATABASE); pthread_mutex_lock(&mutex); ++thread_count; pthread_mutex_unlock(&mutex); printf("thread %2d waiting for all threads to start\n", num+1); pthread_mutex_lock(&mutex); while (thread_count < NUM_THREAD) { pthread_mutex_unlock(&mutex); sleep(1); pthread_mutex_lock(&mutex); } pthread_mutex_unlock(&mutex); for (i = 1; i <= NUM_LOOP; ++i) { printf("thread %2d of %2d loop %d\n", num+1, NUM_THREAD, i); if (test(dbproc) || result != 0) break; } dbclose(dbproc); return NULL; }
static int test(DBPROCESS *dbproc) { int i; char teststr[1024]; DBINT testint; /* fprintf(stdout, "select\n"); */ dbcmd(dbproc, "select * from dblib_thread order by i"); dbsqlexec(dbproc); if (dbresults(dbproc) != SUCCEED) { fprintf(stdout, "Was expecting a result set.\n"); set_failed(); return 1; } if (SUCCEED != dbbind(dbproc, 1, INTBIND, 0, (BYTE *) & testint)) { fprintf(stderr, "Had problem with bind\n"); abort(); } if (SUCCEED != dbbind(dbproc, 2, STRINGBIND, 0, (BYTE *) teststr)) { fprintf(stderr, "Had problem with bind\n"); abort(); } for (i = 0; i < ROWS; i++) { char expected[64]; sprintf(expected, "row %d", i); memset(teststr, 'x', sizeof(teststr)); teststr[0] = 0; teststr[sizeof(teststr) - 1] = 0; if (REG_ROW != dbnextrow(dbproc)) { fprintf(stderr, "Failed. Expected a row\n"); set_failed(); return 1; } if (testint != i) { fprintf(stderr, "Failed. Expected i to be %d, was %d\n", i, (int) testint); abort(); } if (0 != strncmp(teststr, expected, strlen(expected))) { fprintf(stdout, "Failed. Expected s to be |%s|, was |%s|\n", expected, teststr); abort(); } /* printf("Read a row of data -> %d |%s|\n", (int) testint, teststr); */ } if (dbnextrow(dbproc) != NO_MORE_ROWS) { fprintf(stderr, "Was expecting no more rows\n"); set_failed(); return 1; } dbcancel(dbproc); return 0; }
int PPInstance::DownloadP3DComponents( std::string& p3dDllFilename ) { int error(0); // Get the pathname of the local copy of the contents.xml file. std::string finalContentsFileName( m_rootDir ); finalContentsFileName += "/"; finalContentsFileName += P3D_CONTENTS_FILENAME; // Check to see if the version on disk is already current enough. bool already_got = false; if (read_contents_file(finalContentsFileName, false)) { if (time(NULL) < _contents_expiration) { // Got the file, and it's good. already_got = true; } } if (!already_got) { // OK, we need to download a new contents.xml file. Start off // by downloading it into a local temporary file. TCHAR tempFileName[ MAX_PATH ]; if (!::GetTempFileName( m_rootDir.c_str(), "p3d", 0, tempFileName )) { nout << "GetTempFileName failed (folder is " << m_rootDir << ")\n"; return 1; } std::string localContentsFileName( tempFileName ); std::string hostUrl( PANDA_PACKAGE_HOST_URL ); if (!hostUrl.empty() && hostUrl[hostUrl.size() - 1] != '/') { hostUrl += '/'; } // Append a query string to the contents.xml URL to uniquify it // and ensure we don't get a cached version. std::ostringstream strm; strm << hostUrl << P3D_CONTENTS_FILENAME << "?" << time(NULL); std::string remoteContentsUrl( strm.str() ); error = DownloadFile( remoteContentsUrl, localContentsFileName ); if ( !error ) { if ( !read_contents_file( localContentsFileName, true ) ) error = 1; } if ( error ) { // If we couldn't download or read the contents.xml file, check // to see if there's a good one on disk already, as a fallback. if ( !read_contents_file( finalContentsFileName, false ) ) error = 1; } // We don't need the temporary file any more. ::DeleteFile( localContentsFileName.c_str() ); } if (!error) { // OK, at this point we have successfully read contents.xml, // and we have a good file spec in _coreapi_dll. if (_coreapi_dll.quick_verify(m_rootDir)) { // The DLL is already on-disk, and is good. p3dDllFilename = _coreapi_dll.get_pathname(m_rootDir); } else { // The DLL is not already on-disk, or it's stale. Go get it. std::string p3dLocalModuleFileName(_coreapi_dll.get_pathname(m_rootDir)); mkfile_complete(p3dLocalModuleFileName, nout); // Try one of the mirrors first. std::vector<std::string> mirrors; choose_random_mirrors(mirrors, 2); error = 1; for (std::vector<std::string>::iterator si = mirrors.begin(); si != mirrors.end() && error; ++si) { std::string url = (*si) + _coreapi_dll.get_filename(); error = DownloadFile(url, p3dLocalModuleFileName); if (!error && !_coreapi_dll.full_verify(m_rootDir)) { // If it's not right after downloading, it's an error. error = 1; } } // If that failed, go get it from the authoritative host. if (error) { std::string url = _download_url_prefix + _coreapi_dll.get_filename(); error = DownloadFile(url, p3dLocalModuleFileName); if (!error && !_coreapi_dll.full_verify(m_rootDir)) { error = 1; } } // If *that* failed, go get it again from the same URL, this // time with a query prefix to bust through any caches. if (error) { std::ostringstream strm; strm << _download_url_prefix << _coreapi_dll.get_filename(); strm << "?" << time(NULL); std::string url = strm.str(); error = DownloadFile(url, p3dLocalModuleFileName); if (!error && !_coreapi_dll.full_verify(m_rootDir)) { nout << "After download, " << _coreapi_dll.get_filename() << " is no good.\n"; error = 1; } } if (!error) { // Downloaded successfully. p3dDllFilename = _coreapi_dll.get_pathname(m_rootDir); } } } if (error) { set_failed(); } return error; }