Esempio n. 1
0
/* TRUE if item is an exact match or item is a member of "item1|item2|...|itemN" (case-insensitive) */
static Bool minterm_matches(
	esif_string list,
	esif_string item
	)
{
	size_t len = esif_ccb_strlen(item, MAX_MINTERM_LENGTH);

	while (list) {
		if ((esif_ccb_strnicmp(list, item, len) == 0) && (list[len] == 0 || list[len] == '|')) {
			return ESIF_TRUE;
		}
		if ((list = esif_ccb_strchr(list, '|')) != NULL)
			list++;
	}
	return ESIF_FALSE;
}
Esempio n. 2
0
static eEsifError EsifActMgr_CreatePossActList_Locked()
{
	eEsifError rc = ESIF_OK;
	struct esif_ccb_file curFile = {0};
	esif_ccb_file_enum_t fileIter = {0};
	char libPath[ESIF_LIBPATH_LEN];
	char *dotPtr = NULL;
	EsifActMgrEntryPtr newPossPtr = NULL;
	EsifString filePattern = ESIF_UPE_FILE_PREFIX "*" ESIF_LIB_EXT;

	g_actMgr.possibleActions = esif_link_list_create();
	if (NULL == g_actMgr.possibleActions) {
		rc = ESIF_E_NO_MEMORY;
		goto exit;
	}

	/* Get the loadable action directory path */
	esif_build_path(libPath, sizeof(libPath), ESIF_PATHTYPE_DLL, NULL, NULL);

	fileIter = esif_ccb_file_enum_first(libPath, filePattern, &curFile);
	if (INVALID_HANDLE_VALUE == fileIter) {
		goto exit;
	}

	do {
		newPossPtr = esif_ccb_malloc(sizeof(*newPossPtr));
		if(NULL == newPossPtr) {
			break;
		}
		dotPtr = esif_ccb_strchr(curFile.filename, '.');
		if (dotPtr != NULL) {
			*dotPtr = '\0';
			newPossPtr->libName = (esif_string)esif_ccb_strdup(curFile.filename);

			esif_link_list_add_at_back(g_actMgr.possibleActions, (void *)newPossPtr);
		}
	} while (esif_ccb_file_enum_next(fileIter, filePattern, &curFile));
	esif_ccb_file_enum_close(fileIter);
exit:
	return rc;
}
Esempio n. 3
0
// Initialize Pathname List
enum esif_rc esif_pathlist_init(esif_string paths)
{
	static esif_pathmap pathmap[] = {
		{ "HOME",	ESIF_PATHTYPE_HOME },
		{ "TEMP",	ESIF_PATHTYPE_TEMP },
		{ "DV",		ESIF_PATHTYPE_DV },
		{ "LOG",	ESIF_PATHTYPE_LOG },
		{ "BIN",	ESIF_PATHTYPE_BIN },
		{ "LOCK",	ESIF_PATHTYPE_LOCK },
		{ "EXE",	ESIF_PATHTYPE_EXE },
		{ "DLL",	ESIF_PATHTYPE_DLL },
		{ "DPTF",	ESIF_PATHTYPE_DPTF },
		{ "DSP",	ESIF_PATHTYPE_DSP },
		{ "CMD",	ESIF_PATHTYPE_CMD },
		{ "UI",		ESIF_PATHTYPE_UI  },
		{ NULL }
	};
	static int num_paths = (sizeof(pathmap)/sizeof(*pathmap)) - 1;
	esif_string *pathlist = NULL;
	enum esif_rc rc = ESIF_OK;

