Пример #1
0
static void *APR_THREAD_FUNC shellTui_runnable(apr_thread_t *thd, void *data) {
	shell_tui_activator_pt act = (shell_tui_activator_pt) data;

	char in[256];
	bool needPrompt = true;
	while (act->running) {
		char * dline = NULL;
		char * line = NULL;
		if (needPrompt) {
			printf("-> ");
			needPrompt = false;
		}
		fgets(in, 256, stdin);
		needPrompt = true;
		dline = strdup(in);
		line = utils_stringTrim(dline);
		if (strlen(line) == 0) {
		    free(dline);
			continue;
		}
		if (act->shell == NULL) {
		    free(dline);
			continue;
		}
		act->shell->executeCommand(act->shell->shell, line, shellTui_write, shellTui_write);
		free(dline);
	}
	apr_thread_exit(thd, APR_SUCCESS);
	return NULL;
}
Пример #2
0
static celix_status_t remoteShell_connection_execute(connection_pt connection, char *command) {
	celix_status_t status = CELIX_SUCCESS;

	if (status == CELIX_SUCCESS) {
		char *dline = strdup(command);
		char *line = utils_stringTrim(dline);
		int len = strlen(line);

		if (len == 0) {
			//ignore
		} else if (len == 4 && strncmp("exit", line, 4) == 0) {
			status = CELIX_FILE_IO_EXCEPTION;
		} else {
			status = shellMediator_executeCommand(connection->parent->mediator, line, connection->socketStream, connection->socketStream);
            fflush(connection->socketStream);
		}

		free(dline);
	}

	return status;
}
Пример #3
0
celix_status_t wiringEndpoint_properties_load(char *inStr, properties_pt properties) {

	celix_status_t status = CELIX_SUCCESS;

	char* line;
	char key[WIRING_ENDPOINT_PROP_MAX_KEY_LENGTH];
	char value[WIRING_ENDPOINT_PROP_MAX_VALUE_LENGTH];

	bool precedingCharIsBackslash = false;
	bool isComment = false;
	int linePos = 0;
	int outputPos = 0;
	char* output = NULL;

	char* delim = "\n";
	char* saveptr;

	if (properties == NULL) {
		status = CELIX_ILLEGAL_STATE;
	} else {

		line = strtok_r(inStr, delim , &saveptr);

		while (line != NULL) {
			linePos = 0;
			precedingCharIsBackslash = false;
			isComment = false;
			output = NULL;
			outputPos = 0;
			key[0] = '\0';
			value[0] = '\0';

			while (line[linePos] != '\0') {
				if (line[linePos] == ' ' || line[linePos] == '\t') {
					if (output == NULL) {
						//ignore
						linePos += 1;
						continue;
					} else {
						output[outputPos++] = line[linePos];
					}
				} else {
					if (output == NULL) {
						output = key;
					}
				}
				if (line[linePos] == '=' || line[linePos] == ':' || line[linePos] == '#' || line[linePos] == '!') {
					if (precedingCharIsBackslash) {
						//escaped special character
						output[outputPos++] = line[linePos];
						precedingCharIsBackslash = false;
					} else {
						if (line[linePos] == '#' || line[linePos] == '!') {
							if (outputPos == 0) {
								isComment = true;
								break;
							} else {
								output[outputPos++] = line[linePos];
							}
						} else { // = or :
							if (output == value) { //already have a seperator
								output[outputPos++] = line[linePos];
							} else {
								output[outputPos++] = '\0';
								output = value;
								outputPos = 0;
							}
						}
					}
				} else if (line[linePos] == '\\') {
					if (precedingCharIsBackslash) { //double backslash -> backslash
						output[outputPos++] = '\\';
					}
					precedingCharIsBackslash = true;
				} else { //normal character
					precedingCharIsBackslash = false;
					output[outputPos++] = line[linePos];
				}
				linePos += 1;
			}
			if (output != NULL) {
				output[outputPos] = '\0';
			}

			if (!isComment) {
				properties_set(properties, utils_stringTrim(key), utils_stringTrim(value));
			}

			line = strtok_r(NULL, delim, &saveptr);
		}
	}

	return status;
}
Пример #4
0
/**
 * Allocates memory and initializes a new endpoint_discovery_poller instance.
 */
