Exemple #1
0
void downloader_init() {
	logging_log("Donwloader", LOGGING_LEVEL_INFO, "downloader_init()");
	
	configuration = configuration_get();
	
	downloader_requests_queue = queue_construct();
	downloader_files_free_queue = queue_construct();
	
	downloader_requests_cond = (pthread_cond_t*)malloc(sizeof(pthread_cond_t));
	pthread_cond_init(downloader_requests_cond, NULL);
	
	downloader_files
			= al_dictionary_construct((char(*)(const void *, const void *))&string_compare);
	downloader_files_size = 0;
	
	downloader_files_mutex = (pthread_mutex_t*)malloc(sizeof(pthread_mutex_t));
	pthread_mutex_init(downloader_files_mutex, NULL);
	
	thread_counter_mutex = (pthread_mutex_t*)malloc(sizeof(pthread_mutex_t));
	pthread_mutex_init(thread_counter_mutex, NULL);
	
	thread_terminating = (pthread_cond_t*)malloc(sizeof(pthread_cond_t));
	pthread_cond_init(thread_terminating, NULL);
	
	for(uint8_t i = 0; i < configuration->downloader_threads_number; ++i) {
		pthread_t worker_thread;
		pthread_create(&worker_thread, NULL, (void *(*)(void *))&downloader_do_work, (void*)NULL);
	}
}
Exemple #2
0
static void *__fuse_initialised(struct fuse_conn_info *conn) {
    filesystem_io_mutex = (pthread_mutex_t*)malloc(sizeof(pthread_mutex_t));
    pthread_mutex_init(filesystem_io_mutex, NULL);

    configuration = configuration_get();

    _fuse_initialised();
    return NULL;
}
Exemple #3
0
static void compile(route *route, char *path) {
  int status, pos = 0;
  regex_t *result = malloc(sizeof(regex_t));
  regmatch_t matches[2];
  char *named_param_re_src = "([^/]*)";
  char *matcher_re_src = malloc_str(strlen(path) * 2);

  // capture named params and build regex
  while ((status = regexec(configuration_get()->param_match_regex, path + pos, 2, matches, 0)) == 0) {
    int match_length = matches[1].rm_eo - matches[1].rm_so;

    // get everething before parameter in url - step 1: /foo/(:bar)/test -> /foo/
    memcpy(matcher_re_src + strlen(matcher_re_src), path + pos, matches[0].rm_so);
    // put parameter regex - step 2: /foo/(:bar)/test -> /foo/([^/]*)
    memcpy(matcher_re_src + strlen(matcher_re_src), named_param_re_src, strlen(named_param_re_src));
    // capture named parameter name to use later during match
    char *parameter = malloc_str(match_length);
    memcpy(parameter, path + pos + matches[1].rm_so, matches[1].rm_eo - matches[1].rm_so);

    route->named_params[route->named_params_count] = parameter;
    route->named_params_count++;

    // advance
    pos += matches[0].rm_eo;
  }

  // remaining url part - step 3: /foo/(:bar)/test -> /foo/([^/]*)/test
  memcpy(matcher_re_src + strlen(matcher_re_src), path + pos, strlen(path) - pos);

  char *regex = malloc_str(strlen("^") + strlen(matcher_re_src) + strlen("$"));
  sprintf(regex, "^%s$", matcher_re_src);
  if(regcomp(result, regex, REG_EXTENDED) != 0) {
    die("Cannot compile dynamic matcher for route: %s", path);
  }
  free(regex);
  free(matcher_re_src);

  route->matcher = result;
}
Exemple #4
0
static void
do_autostart(void)
{
   struct chck_string key = {0}, command = {0};
   struct chck_iter_pool argv;

   if (!chck_iter_pool(&argv, 4, 4, sizeof(char*)))
      return;

   for (uint32_t i = 0; ; i++) {
      if (!chck_string_set_format(&key, "/autostart/%u", i))
         break;

      const char *command_cstr;
      if (!configuration_get(key.data, 's', &command_cstr))
         break;

      if (!chck_string_set_cstr(&command, command_cstr, true))
         break;

      char *t;
      size_t len;
      const char *state = NULL;
      while ((t = (char*)chck_cstr_tokenize_quoted(command.data, &len, " ", "\"'", &state))) {
         chck_iter_pool_push_back(&argv, &t);
         t[len] = 0; /* replaces each token with \0 */
      }

      const char *null = NULL;
      chck_iter_pool_push_back(&argv, &null); /* NULL indicates end of the array */
      plog(plugin.self, PLOG_INFO, "spawning: %s", command_cstr);
      wlc_exec(command.data, chck_iter_pool_to_c_array(&argv, NULL));
      chck_iter_pool_empty(&argv);
   }

   chck_string_release(&key);
   chck_string_release(&command);
   chck_iter_pool_release(&argv);
}
Exemple #5
0
static void fuse_initialised() {
	logging_init();
	
	musicfs_configuration_t *configuration = configuration_get();
	
	logging_set_destination(configuration->logfile);
	logging_set_level(configuration->log_level);
	logging_set_timestamp_printed(configuration->log_timestamp_use);
	
	http_init();
	providers_init();
	
	// Register built-in providers
	skreemr_init();
	
	// Set default search provider
	provider_t *provider = providers_find(configuration->provider_name);
	if(!provider)
		logging_log(MODULE, LOGGING_LEVEL_CRITICAL, "'%s' is not a known search provider.", configuration->provider_name);
	else searcher_provider_set(provider);
	
	logging_log(MODULE, LOGGING_LEVEL_INFO, "fuse_initialised()");
	downloader_init();
}