示例#1
0
DrmaaServiceJob *AllocateDrmaaServiceJob (const char *drmaa_program_name_s, Service *service_p, const char *job_name_s)
{
	DrmaaServiceJob *job_p = NULL;
	DrmaaTool *drmaa_tool_p = AllocateDrmaaTool (drmaa_program_name_s);

	if (drmaa_tool_p)
		{
			job_p = (DrmaaServiceJob *) AllocMemory (sizeof (DrmaaServiceJob));

			if (job_p)
				{
					InitDrmaaServiceJob (job_p, service_p, job_name_s, NULL);
					job_p -> dsj_drmaa_p = drmaa_tool_p;
				}
			else
				{
					FreeDrmaaTool (drmaa_tool_p);
					PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to allocate drmaa service job");
				}
		}
	else
		{
			PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to allocate drmaa tool");
		}

	return job_p;
}
示例#2
0
char *GetFileContentsAsStringByFilename (const char *filename_s)
{
	char *data_s = NULL;

	if (filename_s)
		{
			FILE *in_f = fopen (filename_s, "r");

			if (in_f)
				{
					int res = 0;

					data_s = GetFileContentsAsString (in_f);

					res = fclose (in_f);

					if (res)
						{
							PrintErrors (STM_LEVEL_WARNING, __FILE__, __LINE__, "Error %d closing %s", res, filename_s);
						}

				}		/* if (in_f) */
			else
				{
					PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to open file %s", filename_s);
				}

		}		/* if (filename_s) */
	else
		{
			PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Filename is NULL");
		}

	return data_s;
}
示例#3
0
TempFile *TempFile :: GetTempFile (const char *template_s, const bool temp_flag)
{
	char *copied_template_s = CopyToNewString (template_s, 0, false);

	if (copied_template_s)
		{
			bool success_flag = false;

			if (temp_flag)
				{
					int fd = mkstemp (copied_template_s);

					if (fd >= 1)
						{
							close (fd);
							success_flag = true;
						}
					else
						{
							PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to create temp file for \"%s\"", copied_template_s);
							FreeCopiedString (copied_template_s);
						}
				}
			else
				{
					success_flag = true;
				}

			if (success_flag)
				{
					TempFile *tf_p = new TempFile;

					tf_p -> tf_handle_f = fopen (copied_template_s, "w");

					if (tf_p -> tf_handle_f)
						{
							tf_p -> tf_name_s = copied_template_s;
							tf_p -> tf_name_mem = MF_SHALLOW_COPY;

							return tf_p;
						}
					else
						{
							PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to open temp filename \"%s\", %s", copied_template_s, strerror (errno));
						}

					delete tf_p;
				}

			FreeCopiedString (copied_template_s);
		}
	else
		{
			PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to copy temp filename for \"%s\"", template_s);
		}

	return NULL;
}
示例#4
0
bool PostConfigureGlobalStorage  (APRGlobalStorage *storage_p, apr_pool_t *server_pool_p, server_rec *server_p, const char *provider_name_s, struct ap_socache_hints *cache_hints_p)
{
	apr_status_t res;
	bool success_flag = true;

	/*
	 * Have we got a valid set of config directives?
	 */
	if (storage_p -> ags_socache_provider_p)
		{
			/* We have socache_provider, but do not have socache_instance. This should
			 * happen only when using "default" socache_provider, so create default
			 * socache_instance in this case. */
			if (! (storage_p -> ags_socache_instance_p))
				{
					const char *err_msg_s = storage_p -> ags_socache_provider_p -> create (& (storage_p -> ags_socache_instance_p), NULL, server_pool_p, server_pool_p);

					if (err_msg_s)
						{
							PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "failed to create mod_socache_shmcb socache instance: %s", err_msg_s);
							success_flag = false;
						}
				}

			if (success_flag)
				{
					res = ap_global_mutex_create (& (storage_p -> ags_mutex_p), NULL, storage_p -> ags_cache_id_s, NULL, server_p, server_pool_p, 0);

					if (res == APR_SUCCESS)
						{
							res = storage_p -> ags_socache_provider_p -> init (storage_p -> ags_socache_instance_p, storage_p -> ags_cache_id_s, cache_hints_p, server_p, server_pool_p);

							if (res != APR_SUCCESS)
								{
									PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to initialise %s cache", storage_p -> ags_cache_id_s);
									success_flag = false;
								}
						}
					else
						{
							PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "failed to create %s mutex", storage_p -> ags_cache_id_s);
							success_flag = false;
						}
				}
		}
	else
		{
			PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Please select a socache provider with AuthnCacheSOCache (no default found on this platform). Maybe you need to load mod_socache_shmcb or another socache module first");
			success_flag = false;
		}


	return success_flag;
}
示例#5
0
char *GetFileContentsAsString (FILE *input_f)
{
	char *data_s = NULL;
	long int current_pos = ftell (input_f);

	// Determine file size
	fseek (input_f, 0, SEEK_END);
	long int size = ftell (input_f);

	if (size != -1)
		{
			data_s = (char *) AllocMemory ((size + 1) * sizeof (char));

			if (data_s)
				{
					size_t read_size = 0;

					rewind (input_f);

					read_size = fread (data_s, sizeof (char), size, input_f);

					if (read_size == (size_t) size)
						{
							* (data_s + size) = '\0';

							return data_s;
						}		/* if (read_size == size) */
					else
						{
							PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to read all of file " SIZET_FMT " / " SIZET_FMT " bytes ", read_size, (size_t) size);
						}

					fseek (input_f, current_pos, SEEK_SET);

					FreeMemory (data_s);
				}
			else
				{
					PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to allocate " SIZET_FMT " bytes ", (size_t) size);
				}
		}
	else
		{
			PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to determine file size");
		}

	return NULL;
}
示例#6
0
static char *GetKeyAsValidString (char *raw_key_p, unsigned int key_length, bool *alloc_key_flag_p)
{
	char *key_s = NULL;

	if (* (raw_key_p + key_length) == '\0')
		{
			key_s = (char *) raw_key_p;
		}
	else
		{
			key_s = CopyToNewString ((const char * const) raw_key_p, key_length, false);

			if (key_s)
				{
					*alloc_key_flag_p = true;
				}
			else
				{
					key_s = "DUMMY KEY";
					PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to make key");
				}
		}

	#if APR_GLOBAL_STORAGE_DEBUG >= STM_LEVEL_FINER
	PrintLog (STM_LEVEL_FINER, __FILE__, __LINE__, "Added \"%s\" from raw key of length %u", key_s, key_length);
	#endif

	return key_s;
}
示例#7
0
bool CloseSharedMemory (void *value_p)
{
	int res = shmdt (value_p);

	if (res != -1)
		{
			return true;
		}
	else
		{
			const char *error_s = NULL;

			/* The error strings are taken from http://linux.die.net/man/2/shmat */
			switch (errno)
				{
					case EINVAL:
						error_s = "There is no shared memory segment attached at shmaddr; or, shmaddr is not aligned on a page boundary.";
						break;

					default:
						error_s = "Unknown error occurred";
						break;
				}

			PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, error_s);

			return false;
		}
}
char *ExternalBlastTool :: GetLog ()
{
	char *log_file_s = NULL;
	char sep_s [2];
	char uuid_s [UUID_STRING_BUFFER_SIZE];

	*sep_s = GetFileSeparatorChar ();
	* (sep_s + 1) = '\0';

	ConvertUUIDToString (bt_job_p -> bsj_job.sj_id, uuid_s);

	log_file_s = ConcatenateVarargsStrings (ebt_working_directory_s, sep_s, uuid_s, BS_LOG_SUFFIX_S, NULL);

	if (log_file_s)
		{
			FILE *log_f = fopen (log_file_s, "r");

			if (log_f)
				{
					char *log_data_s = GetFileContentsAsString (log_f);

					if (log_data_s)
						{
							return log_data_s;
						}
					else
						{
							PrintErrors (STM_LEVEL_WARNING, __FILE__, __LINE__, "Failed to open log file %s", log_file_s);
						}

				}		/* if (log_f) */
			else
				{
					PrintErrors (STM_LEVEL_WARNING, __FILE__, __LINE__, "Failed to open log file %s", log_file_s);
				}

			FreeCopiedString (log_file_s);
		}		/* if (log_file_s) */
	else
		{
			PrintErrors (STM_LEVEL_WARNING, __FILE__, __LINE__, "Failed to get log filename for %s", uuid_s);
		}

	return NULL;
}
char *ExternalBlastTool :: GetResults (BlastFormatter *formatter_p)
{
	char *results_s = NULL;

	if (ebt_results_filename_s)
		{
			if (formatter_p && (bt_output_format != BS_DEFAULT_OUTPUT_FORMAT))
				{
					results_s = formatter_p -> GetConvertedOutput (ebt_results_filename_s, bt_output_format);

					if (!results_s)
						{
							PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to format %s to " UINT32_FMT, ebt_results_filename_s, bt_output_format);
						}

				}		/* if (formatter_p && (bt_output_format != BS_DEFAULT_OUTPUT_FORMAT)) */
			else
				{
					if (IsPathValid (ebt_results_filename_s))
						{
							results_s = GetFileContentsAsStringByFilename (ebt_results_filename_s);

							if (!results_s)
								{
									PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to read data from  %s", ebt_results_filename_s);
								}

						}		/* if (IsPathValid (ebt_results_filename_s)) */
					else
						{
							PrintErrors (STM_LEVEL_INFO, __FILE__, __LINE__, "File %s does not exist", ebt_results_filename_s);

						}
				}
		}		/* if (ebt_results_filename_s) */
	else
		{
			char uuid_s [UUID_STRING_BUFFER_SIZE];

			ConvertUUIDToString (bt_job_p -> bsj_job.sj_id, uuid_s);
			PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Results output object is NULL for \"%s\"", uuid_s);
		}

	return results_s;
}
示例#10
0
void FreePlugin (Plugin * const plugin_p)
{
	#if PLUGIN_DEBUG >= STM_LEVEL_FINER
	PrintErrors (STM_LEVEL_FINER, __FILE__, __LINE__, "FreePlugin %s" , plugin_p -> pl_name_s);
	#endif

	ClosePlugin (plugin_p);
	FreeMemory ((UnixPlugin *) plugin_p);
}
示例#11
0
// prints a JSON value object and the reader's errors
void PrintValue( wxJSONValue& val, wxJSONReader* reader )
{
	wxJSONWriter writer( wxJSONWRITER_STYLED | wxJSONWRITER_WRITE_COMMENTS );
	wxString s;
	writer.Write( val, s );
	TestCout( s );
	if ( reader )  {
		PrintErrors( *reader );
	}
}
示例#12
0
ParameterGroup *CreateAndAddParameterGroupToParameterSet (const char *name_s, const char *key_s, struct ServiceData *service_data_p, ParameterSet *param_set_p)
{
	ParameterGroup *group_p = AllocateParameterGroup (name_s, key_s, service_data_p);

	if (group_p)
		{
			if (!AddParameterGroupToParameterSet (param_set_p, group_p))
				{
					PrintErrors (STM_LEVEL_WARNING, __FILE__, __LINE__, "Failed to add \"%s\" group to \"%s\" param set", name_s, param_set_p -> ps_name_s);
					FreeParameterGroup (group_p);
					group_p = NULL;
				}
		}
	else
		{
			PrintErrors (STM_LEVEL_WARNING, __FILE__, __LINE__, "Failed to create \"%s\" group", name_s);
		}

	return group_p;
}
示例#13
0
bool ExternalBlastTool :: SetUpOutputFile ()
{
	bool success_flag = false;
	char *local_filename_s = 0;
	char uuid_s [UUID_STRING_BUFFER_SIZE];

	ConvertUUIDToString (bt_job_p -> bsj_job.sj_id, uuid_s);

	local_filename_s = ConcatenateStrings (uuid_s, BS_OUTPUT_SUFFIX_S);

	if (local_filename_s)
		{
			ebt_results_filename_s = MakeFilename (ebt_working_directory_s, local_filename_s);

			if (ebt_results_filename_s)
				{
					if (AddBlastArgsPair ("out", ebt_results_filename_s))
						{
							success_flag = true;
						}
					else
						{
							PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to set output filename to \"%s\"", ebt_results_filename_s);
						}
				}
			else
				{
					PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to create filename for %s, %s", ebt_working_directory_s, local_filename_s);
				}

			FreeCopiedString (local_filename_s);
		}
	else
		{
			PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to create local filename for %s, %s", uuid_s, BS_OUTPUT_SUFFIX_S);
		}



	return success_flag;
}
示例#14
0
json_t *GetParameterGroupAsJSON (ParameterGroup *param_group_p)
{
	json_error_t err;
	json_t *value_p = json_pack_ex (&err, 0, "{s:s,s:b}", PARAM_GROUP_S, param_group_p -> pg_name_s, PARAM_GROUP_VISIBLE_S, param_group_p -> pg_visible_flag);

	if (!value_p)
		{
			PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "GetParameterGroupAsJSON failed for \"%s\"", param_group_p -> pg_name_s);
		}

	return value_p;
}
示例#15
0
bool FreeSharedMemory (int id)
{
	int res = shmctl (id, IPC_RMID, NULL);

	if (res != -1)
		{
			return true;
		}
	else
		{
			const char *error_s = NULL;

			/* The error strings are taken from http://linux.die.net/man/2/shmget */
			switch (errno)
				{
					case EACCES:
						error_s = "IPC_STAT or SHM_STAT is requested and shm_perm.mode does not allow read access for shmid, and the calling process does not have the CAP_IPC_OWNER capability.";
						break;

					case EFAULT:
						error_s = "The argument cmd has value IPC_SET or IPC_STAT but the address pointed to by buf isn't accessible.";
						break;

					case EINVAL:
						error_s = "shmid is not a valid identifier, or cmd is not a valid command. Or: for a SHM_STAT operation, the index value specified in shmid referred to an array slot that is currently unused.";
						break;

					case EIDRM:
						error_s = "shmid points to a removed identifier.";
						break;

					case ENOENT:
						error_s = "No segment exists for the given key, and IPC_CREAT was not specified.";
						break;

					case ENOMEM:
						error_s = "SHM_LOCK was specified and the size of the to-be-locked segment would mean that the total bytes in locked shared memory segments would exceed the limit for the real user ID of the calling process. This limit is defined by the RLIMIT_MEMLOCK soft resource limit (see setrlimit(2)).";
						break;

					case EOVERFLOW:
						error_s = "IPC_STAT is attempted, and the GID or UID value is too large to be stored in the structure pointed to by buf.";
						break;

					default:
						error_s = "Unknown error occurred";
						break;
				}

			PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, error_s);
			return false;
		}		/* if (res == -1) */
}
示例#16
0
bool ExternalBlastTool :: AddToJSON (json_t *root_p)
{
	bool success_flag = BlastTool :: AddToJSON (root_p);

	if (success_flag)
		{
			if (json_object_set_new (root_p, EBT_RESULTS_FILE_S, json_string (ebt_results_filename_s)) == 0)
				{
					if (json_object_set_new (root_p, EBT_COMMAND_LINE_EXECUTABLE_S, json_string (ebt_blast_s)) == 0)
						{
							if (json_object_set_new (root_p, EBT_WORKING_DIR_S, json_string (ebt_working_directory_s)) == 0)
								{
									success_flag = true;
								}		/* if (json_object_set_new (root_p, BT_FACTORY_NAME_S, json_string (bt_factory_name_s)) == 0) */
							else
								{
									PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to add %s:%s to ExternalBlastTool json", EBT_WORKING_DIR_S, ebt_working_directory_s);
								}

						}		/* if (json_object_set_new (root_p, BT_NAME_S, json_string (bt_name_s)) == 0) */
					else
						{
							PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to add %s:%s to ExternalBlastTool json", EBT_COMMAND_LINE_EXECUTABLE_S, ebt_blast_s);
						}

				}		/* if (json_object_set_new (root_p, EBT_RESULTS_FILE_S, output_file_s) == 0) */
			else
				{
					PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to add %s:%s to ExternalBlastTool json", EBT_RESULTS_FILE_S, ebt_results_filename_s);
				}

		}		/* if (success_flag) */
	else
		{
			PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "BlastTool :: AddToJSON failed");
		}

	return success_flag;
}
示例#17
0
static char *GetLocalJobFilename (const char *uuid_s, const BlastServiceData *blast_data_p)
{
	char *output_filename_s = NULL;
	char *output_filename_stem_s = MakeFilename (blast_data_p -> bsd_working_dir_s, uuid_s);

	if (output_filename_stem_s)
		{
			output_filename_s = ConcatenateStrings (output_filename_stem_s, s_remote_suffix_s);

			if (!output_filename_s)
				{
					PrintErrors (STM_LEVEL_WARNING, __FILE__, __LINE__, "Failed to create filename from \"%s\" and \"%s\"", output_filename_stem_s, s_remote_suffix_s);
				}

			FreeCopiedString (output_filename_stem_s);
		}		/* if (output_filename_stem_s) */
	else
		{
			PrintErrors (STM_LEVEL_WARNING, __FILE__, __LINE__, "Failed to create filename stem from \"%s\" and \"%s\"", output_filename_stem_s, uuid_s);
		}

	return output_filename_s;
}
示例#18
0
void ObjectManager::drawAllObjects() {
	// background color
	SDL_SetRenderDrawColor(context, 0, 0, 0, 0);
	if (SDL_RenderClear(context)) {
		PrintErrors("Renderer failed to clear", SDL_GetError);
	}
	mutey.lock();
	std::map<uint32_t, Object*>::iterator iter = objectsInLevel.begin();
	for (iter; iter != objectsInLevel.end(); ++iter) {
		if (iter->second->getIsRenderable())
			iter->second->draw();
	}
	mutey.unlock();

	SDL_RenderPresent(context);
}
示例#19
0
char *CreateGroupName (const char *server_s)
{
	char *group_name_s = ConcatenateVarargsStrings (BS_DATABASE_GROUP_NAME_S, " provided by ", server_s, NULL);

	if (group_name_s)
		{
			#if PAIRED_BLAST_SERVICE_DEBUG >= STM_LEVEL_FINER
			PrintLog (STM_LEVEL_FINER, __FILE__, __LINE__, "Created group name \"%s\" for \"%s\" and \"%s\"", group_name_s, server_s);
			#endif
		}
	else
		{
			PrintErrors (STM_LEVEL_WARNING, __FILE__, __LINE__, "Failed to create group name for \"%s\"", group_name_s);
		}

	return group_name_s;
}
示例#20
0
bool PreConfigureGlobalStorage (APRGlobalStorage *storage_p, apr_pool_t *config_pool_p)
{
	bool success_flag = false;
	apr_status_t status = ap_mutex_register (config_pool_p, storage_p -> ags_cache_id_s, NULL, APR_LOCK_DEFAULT, 0);

	if (status == APR_SUCCESS)
		{
			storage_p -> ags_socache_provider_p = ap_lookup_provider (AP_SOCACHE_PROVIDER_GROUP, AP_SOCACHE_DEFAULT_PROVIDER, AP_SOCACHE_PROVIDER_VERSION);
			success_flag = true;
		}
	else
		{
			PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "failed to register %s mutex", storage_p -> ags_cache_id_s);
		}

	return success_flag;
}
示例#21
0
static bool GetLargestEntrySize (APRGlobalStorage *storage_p, unsigned int *size_p)
{
	bool success_flag = false;
	unsigned int *largest_size_p = (unsigned int *) OpenSharedMemory (storage_p -> ags_largest_entry_memory_id, 0);

	if (largest_size_p)
		{
			*size_p =	*largest_size_p;

			CloseSharedMemory (largest_size_p);
			success_flag = true;
		}
	else
		{
			PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to open shared memory %d for largest size entry", storage_p -> ags_largest_entry_memory_id);
		}

	return success_flag;
}
示例#22
0
bool OpenPlugin (Plugin * const plugin_p)
{
	bool success_flag = false;
	UnixPlugin *unix_plugin_p = (UnixPlugin *) plugin_p;

	unix_plugin_p -> up_handle_p = dlopen (plugin_p -> pl_path_s, RTLD_LAZY);

	if (unix_plugin_p -> up_handle_p != NULL)
		{
			success_flag = true;
		}
	else
		{
			char *error_s = dlerror ();
			PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Error opening \"%s\": \"%s\"\n", plugin_p -> pl_path_s, error_s);
		}

	return success_flag;
}
示例#23
0
void *OpenSharedMemory (int id, int flags)
{
	void *mem_p = shmat (id, NULL, flags);

	if (mem_p != (char *) -1)
		{
			return mem_p;
		}
	else
		{
			const char *error_s = NULL;

			/* The error strings are taken from http://linux.die.net/man/2/shmat */
			switch (errno)
				{
					case EACCES:
						error_s = "The calling process does not have the required permissions for the requested attach type, and does not have the CAP_IPC_OWNER capability.";
						break;

					case EINVAL:
						error_s = "Invalid id value, unaligned (i.e., not page-aligned and SHM_RND was not specified) or invalid shmaddr value, or can't attach segment at shmaddr, or SHM_REMAP was specified and shmaddr was NULL.";
						break;

					case EIDRM:
						error_s = "id points to a removed identifier.";
						break;

					case ENOMEM:
						error_s = "Could not allocate memory for the descriptor or for the page tables.";
						break;

					default:
						error_s = "Unknown error occurred";
						break;
				}

			PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, error_s);

			return NULL;
		}
}
示例#24
0
bool InitAPRGlobalStorageForChild (APRGlobalStorage *storage_p, apr_pool_t *pool_p)
{
	bool success_flag = false;

	/* Now that we are in a child process, we have to reconnect
	 * to the global mutex and the shared segment. We also
	 * have to find out the base address of the segment, in case
	 * it moved to a new address. */
	apr_status_t res = apr_global_mutex_child_init (& (storage_p -> ags_mutex_p), storage_p -> ags_mutex_lock_filename_s, pool_p);

	if (res != APR_SUCCESS)
		{
			PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to attach grassroots child to global mutex file '%s', res %d", storage_p -> ags_mutex_lock_filename_s, res);
		}
	else
		{
			success_flag = true;
		}

	return success_flag;
}
示例#25
0
static bool SaveRemoteJobDetails (RemoteServiceJob *job_p, const BlastServiceData *blast_data_p)
{
	bool success_flag = false;
	char uuid_s [UUID_STRING_BUFFER_SIZE];
	char *output_filename_s = NULL;

	ConvertUUIDToString (job_p -> rsj_job.sj_id, uuid_s);

	output_filename_s = GetLocalJobFilename (uuid_s, blast_data_p);

	if (output_filename_s)
		{
			json_error_t error;
			json_t *remote_p = NULL;

			ConvertUUIDToString (job_p -> rsj_job_id, uuid_s);

			remote_p = json_pack_ex (&error, 0, "{s:s,s:s,s:s}", JOB_REMOTE_URI_S, job_p -> rsj_uri_s, JOB_REMOTE_UUID_S, uuid_s, JOB_SERVICE_S, job_p -> rsj_service_name_s);

			if (remote_p)
				{
					int res = json_dump_file (remote_p, output_filename_s, JSON_INDENT (2));

					if (res == 0)
						{
							success_flag = true;
						}

					json_decref (remote_p);
				}		/* if (remote_p) */
			else
				{
					PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to create remote json data, error at line %d, col %d,  \"%s\"", error.line, error.column, error.text);
				}

			FreeCopiedString (output_filename_s);
		}		/* if (output_filename_s) */

	return success_flag;
}
示例#26
0
APRGlobalStorage *AllocateAPRGlobalStorage (apr_pool_t *pool_p, apr_hashfunc_t hash_fn, unsigned char *(*make_key_fn) (const void *data_p, uint32 raw_key_length, uint32 *key_len_p), void (*free_key_and_value_fn) (unsigned char *key_p, void *value_p), server_rec *server_p, const char *mutex_filename_s, const char *cache_id_s, const char *provider_name_s)
{
	APRGlobalStorage *store_p = (APRGlobalStorage *) AllocMemory (sizeof (APRGlobalStorage));

	if (store_p)
		{
			memset (store_p, 0, sizeof (APRGlobalStorage));

			if (InitAPRGlobalStorage (store_p, pool_p, hash_fn, make_key_fn, free_key_and_value_fn, server_p, mutex_filename_s, cache_id_s, provider_name_s))
				{
					return store_p;
				}

			FreeAPRGlobalStorage (store_p);
		}
	else
		{
			PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to allocate APRGlobalStorage");
		}

	return NULL;
}
示例#27
0
char *ExternalBlastTool :: GetJobFilename (const char * const prefix_s, const char * const suffix_s)
{
	char *job_filename_s = NULL;
	char *job_id_s = GetUUIDAsString (bt_job_p -> bsj_job.sj_id);

	if (job_id_s)
		{
			char *file_stem_s = NULL;

			if (ebt_working_directory_s)
				{
					file_stem_s = MakeFilename (ebt_working_directory_s, job_id_s);
				}
			else
				{
					file_stem_s = job_id_s;
				}

			if (file_stem_s)
				{
					ByteBuffer *buffer_p = AllocateByteBuffer (1024);

					if (buffer_p)
						{
							bool success_flag = false;

							if (prefix_s)
								{
									success_flag = AppendStringsToByteBuffer (buffer_p, prefix_s, file_stem_s, NULL);
								}
							else
								{
									success_flag = AppendStringToByteBuffer (buffer_p, file_stem_s);
								}

							if (success_flag && suffix_s)
								{
									success_flag = AppendStringToByteBuffer (buffer_p, suffix_s);
								}

							if (success_flag)
								{
									job_filename_s = DetachByteBufferData (buffer_p);
								}
							else
								{
									FreeByteBuffer (buffer_p);
								}

						}		/* if (buffer_p) */

					FreeCopiedString (file_stem_s);
				}		/* if (file_stem_s) */
			else
				{
					PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to get file stem for \"%s\"", job_id_s);
				}

			FreeUUIDString (job_id_s);
		}		/* if (job_id_s) */
	else
		{
			PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to get uuid string for %s", bt_job_p -> bsj_job.sj_name_s);
		}

	return job_filename_s;
}
示例#28
0
static void *FindObjectFromAPRGlobalStorage (APRGlobalStorage *storage_p, const void *raw_key_p, unsigned int raw_key_length, const bool remove_flag)
{
	void *result_p = NULL;
	unsigned int key_len = 0;
	unsigned char *key_p = NULL;

	if (storage_p -> ags_make_key_fn)
		{
			key_p = storage_p -> ags_make_key_fn (raw_key_p, raw_key_length, &key_len);
		}
	else
		{
			key_p = (unsigned char *) raw_key_p;
			key_len = raw_key_length;
		}

	if (key_p)
		{
			apr_status_t status;
			bool alloc_key_flag = false;
			char *key_s = GetKeyAsValidString ((char *) key_p, key_len, &alloc_key_flag);

			#if APR_GLOBAL_STORAGE_DEBUG >= STM_LEVEL_FINEST
			PrintLog (STM_LEVEL_FINEST,  __FILE__, __LINE__,"Made key: %s", key_s);
			#endif


			status = apr_global_mutex_lock (storage_p -> ags_mutex_p);

			if (status == APR_SUCCESS)
				{
					unsigned char *temp_p = NULL;
					unsigned int array_size = 0;

					#if APR_GLOBAL_STORAGE_DEBUG >= STM_LEVEL_FINEST
					PrintLog (STM_LEVEL_FINEST,  __FILE__, __LINE__,"Locked mutex");
					#endif

					if (GetLargestEntrySize (storage_p, &array_size))
						{
							/* We don't know how big the value might be so allocate the largest value that we've seen so far */
							temp_p = (unsigned char *) AllocMemoryArray (array_size, sizeof (unsigned char));

							if (temp_p)
								{
									/* get the value */
									status = storage_p -> ags_socache_provider_p -> retrieve (storage_p -> ags_socache_instance_p,
																							 storage_p -> ags_server_p,
									                              key_p,
									                              key_len,
									                              temp_p,
									                              &array_size,
									                              storage_p -> ags_pool_p);


									#if APR_GLOBAL_STORAGE_DEBUG >= STM_LEVEL_FINEST
									PrintLog (STM_LEVEL_FINEST,  __FILE__, __LINE__,"status %d key %s length %u result_p %0.16X remove_flag %d", status, key_s, key_len, temp_p, remove_flag);
									#endif

									if (status == APR_SUCCESS)
										{
											result_p = temp_p;

											if (remove_flag == true)
												{
													status = storage_p -> ags_socache_provider_p -> remove (storage_p -> ags_socache_instance_p,
													                                                        storage_p -> ags_server_p,
													                                                        key_p,
													                                                        key_len,
													                                                        storage_p -> ags_pool_p);


													#if APR_GLOBAL_STORAGE_DEBUG >= STM_LEVEL_FINEST
													PrintLog (STM_LEVEL_FINEST,  __FILE__, __LINE__,"status after removal %d", status);
													#endif
												}
										}
									else
										{
											PrintErrors (STM_LEVEL_SEVERE,  __FILE__, __LINE__,"status %d key %s result_p %0.16X remove_flag %d", status, key_s, temp_p, remove_flag);
											FreeMemory (temp_p);
										}

								}		/* if (temp_p) */

						}		/* if (GetLargestEntrySize (storage_p, &array_size)) */
					else
						{
							PrintErrors (STM_LEVEL_SEVERE,  __FILE__, __LINE__,"Failed to get largest entry size when adding \"%s\"", key_s);
						}

				}		/* if (status == APR_SUCCESS) */
			else
				{
					PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to lock mutex for %s, status %s", key_s, status);
				}


			status = apr_global_mutex_unlock (storage_p -> ags_mutex_p);

			if (status != APR_SUCCESS)
				{
					PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to unlock mutex for %s, status %s after finding %s", key_s, status);
				} /* if (status != APR_SUCCESS) */

			if (key_p != raw_key_p)
				{
					FreeMemory (key_p);
				}

			if (alloc_key_flag)
				{
					FreeCopiedString (key_s);
				}
		} /* if (key_p) */

	#if APR_GLOBAL_STORAGE_DEBUG >= STM_LEVEL_FINEST
	PrintAPRGlobalStorage (storage_p);
	#endif


	return result_p;
}
示例#29
0
bool ExternalBlastTool :: ParseParameters (ParameterSet *params_p, BlastAppParameters *app_params_p)
{
	bool success_flag = false;
	SharedType value;

	memset (&value, 0, sizeof (SharedType));

	if (GetParameterValueFromParameterSet (params_p, BS_TASK.npt_name_s, &value, true))
		{
			if (AddBlastArgsPair ("task", value.st_string_value_s))
				{
					ArgsProcessor *args_processor_p = GetArgsProcessor ();

					if (GetAndAddBlastArgs (params_p, BS_MAX_SEQUENCES.npt_name_s, false, args_processor_p))
						{
							if (bt_job_p -> bsj_job.sj_name_s)
								{
									if (AddBlastArgsPair ("db", bt_job_p -> bsj_job.sj_name_s))
										{
											if (ParseBlastAppParameters (app_params_p, bt_service_data_p, params_p, args_processor_p))
												{
													/* Expect threshold */
													if (GetAndAddBlastArgs (params_p, BS_EXPECT_THRESHOLD.npt_name_s, false, args_processor_p))
														{
															/* Output Format
															 * If we have a BlastFormatter then the output is always set to 11 which is ASN and
															 * from that we can convert into any other format using a BlastFormatter tool
															 */
															memset (&value, 0, sizeof (SharedType));

															if (GetParameterValueFromParameterSet (params_p, BS_OUTPUT_FORMAT.npt_name_s, &value, true))
																{
																	bt_output_format = value.st_ulong_value;

																	if (bt_service_data_p -> bsd_formatter_p)
																		{
																			success_flag = AddBlastArgsPair (BS_OUTPUT_FORMAT.npt_name_s, BS_DEFAULT_OUTPUT_FORMAT_S);
																		}
																	else
																		{
																			char *value_s = NULL;

																			/*
																			 * If we are producing grassroots mark up, get the results
																			 * in json file format as that is the format that we will
																			 * convert from.
																			 */
																			if (value.st_ulong_value == BOF_GRASSROOTS)
																				{
																					value.st_ulong_value = BOF_SINGLE_FILE_JSON_BLAST;
																				}

																			value_s = ConvertIntegerToString (bt_output_format);

																			if (value_s)
																				{
																					success_flag = AddBlastArgsPair (BS_OUTPUT_FORMAT.npt_name_s, value_s);
																					FreeCopiedString (value_s);
																				}		/* if (value_s) */
																			else
																				{
																					PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to convert output format \"" UINT32_FMT "\" to string", bt_output_format);
																				}

																			}

																}		/* if (GetParameterValueFromParameterSet (params_p, TAG_BLAST_OUTPUT_FORMAT, &value, true)) */
															else
																{
																	PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to get output format");
																}

															if (success_flag)
																{
																	/* Query Location */
																	if (GetParameterValueFromParameterSet (params_p, BS_SUBRANGE_FROM.npt_name_s, &value, true))
																		{
																			uint32 from = value.st_ulong_value;

																			if (GetParameterValueFromParameterSet (params_p, BS_SUBRANGE_TO.npt_name_s, &value, true))
																				{
																					uint32 to = value.st_ulong_value;

																					if ((from != 0) && (to != 0))
																						{
																							ByteBuffer *buffer_p = AllocateByteBuffer (1024);

																							if (buffer_p)
																								{
																									char *from_s = ConvertIntegerToString (from);

																									if (from_s)
																										{
																											char *to_s = ConvertIntegerToString (to);

																											if (to_s)
																												{
																													if (AppendStringsToByteBuffer (buffer_p, from_s, "-", to_s, NULL))
																														{
																															const char *query_loc_s = GetByteBufferData (buffer_p);

																															if (!AddBlastArgsPair ("query_loc", query_loc_s))
																																{
																																	success_flag = false;
																																}
																														}

																													FreeCopiedString (to_s);
																												}		/* if (to_s) */

																											FreeCopiedString (from_s);
																										}		/* if (from_s) */

																									FreeByteBuffer (buffer_p);
																								}		/* if (buffer_p) */

																						}		/* if ((from != 0) && (to != 0)) */

																				}		/* if (GetParameterValueFromParameterSet (params_p, TAG_BLAST_SUBRANGE_TO, &to, true)) */

																		}		/* if (GetParameterValueFromParameterSet (params_p, TAG_BLAST_SUBRANGE_FROM, &value, true)) */

																}		/*  if (success_flag) */
															else
																{
																	PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to set output format");
																}


														}		/* if (AddBlastArgsPairFromIntegerParameter (params_p, TAG_BLAST_EXPECT_THRESHOLD, "-evalue", true)) */

												}		/* if (bt_app_params_p -> ParseParametersToByteBuffer (bt_service_data_p, params_p, ebt_buffer_p)) */

										}		/* if (AddBlastArgsPair ("-db", bt_job_p -> sj_name_s))*/
									else
										{
											PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to set database name");
										}
								}		/* if (bt_job_p -> sj_name_s) */
							else
								{
									PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to get job name");
								}

						}		/* if (AddABlastrgsPair ("-num_alignments", "5")) */
					else
						{
							PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to add num_alignments parameter");
						}

				}		/* if (AddBlastArgsPair ("-task", BS_TASK.npt_name_s)) */
			else
				{
					PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to add task parameter");
				}

		}		/* if (GetParameterValueFromParameterSet (params_p, BS_TASK.npt_name_s, &value, true)) */
	else
		{
			PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to get task parameter value");
		}


	return success_flag;
}
示例#30
0
bool InitAPRGlobalStorage (APRGlobalStorage *storage_p, apr_pool_t *pool_p, apr_hashfunc_t hash_fn, unsigned char *(*make_key_fn) (const void *data_p, uint32 raw_key_length, uint32 *key_len_p), void (*free_key_and_value_fn) (unsigned char *key_p, void *value_p), server_rec *server_p, const char *mutex_filename_s, const char *cache_id_s, const char *provider_name_s)
{
	ap_socache_provider_t *provider_p = ap_lookup_provider (AP_SOCACHE_PROVIDER_GROUP, provider_name_s, AP_SOCACHE_PROVIDER_VERSION);

	if (provider_p)
		{
			apr_status_t status = apr_global_mutex_create (& (storage_p -> ags_mutex_p), mutex_filename_s, APR_THREAD_MUTEX_UNNESTED, pool_p);

			if (status == APR_SUCCESS)
				{
					char *current_dir_s = GetCurrentWorkingDirectory ();

					if (current_dir_s)
						{
							storage_p -> ags_largest_entry_memory_id = AllocateSharedMemory (current_dir_s, sizeof (unsigned int), 0644);

							FreeCopiedString (current_dir_s);

							if (storage_p -> ags_largest_entry_memory_id != -1)
								{
									storage_p -> ags_entries_p = apr_hash_make_custom (pool_p, hash_fn);

										if (storage_p -> ags_entries_p)
											{
												storage_p -> ags_pool_p = pool_p;
												storage_p -> ags_server_p = server_p;
												storage_p -> ags_make_key_fn = make_key_fn;
												storage_p -> ags_free_key_and_value_fn = free_key_and_value_fn;

												storage_p -> ags_cache_id_s = cache_id_s;
												storage_p -> ags_mutex_lock_filename_s = mutex_filename_s;

												storage_p -> ags_socache_instance_p = NULL;
												storage_p -> ags_socache_provider_p = provider_p;

												apr_pool_cleanup_register (pool_p, storage_p, (const void *) FreeAPRGlobalStorage, apr_pool_cleanup_null);

												return true;
											}		/* if (storage_p -> ags_entries_p) */
										else
											{
												PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to allocate shared memory hash table");
											}

									FreeSharedMemory (storage_p -> ags_largest_entry_memory_id);
								}		/* if (storage_p -> ags_largest_entry_memory_id != -1) */
							else
								{
									PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to allocate shared memory for largest chunk size");
								}

						}		/* if (mem_key_s) */
					else
						{
							PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to create memory key from \"%s\" and \".memory\"", cache_id_s);
						}

					apr_global_mutex_destroy (storage_p -> ags_mutex_p);
					storage_p -> ags_mutex_p = NULL;
				}		/* if (status == APR_SUCCESS) */
			else
				{
					PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to create global mutex for shared memory at %s", mutex_filename_s);
				}

		}		/* if (provider_p) */
	else
		{
			PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to find provider \"%s\"", provider_name_s ? provider_name_s : "NULL");
		}

	return false;
}