celix_status_t endpointDiscoveryPoller_create(discovery_pt discovery, bundle_context_pt context, endpoint_discovery_poller_pt *poller) {
    celix_status_t status;

    *poller = malloc(sizeof(struct endpoint_discovery_poller));
    if (!*poller) {
        return CELIX_ENOMEM;
    }

    (*poller)->loghelper = &discovery->loghelper;

	status = celixThreadMutex_create(&(*poller)->pollerLock, NULL);
	if (status != CELIX_SUCCESS) {
		return status;
	}

	char* interval = NULL;
	status = bundleContext_getProperty(context, DISCOVERY_POLL_INTERVAL, &interval);
	if (!interval) {
		interval = DEFAULT_POLL_INTERVAL;
	}

	char* endpoints = NULL;
	status = bundleContext_getProperty(context, DISCOVERY_POLL_ENDPOINTS, &endpoints);
	if (!endpoints) {
		endpoints = DEFAULT_POLL_ENDPOINTS;
	}
	// we're going to mutate the string with strtok, so create a copy...
	endpoints = strdup(endpoints);

	(*poller)->poll_interval = atoi(interval);
	(*poller)->discovery = discovery;
	(*poller)->running = false;
	(*poller)->entries = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL);

	const char* sep = ",";
	char *save_ptr = NULL;
	char* tok = strtok_r(endpoints, sep, &save_ptr);
	while (tok) {
		endpointDiscoveryPoller_addDiscoveryEndpoint(*poller, utils_stringTrim(tok));
		tok = strtok_r(NULL, sep, &save_ptr);
	}
	// Clean up after ourselves...
	free(endpoints);

    status = celixThreadMutex_lock(&(*poller)->pollerLock);
    if (status != CELIX_SUCCESS) {
        return CELIX_BUNDLE_EXCEPTION;
    }

	(*poller)->running = true;

	status = celixThread_create(&(*poller)->pollerThread, NULL, endpointDiscoveryPoller_performPeriodicPoll, *poller);
	if (status != CELIX_SUCCESS) {
		return status;
	}


    status = celixThreadMutex_unlock(&(*poller)->pollerLock);

    return status;
}
Пример #5
0
properties_pt properties_load(char *filename) {
	properties_pt props = properties_create();
	FILE *file = fopen ( filename, "r" );

	char line[1024];
	char key[1024];
	char value[1024];
	bool precedingCharIsBackslash = false;
	bool isComment = false;
	int valueStart = 0;
	int linePos = 0;
	int outputPos = 0;
	char *output = NULL;

	if (file != NULL ) {
		while ( fgets ( line, sizeof line, file ) != NULL ) {

			linePos = 0;
			precedingCharIsBackslash = false;
			isComment = false;
			output = NULL;
			outputPos = 0;
			key[0] = '\0';
			value[0] = '\0';

			while (line[linePos] != '\0') {
				if (line[linePos] == ' ' || line[linePos] == '\t') {
					if (output == NULL) {
						//ignore
						linePos += 1;
						continue;
					} else {
						output[outputPos++] = line[linePos];
					}
				} else {
					if (output == NULL) {
						output = key;
					}
				}
				if (line[linePos] == '=' || line[linePos] == ':' || line[linePos] == '#' || line[linePos] == '!') {
					if (precedingCharIsBackslash) {
						//escaped special character
						output[outputPos++] = line[linePos];
						precedingCharIsBackslash = false;
					} else {
						if (line[linePos] == '#' || line[linePos] == '!') {
							if (outputPos == 0) {
								isComment = true;
								break;
							} else {
								output[outputPos++] = line[linePos];
							}
						} else { // = or :
							if (output == value) { //already have a seperator
								output[outputPos++] = line[linePos];
							} else {
								output[outputPos++] = '\0';
								output = value;
								outputPos = 0;
							}
						}
					}
				} else if (line[linePos] == '\\') {
					if (precedingCharIsBackslash) { //double backslash -> backslash
							output[outputPos++] = '\\';
					}
					precedingCharIsBackslash = true;
				} else { //normal character
					precedingCharIsBackslash = false;
					output[outputPos++] = line[linePos];
				}
				linePos += 1;
			}
			if (output != NULL) {
				output[outputPos] = '\0';
			}

			if (!isComment) {
				//printf("putting 'key'/'value' '%s'/'%s' in properties\n", utils_stringTrim(key), utils_stringTrim(value));
				hashMap_put(props, strdup(utils_stringTrim(key)), strdup(utils_stringTrim(value)));
			}
		}

		fclose(file);
	}

	return props;
}