	if (!g_pathlist.initialized) {
		char *buffer = NULL;
		char *filename = ESIF_PATHLIST_FILENAME;
		FILE *fp = NULL;
		struct stat st={0};

		// Use pathlist file, if it exists
		if (esif_ccb_stat(filename, &st) == 0 && esif_ccb_fopen(&fp, filename, "rb") == 0) {
			if ((buffer = (char *) esif_ccb_malloc(st.st_size + 1)) != NULL) {
				if (esif_ccb_fread(buffer, st.st_size, sizeof(char), st.st_size, fp) != (size_t)st.st_size) {
					rc = ESIF_E_IO_ERROR;
				}
			}
			esif_ccb_fclose(fp);
		}
		// Otherwise, use default pathlist
		else if (buffer == NULL && paths != NULL) {
			buffer = esif_ccb_strdup(paths);
		}

		if ((buffer == NULL) || ((pathlist = (esif_string *)esif_ccb_malloc(num_paths * sizeof(esif_string))) == NULL)) {
			esif_ccb_free(buffer);
			buffer = NULL;
			rc = ESIF_E_NO_MEMORY;
		}

		// Parse key/value pairs into pathlist
		if (rc == ESIF_OK && buffer != NULL) {
			char *ctxt = 0;
				char *keypair = esif_ccb_strtok(buffer, "\r\n", &ctxt);
				char *value = 0;
				int  id=0;

				g_pathlist.initialized = 1;
				g_pathlist.pathmap = pathmap;
				g_pathlist.num_paths = num_paths;
				g_pathlist.pathlist = pathlist;

				while (keypair != NULL) {
					value = esif_ccb_strchr(keypair, '=');
					if (value) {
						*value++ = 0;
						for (id = 0; id < g_pathlist.num_paths && g_pathlist.pathmap[id].name; id++) {
							if (esif_ccb_stricmp(keypair, g_pathlist.pathmap[id].name) == 0) {
								esif_pathlist_set(g_pathlist.pathmap[id].type, value);
								break;
							}
						}
					}
					keypair = esif_ccb_strtok(NULL, "\r\n", &ctxt);
				}
		}
		esif_ccb_free(buffer);
	}
	return rc;
}
Esempio n. 4
0
int EsifTraceMessage(
	esif_tracemask_t module, 
	int level, 
	const char *func, 
	const char *file, 
	int line, 
	const char *msg, 
	...)
{
	int rc=0;
	char *appname  = "";
	char *fmtDetail= "%s%s:[<%s>%s@%s#%d]<%llu ms>: ";
	char *fmtInfo  = "%s%s:[<%s>]<%llu ms>: ";
	const char *sep=NULL;
	size_t fmtlen=esif_ccb_strlen(msg, 0x7FFFFFFF);
	int  detailed_message = (level >= DETAILED_TRACELEVEL ? ESIF_TRUE : ESIF_FALSE);
	va_list args;
	esif_ccb_time_t msec = 0;
	enum esif_tracemodule moduleid = ESIF_TRACEMODULE_DEFAULT;
	const char *module_name = NULL;

	esif_ccb_system_time(&msec);

	while (module >>= 1)
		moduleid++;
	module_name = EsifTraceModule_ToString(moduleid);

	level = esif_ccb_min(level, ESIF_TRACELEVEL_MAX);
	level = esif_ccb_max(level, ESIF_TRACELEVEL_FATAL);
	if ((sep = strrchr(file, *ESIF_PATH_SEP)) != NULL)
		file = sep+1;

	// Do not log function/file/line information for DPTF app interface messages logged from EsifSvcWriteLog
	if (moduleid == ESIF_TRACEMODULE_DPTF) {
		detailed_message = ESIF_FALSE;
	}

	if (g_traceinfo[level].routes & ESIF_TRACEROUTE_CONSOLE) {
		if (detailed_message)
			rc =  CMD_CONSOLE(fmtDetail, appname, g_traceinfo[level].label, module_name, func, file, line, msec);
		else
			rc =  CMD_CONSOLE(fmtInfo, appname, g_traceinfo[level].label, module_name, msec);
		va_start(args, msg);
		rc += EsifConsole_WriteConsole(msg, args);
		va_end(args);

		if (fmtlen && msg[fmtlen-1]!='\n')
			CMD_CONSOLE("\n");
	}

	if (g_traceinfo[level].routes & ESIF_TRACEROUTE_LOGFILE && EsifLogFile_IsOpen(ESIF_LOG_TRACE)) {
		time_t now=0;
		char timestamp[MAX_CTIME_LEN]={0};

		time(&now);
		esif_ccb_ctime(timestamp, sizeof(timestamp), &now);
		timestamp[20] = 0; // truncate year

		if (detailed_message)
			rc = EsifLogFile_Write(ESIF_LOG_TRACE, fmtDetail, timestamp + 4, g_traceinfo[level].label, module_name, func, file, line, msec);
		else
			rc =  EsifLogFile_Write(ESIF_LOG_TRACE, fmtInfo, timestamp+4, g_traceinfo[level].label, module_name, msec);
		va_start(args, msg);
		rc += EsifLogFile_WriteArgsAppend(ESIF_LOG_TRACE, "\n", msg, args);
		va_end(args);
	}

#ifdef ESIF_ATTR_OS_WINDOWS
	if (g_traceinfo[level].routes & (ESIF_TRACEROUTE_DEBUGGER)) {
		size_t  msglen=0;
		char *buffer=0;
		int  offset=0;

		va_start(args, msg);
		msglen = esif_ccb_vscprintf(msg, args) + esif_ccb_strlen(g_traceinfo[level].label, MAX_PATH) + esif_ccb_strlen(appname, MAX_PATH) + esif_ccb_strlen(func, MAX_PATH) + esif_ccb_strlen(file, MAX_PATH) + esif_ccb_strlen(module_name, MAX_PATH) + 22;
		va_end(args);
		msglen += (detailed_message ? esif_ccb_strlen(fmtDetail, MAX_PATH) : esif_ccb_strlen(fmtInfo, MAX_PATH));
		buffer = (char *)esif_ccb_malloc(msglen);

		if (NULL != buffer) {
			if (detailed_message)
				rc =  esif_ccb_sprintf(msglen, buffer, fmtDetail, appname, g_traceinfo[level].label, module_name, func, file, line, msec);
			else
				rc =  esif_ccb_sprintf(msglen, buffer, fmtInfo, appname, g_traceinfo[level].label, module_name, msec);

			offset = rc;
			va_start(args, msg);
			rc += esif_ccb_vsprintf(msglen-offset, buffer+offset, msg, args);
			va_end(args);
			if (rc && buffer[rc-1]!='\n')
				esif_ccb_strcat(buffer, "\n", msglen);

			OutputDebugStringA(buffer); 
			esif_ccb_free(buffer);
		}
	}
	if (g_traceinfo[level].routes & (ESIF_TRACEROUTE_EVENTLOG)) {
		size_t  msglen=0;
		char *buffer=0;
		char *replaced=0;
		int  offset=0;
		int  backset=0;
		WORD eventType;

		appname  = "";
		fmtInfo  = "%sESIF(%s) TYPE: %s MODULE: %s TIME %llu ms\n\n";
		fmtDetail= "%sESIF(%s) TYPE: %s MODULE: %s FUNC: %s FILE: %s LINE: %d TIME: %llu ms\n\n";
		backset  = 0;

		va_start(args, msg);
		msglen = esif_ccb_vscprintf(msg,args) + esif_ccb_strlen(g_traceinfo[level].label, MAX_PATH) + esif_ccb_strlen(appname, MAX_PATH) + esif_ccb_strlen(func, MAX_PATH) + esif_ccb_strlen(file, MAX_PATH) + esif_ccb_strlen(module_name, MAX_PATH) + 32;
		va_end(args);
		msglen += (detailed_message ? esif_ccb_strlen(fmtDetail, MAX_PATH) : esif_ccb_strlen(fmtInfo, MAX_PATH));
		buffer = (char *)esif_ccb_malloc(msglen);

		if (NULL != buffer) {
			if (detailed_message)
				rc = esif_ccb_sprintf(msglen, buffer, fmtDetail, appname, ESIF_UF_VERSION, g_traceinfo[level].label, module_name, func, file, line, msec);
			else
				rc = esif_ccb_sprintf(msglen, buffer, fmtInfo, appname, ESIF_UF_VERSION, g_traceinfo[level].label, module_name, msec);

			if (backset && backset < rc)
				buffer[rc-backset-1] = 0;
			offset = rc-backset;
			va_start(args, msg);
			rc += esif_ccb_vsprintf(msglen-(offset+backset), buffer+offset+backset, msg, args);
			va_end(args);
			if (rc && buffer[rc-1]=='\n')
				buffer[--rc] = 0;

			switch (g_traceinfo[level].level) {
			case ESIF_TRACELEVEL_FATAL:
			case ESIF_TRACELEVEL_ERROR:
				eventType = EVENTLOG_ERROR_TYPE;
				break;
			case ESIF_TRACELEVEL_WARN:
				eventType = EVENTLOG_WARNING_TYPE;
				break;
			case ESIF_TRACELEVEL_INFO:
			case ESIF_TRACELEVEL_DEBUG:
			default:
				eventType = EVENTLOG_INFORMATION_TYPE;
				break;
			}
			// Escape any "%" in message before writing to EventLog
			if ((replaced = esif_str_replace(buffer, "%", "%%")) != NULL) {
				esif_ccb_free(buffer);
				buffer = replaced;
				replaced = NULL;
			}
			report_event_to_event_log(CATEGORY_GENERAL, eventType, buffer);
			esif_ccb_free(buffer);
		}
	}
#endif
#ifdef ESIF_ATTR_OS_LINUX
	if (g_traceinfo[level].routes & (ESIF_TRACEROUTE_EVENTLOG|ESIF_TRACEROUTE_DEBUGGER)) {
		size_t  msglen=0;
		char *buffer=0;
		int  offset=0;
		int priority;

		fmtDetail= "%s:[<%s>%s@%s#%d]<%llu ms>: ";
		fmtInfo  = "%s:[<%s>]<%llu ms>: ";

		va_start(args, msg);
		msglen = esif_ccb_vscprintf(msg,args) + esif_ccb_strlen(g_traceinfo[level].label, MAX_PATH) + esif_ccb_strlen(func, MAX_PATH) + esif_ccb_strlen(file, MAX_PATH) + esif_ccb_strlen(module_name, MAX_PATH) + 22;
		va_end(args);
		msglen += (detailed_message ? esif_ccb_strlen(fmtDetail, MAX_PATH) : esif_ccb_strlen(fmtInfo, MAX_PATH));
		buffer = (char *)esif_ccb_malloc(msglen);

		if (NULL != buffer) {
			char *lf;
			if (detailed_message)
				rc =  esif_ccb_sprintf(msglen, buffer, fmtDetail, g_traceinfo[level].label, module_name, func, file, line, msec);
			else
				rc =  esif_ccb_sprintf(msglen, buffer, fmtInfo, g_traceinfo[level].label, module_name, msec);

			offset = rc;
			va_start(args, msg);
			rc += esif_ccb_vsprintf(msglen-offset, buffer+offset, msg, args);
			va_end(args);
			if (rc && buffer[rc-1]=='\n')
				buffer[--rc] = 0;

			while ((lf = esif_ccb_strchr(buffer, '\n')) != NULL)
				*lf = '\t';

			switch (g_traceinfo[level].level) {
			case ESIF_TRACELEVEL_FATAL:
				priority = ESIF_PRIORITY_FATAL;
				break;
			case ESIF_TRACELEVEL_ERROR:
				priority = ESIF_PRIORITY_ERROR;
				break;
			case ESIF_TRACELEVEL_WARN:
				priority = ESIF_PRIORITY_WARNING;
				break;
			case ESIF_TRACELEVEL_INFO:
				priority = ESIF_PRIORITY_INFO;
				break;
			case ESIF_TRACELEVEL_DEBUG:
			default:
				priority = ESIF_PRIORITY_DEBUG;
				break;
			}
		#ifdef ESIF_ATTR_OS_ANDROID
			__android_log_write(priority, IDENT, buffer);
		#else
			openlog(IDENT, OPTION, FACILITY);
			syslog(priority, "%s", buffer);
			closelog();
		#endif
			esif_ccb_free(buffer);
		}
	}
#endif
	return rc;
}