1. Aristarkh Zagorodnikov
  2. mod_gridfs

Commits

Aristarkh Zagorodnikov  committed 74bcbd4

Catchup with mongodb C++ driver

  • Participants
  • Parent commits 134615b
  • Branches v0.1

Comments (0)

Files changed (1)

File gridfs/mod_gridfs.cpp

View file
  • Ignore whitespace
 //	Module configuration
 struct gridfs_config
 {
-	mongo::ConnectionString *connection_string;
+	const std::string *connection_string;
 	const std::string *database;
 	int cache_max_age;
 	bool cache_max_age_set;
 static const char *gridfs_connection_command(cmd_parms *const command, void *const module_config, const char *const argument)
 {
 	gridfs_config *const config = static_cast<gridfs_config *>(module_config);
-	void *const connection_string_data = apr_palloc(command->pool, sizeof(mongo::ConnectionString));
+	void *const connection_string_data = apr_palloc(command->pool, sizeof(std::string));
 	if (connection_string_data == 0)
 		return "GridFSConnection failed to allocate data.";
-	mongo::ConnectionString * connection_string;
+	std::string *connection_string;
 	try
 	{
-		connection_string = new (connection_string_data) mongo::ConnectionString(argument, mongo::ConnectionString::SET);
+		connection_string = new (connection_string_data) std::string(argument);
 	}
 	catch (...)
 	{
 		return "GridFSConnection exception.";
 	}
-	if (!connection_string->isValid())
-		return "Invalid GridFSConnection.";
 	config->connection_string = connection_string;
 	return 0;
 }
 	void *const database_data = apr_palloc(command->pool, sizeof(std::string));
 	if (database_data == 0)
 		return "GridFSDatabase failed to allocate data.";
-	std::string * database;
+	std::string *database;
 	try
 	{
 		database = new (database_data) std::string(argument);
 	apr_bucket_brigade *brigade = 0;
 	try
 	{
-		mongo::ScopedDbConnection connection(*config->connection_string, config->connect_timeout);
+		std::auto_ptr<mongo::ScopedDbConnection> connection(mongo::ScopedDbConnection::getScopedDbConnection(*config->connection_string, config->connect_timeout));
 		try
 		{
-			const mongo::GridFS gridfs(connection.conn(), *config->database);
+			const mongo::GridFS gridfs(connection->conn(), *config->database);
 			const mongo::GridFile& gridfile = gridfs.findFile(filename, config->slave_ok);
 			if (!gridfile.exists())
 			{
-				connection.done();
+				connection->done();
 				return HTTP_NOT_FOUND;
 			}
 			const mongo::gridfs_offset file_length = gridfile.getContentLength();
 			{
 				if (!md5.empty())
 					apr_table_unset(request->headers_out, "Etag");
-				connection.done();
+				connection->done();
 				return HTTP_NOT_MODIFIED;
 			}
 			if (file_length != 0 && request->header_only == 0)
 				if (num_chunks == 0)
 				{
 					ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, request, "mod_gridfs: No chunks available for file '%s'.", filename); 
-					connection.done();
+					connection->done();
 					return HTTP_INTERNAL_SERVER_ERROR;
 				}
 				brigade = apr_brigade_create(request->pool, request->connection->bucket_alloc);
 				if (brigade == 0)
 				{
 					ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, request, "mod_gridfs: Failed to create brigade."); 
-					connection.done();
+					connection->done();
 					return HTTP_INTERNAL_SERVER_ERROR;
 				}
 				for (int chunk_index = 0;chunk_index < num_chunks;chunk_index++) 
 				{
 					const mongo::GridFSChunk& chunk = gridfile.getChunk(chunk_index);
 					int chunk_length;
-					const char* chunk_data = chunk.data(chunk_length);
+					const char *chunk_data = chunk.data(chunk_length);
 					if (chunk_length == 0)
 					{
 						ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, request, "mod_gridfs: Empty chunk %d for file '%s'.", chunk_index, filename); 
-						connection.done();
+						connection->done();
 						return HTTP_INTERNAL_SERVER_ERROR;
 					}
 					if ((result = apr_brigade_write(brigade, 0, 0, chunk_data, chunk_length)) != APR_SUCCESS)
 					{
 						ap_log_rerror(APLOG_MARK, APLOG_ERR, result, request, "mod_gridfs: Failed to write chunk %d for file '%s' to brigade (length: %d).", chunk_index, filename, chunk_length); 
-						connection.done();
+						connection->done();
 						apr_brigade_destroy(brigade);
 						return HTTP_INTERNAL_SERVER_ERROR;
 					}
 		{
 			try
 			{
-				connection.done();
+				connection->done();
 			}
 			catch (...)
 			{
 				apr_brigade_destroy(brigade);
 			throw;
 		}
-		connection.done();
+		connection->done();
 	}
 	catch (const std::exception& exception)
 	{