コード例 #1
0
/*! @brief Duplicates the error into the target
 * 
 * 
 * @param target The target error to update
 * @param source The source error which to duplicate
 * 
 */
void osync_error_set_from_error(OSyncError **target, OSyncError **source)
{
  if (!target || osync_error_is_set(target))
    return;
	
  if (!osync_error_is_set(source)) {
    *target = NULL;
    return;
  }
	
  *target = *source;
  osync_error_ref(target);
}
コード例 #2
0
osync_bool osync_plugin_env_load_module(OSyncPluginEnv *env, const char *filename, OSyncError **error)
{
	OSyncModule *module = NULL;
	
	osync_trace(TRACE_ENTRY, "%s(%p, %s, %p)", __func__, env, filename, error);
	osync_assert(env);
	osync_assert(filename);
	
	module = osync_module_new(error);
	if (!module)
		goto error;
	
	if (!osync_module_load(module, filename, error)) {
		osync_trace(TRACE_INTERNAL, "Unable to load module %s: %s", filename, osync_error_print(error));
		osync_module_free(module);
	} else {
		if (!osync_module_check(module, error)) {
			if (osync_error_is_set(error)) {
				osync_trace(TRACE_INTERNAL, "Module check error for %s: %s", filename, osync_error_print(error));
			}
			osync_module_unload(module);
			osync_module_free(module);
			osync_trace(TRACE_EXIT, "%s: Unable to load module", __func__);
			return FALSE;
		}
		
		if (!osync_module_get_sync_info(module, env, error)) {
			if (osync_error_is_set(error))
				goto error_free_module;
			
			osync_module_unload(module);
			osync_module_free(module);
			osync_trace(TRACE_EXIT, "%s: No get_sync_info function", __func__);
			return FALSE;
		}
		env->modules = g_list_append(env->modules, module);
	}
	
	osync_trace(TRACE_EXIT, "%s", __func__);
	return TRUE;

error_free_module:
	osync_module_unload(module);
	osync_module_free(module);
error:
	osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error));
	return FALSE;
}
コード例 #3
0
ファイル: support.c プロジェクト: luizluca/opensync-luizluca
void mapping_status(OSyncEngineMappingUpdate *status, void *user_data)
{
        OSyncError *error = osync_engine_mapping_update_get_error(status);

	switch (osync_engine_mapping_update_get_event(status)) {
		case OSYNC_ENGINE_MAPPING_EVENT_SOLVED:
			fail_unless(!osync_error_is_set(&(error)), NULL);
			num_mapping_solved++;
			break;
		/*case OSYNC_ENGINE_MAPPING_EVENT_WRITTEN:
			fail_unless(!osync_error_is_set(&(error)), NULL);
			num_mapping_written++;
			break;*/
		case OSYNC_ENGINE_MAPPING_EVENT_ERROR:
			fail_unless(osync_error_is_set(&(error)), NULL);
			num_mapping_errors++;
			break;
	}
}
コード例 #4
0
ファイル: support.c プロジェクト: luizluca/opensync-luizluca
void entry_status(OSyncEngineChangeUpdate *status, void *user_data)
{
	osync_trace(TRACE_ENTRY, "%s(%p, %p)", __func__, status, user_data);

        OSyncError *error = osync_engine_change_update_get_error(status);
	
	switch (osync_engine_change_update_get_event(status)) {
		case OSYNC_ENGINE_CHANGE_EVENT_READ:
			fail_unless(!osync_error_is_set(&(error)), NULL);
			num_change_read++;
			break;
		case OSYNC_ENGINE_CHANGE_EVENT_WRITTEN:
			fail_unless(!osync_error_is_set(&(error)), NULL);
			num_change_written++;
			break;
		case OSYNC_ENGINE_CHANGE_EVENT_ERROR:
			fail_unless(osync_error_is_set(&(error)), NULL);
			num_change_error++;
			break;
	}
	
	osync_trace(TRACE_EXIT, "%s", __func__);
}
コード例 #5
0
/*! @brief Sets a error from a va_list
 * 
 * @param error A pointer to a error struct
 * @param type The type to set
 * @param format The message
 * @param args The arguments to the message
 * 
 */
void osync_error_set_vargs(OSyncError **error, OSyncErrorType type, const char *format, va_list args)
{
  osync_return_if_fail(error);
  osync_return_if_fail(osync_error_is_set(error) == FALSE);
  osync_return_if_fail(format);

  *error = g_malloc0(sizeof(OSyncError));
  (*error)->message = g_strdup_vprintf(format, args);
  (*error)->type = type;
  (*error)->ref_count = 1;

  osync_trace(TRACE_ERROR, "%s", (*error)->message);
	
  return;
}
コード例 #6
0
/** @brief Decrease the reference count of the error object
 * 
 * @param error The error object 
 * 
 */
void osync_error_unref(OSyncError **error)
{
  if (!osync_error_is_set(error))
    return;
		
  if (g_atomic_int_dec_and_test(&(*error)->ref_count)) {
    if ((*error)->message)
      g_free ((*error)->message);
		
    if ((*error)->child)
      osync_error_unref(&((*error)->child));
		
    g_free(*error);
  }
	
  *error = NULL;
}
コード例 #7
0
/*! @brief Returns the entired error stack as single string 
 * 
 * @param error The error stack to print
 * @returns The message of the error or NULL if no error
 * 
 */
char *osync_error_print_stack(OSyncError **error)
{
  char *submessage = NULL;
  char *message = NULL;
  if (!osync_error_is_set(error))
    return NULL;
		
  if ((*error)->child)
    submessage = osync_error_print_stack(&((*error)->child));
	
  if (submessage) {
    message = g_strdup_printf("NEXT ERROR: \"%s\"; %s", (*error)->message, submessage);
    g_free(submessage);
  } else
    message = g_strdup_printf("ROOT CAUSE: \"%s\"", (*error)->message);
	
  return message;
}
コード例 #8
0
/*! @brief Returns the message of the error
 * 
 * @param error The error to print
 * @returns The message of the error or NULL if no error
 * 
 */
const char *osync_error_print(OSyncError **error)
{
  if (!osync_error_is_set(error))
    return NULL;
  return (*error)->message;
}
コード例 #9
0
/*! @brief Returns the type of the error
 * 
 * @param error The error
 * @returns The type of the error or OSYNC_NO_ERROR if no error
 * 
 */
OSyncErrorType osync_error_get_type(OSyncError **error)
{
  if (!osync_error_is_set(error))
    return OSYNC_NO_ERROR;
  return (*error)->type;
}
コード例 #10
0
ファイル: support.c プロジェクト: luizluca/opensync-luizluca
void engine_status(OSyncEngineUpdate *status, void *user_data)
{
	osync_trace(TRACE_ENTRY, "%s(%p, %p)", __func__, status, user_data);

        OSyncError *error = osync_engine_update_get_error(status);

	switch (osync_engine_update_get_event(status)) {
		case OSYNC_ENGINE_EVENT_CONNECTED:
			fail_unless(!osync_error_is_set(&(error)), NULL);
			num_engine_connected++;
			break;
		case OSYNC_ENGINE_EVENT_CONNECT_DONE:
			fail_unless(!osync_error_is_set(&(error)), NULL);
			num_engine_connect_done++;
			break;
		case OSYNC_ENGINE_EVENT_READ:
			fail_unless(!osync_error_is_set(&(error)), NULL);
			num_engine_read++;
			break;
		case OSYNC_ENGINE_EVENT_PREPARED_MAP:
			fail_unless(!osync_error_is_set(&(error)), NULL);
			num_engine_prepared_map++;
			break;
		case OSYNC_ENGINE_EVENT_MAPPED:
			fail_unless(!osync_error_is_set(&(error)), NULL);
			num_engine_mapped++;
			break;
		case OSYNC_ENGINE_EVENT_MULTIPLIED: 
			fail_unless(!osync_error_is_set(&(error)), NULL);
			num_engine_multiplied++;
			break;
		case OSYNC_ENGINE_EVENT_PREPARED_WRITE:
			fail_unless(!osync_error_is_set(&(error)), NULL);
			num_engine_prepared_write++;
			break;
		case OSYNC_ENGINE_EVENT_WRITTEN:
			fail_unless(!osync_error_is_set(&(error)), NULL);
			num_engine_written++;
			break;
		case OSYNC_ENGINE_EVENT_DISCONNECTED:
			fail_unless(!osync_error_is_set(&(error)), NULL);
			num_engine_disconnected++;
			break;
		case OSYNC_ENGINE_EVENT_ERROR:
			fail_unless(osync_error_is_set(&(error)), NULL);
			num_engine_errors++;
			break;
		case OSYNC_ENGINE_EVENT_SUCCESSFUL:
			fail_unless(!osync_error_is_set(&(error)), NULL);
			num_engine_successful++;
			break;
		case OSYNC_ENGINE_EVENT_PREV_UNCLEAN:
			fail_unless(!osync_error_is_set(&(error)), NULL);
			num_engine_prev_unclean++;
			break;
		case OSYNC_ENGINE_EVENT_END_CONFLICTS:
			fail_unless(!osync_error_is_set(&(error)), NULL);
			num_engine_end_conflicts++;
			break;
		case OSYNC_ENGINE_EVENT_SYNC_DONE:
			fail_unless(!osync_error_is_set(&(error)), NULL);
			num_engine_sync_done++;
			break;
	}

	osync_trace(TRACE_EXIT, "%s", __func__);
}
コード例 #11
0
ファイル: support.c プロジェクト: luizluca/opensync-luizluca
void member_status(OSyncEngineMemberUpdate *status, void *user_data)
{
	osync_trace(TRACE_ENTRY, "%s(%p), %p)", __func__, status, user_data);
	fail_unless(GINT_TO_POINTER(1) == user_data, NULL);

        OSyncError *error = osync_engine_member_update_get_error(status);
        const char *objtype = osync_engine_member_update_get_objtype(status);
	
	switch (osync_engine_member_update_get_event(status)) {
		case OSYNC_ENGINE_MEMBER_EVENT_CONNECTED:
			fail_unless(!osync_error_is_set(&(error)), NULL);
			
			if (objtype == NULL) {
				num_client_main_connected++;
			} else {
				fail_unless(!strncmp(objtype, "mockobjtype", 11), NULL);
				num_client_connected++;
			}
			
			break;
		case OSYNC_ENGINE_MEMBER_EVENT_CONNECT_DONE:
			fail_unless(!osync_error_is_set(&(error)), NULL);
			
			if (objtype == NULL) {
				num_client_main_connect_done++;
			} else {
				fail_unless(!strncmp(objtype, "mockobjtype", 11), NULL);
				num_client_connect_done++;
			}
			break;
		case OSYNC_ENGINE_MEMBER_EVENT_DISCONNECTED:
			fail_unless(!osync_error_is_set(&(error)), NULL);
			
			if (objtype == NULL) {
				num_client_main_disconnected++;
			} else {
				fail_unless(!strncmp(objtype, "mockobjtype", 11), NULL);
				num_client_disconnected++;
			}
			
			break;
		case OSYNC_ENGINE_MEMBER_EVENT_READ:
			fail_unless(!osync_error_is_set(&(error)), NULL);
			
			if (objtype == NULL) {
				num_client_main_read++;
			} else {
				fail_unless(!strncmp(objtype, "mockobjtype", 11), NULL);
				num_client_read++;
			}
			
			break;
		case OSYNC_ENGINE_MEMBER_EVENT_WRITTEN:
			fail_unless(!osync_error_is_set(&(error)), NULL);
			
			if (objtype == NULL) {
				num_client_main_written++;
			} else {
				fail_unless(!strncmp(objtype, "mockobjtype", 11), NULL);
				num_client_written++;
			}
			
			break;
		case OSYNC_ENGINE_MEMBER_EVENT_ERROR:
			fail_unless(osync_error_is_set(&(error)), NULL);
			num_client_errors++;
			break;
		case OSYNC_ENGINE_MEMBER_EVENT_SYNC_DONE:
			fail_unless(!osync_error_is_set(&(error)), NULL);
			
			if (objtype == NULL) {
				num_client_main_sync_done++;
			} else {
				fail_unless(!strncmp(objtype, "mockobjtype", 11), NULL);
				num_client_sync_done++;
			}
			
			break;
		case OSYNC_ENGINE_MEMBER_EVENT_DISCOVERED:
			fail_unless(!osync_error_is_set(&(error)), NULL);
			num_client_discovered++;
			break;
	}
	
	osync_trace(TRACE_EXIT, "%s", __func__);
}
コード例 #12
0
static OSyncFormatConverterPath *osync_format_env_find_path_fn(OSyncFormatEnv *env, OSyncData *sourcedata, OSyncPathTargetFn target_fn, OSyncTargetLastConverterFn last_converter_fn, const void *fndata, const char * preferred_format, OSyncError **error)
{
  OSyncFormatConverterPath *path = NULL;
  OSyncFormatConverterTree *tree = NULL;
  OSyncFormatConverterPathVertice *begin = NULL;
  OSyncFormatConverterPathVertice *result = NULL;
  OSyncFormatConverterPathVertice *neighbour = NULL;
  GList *e, *v;
  guint vertice_id = 0;
	
  osync_trace(TRACE_ENTRY, "%s(%p, %p, %p, %p, %p)", __func__, env, sourcedata, target_fn, fndata, error);
  osync_assert(env);
  osync_assert(sourcedata);
  osync_assert(target_fn);
	
  //Vertice = Spitze = Format
  //edge = Kante = Converter

  /* Optimization: check if the format is already valid */
  if (target_fn(fndata, osync_data_get_objformat(sourcedata))) {
    path = osync_converter_path_new(error);
    if (!path)
      goto error;
		
    osync_trace(TRACE_EXIT, "%s: Target already valid", __func__);
    return path;
  }

  /* Make a new search tree */
  tree = osync_try_malloc0(sizeof(OSyncFormatConverterTree), error);
  if (!tree)
    goto error;
  tree->unused = g_list_copy(env->converters);
	
  /* We make our starting point (which is the current format of the 
   * change of course */
  begin = osync_format_converter_path_vertice_new(error);
  if (!begin)
    goto error_free_tree;
	
  begin->format = osync_data_get_objformat(sourcedata);
  begin->path = NULL;
  begin->id = vertice_id;
  begin->neighbour_id = 0;
	
  tree->search = g_list_append(NULL, begin);
	
  /* While there are still vertices in our
   * search queue */
  while (g_list_length(tree->search)) {
    /* log current tree search list */
    GString *string = g_string_new("");
    guint size = g_list_length(tree->search);
    guint count = 0;
    guint neighbour_id = 0;
    OSyncFormatConverterPathVertice *current = NULL;
    OSyncFormatConverterPath *path_tmp = NULL;
    for (v = tree->search; v; v = v->next) {
      OSyncFormatConverterPathVertice *vertice = v->data;
      GString *string2 = g_string_new("");
      guint size2 = g_list_length(vertice->path);
      guint count2 = 0;
      count ++;
      for (e = vertice->path; e; e = e->next) {
        OSyncFormatConverter *edge = e->data;
        count2 ++;
        if (count2 == 1) {
          g_string_append(string2, osync_objformat_get_name(osync_converter_get_sourceformat(edge)));
          g_string_append(string2, " -> ");
        }
        g_string_append(string2, osync_objformat_get_name(osync_converter_get_targetformat(edge)));
        if (size2 > 1 && count2 < size2)
          g_string_append(string2, " -> ");
      }
      g_string_append(string, osync_objformat_get_name(vertice->format));
      g_string_append(string, " ( ");
      g_string_append(string, string2->str);
      g_string_append(string, " ) ");

      g_string_free(string2, TRUE);

      if (size > 1 && count < size)
        g_string_append(string, " -> ");
    }
    osync_trace(TRACE_INTERNAL, "Tree : %s", string->str);
    g_string_free(string, TRUE);

    /* Get the first OSyncFormatConverterPathVertice from the search queue
     * and remove it from the queue */
    current = tree->search->data;
    tree->search = g_list_remove(tree->search, current);
		
    /* log current OSyncFormatConverterPathVertice */
    string = g_string_new("");
    size = g_list_length(current->path);
    count = 0;
    for (e = current->path; e; e = e->next) {
      OSyncFormatConverter *edge = e->data;
      count ++;
      if (count == 1) {
        g_string_append(string, osync_objformat_get_name(osync_converter_get_sourceformat(edge)));
        g_string_append(string, " -> ");
      }
      g_string_append(string, osync_objformat_get_name(osync_converter_get_targetformat(edge)));
      if (size > 1 && count < size)
        g_string_append(string, " -> ");
    }
    osync_trace(TRACE_INTERNAL, "Next vertice : %s (%s).", osync_objformat_get_name(current->format), string->str);
    g_string_free(string, TRUE);

    current->neighbour_id = 0;
    vertice_id++; // current OSyncFormatConverterPathVertice id for its neighbours

    /* Check if we have reached a target format */
    if (target_fn(fndata, current->format)) {
      osync_trace(TRACE_INTERNAL, "Target %s found", osync_objformat_get_name(current->format));
      /* Done. return the result */
      result = current;
      break;
    }
		
    /*
     * Optimizations : 
     */
    if (last_converter_fn(fndata, tree)) {
      osync_trace(TRACE_INTERNAL, "Last converter for target format reached: %s.", (result)?osync_objformat_get_name(result->format):"null");
      osync_format_converter_path_vertice_unref(current);
      break;
    }
    /* Check if saved result is equal to current regarding losses, objtype_changes
     * and conversions. If yes, we can skip further searches and break here */
    if (result) {
      if (result->losses <= current->losses && result->objtype_changes <= current->objtype_changes && result->conversions <= current->conversions) {
        osync_trace(TRACE_INTERNAL, "Target %s found in queue", osync_objformat_get_name(result->format));
        tree->search = g_list_remove(tree->search, result);
        break;
      } else {
        result = NULL;
      }
    }


    /*
     * If we dont have reached a target, we look at our neighbours 
     */
    osync_trace(TRACE_INTERNAL, "Looking at %s's neighbours.", osync_objformat_get_name(current->format));

    /* Convert the "current" data to the last edge found in the "current" conversion path  */
    current->data = osync_data_clone(sourcedata, error);
    path_tmp = osync_converter_path_new(error);
    if (!path_tmp)
      goto error;
    for (e = current->path; e; e = e->next) {
      OSyncFormatConverter *edge = e->data;
      osync_converter_path_add_edge(path_tmp, edge);
    }
    if (!(osync_format_env_convert(env, path_tmp, current->data, error))) {
      osync_trace(TRACE_INTERNAL, "osync format env convert on this path failed - skipping the conversion");
      continue;
    }
    osync_converter_path_unref(path_tmp);

    /* Find all the neighboors or "current" at its current conversion point */
    while ((neighbour = osync_format_converter_path_vertice_get_next_vertice_neighbour(env, tree, current, error))) {
      GString *string = g_string_new("");
      guint size = g_list_length(neighbour->path);
      guint count = 0;

      neighbour->id = vertice_id;
      neighbour_id++;
      neighbour->neighbour_id = neighbour_id;

      neighbour->preferred = FALSE;
      if (current->preferred)	  /* preferred is inherited by the neighbours */
        neighbour->preferred = TRUE;
      if(preferred_format && !strcmp(preferred_format, osync_objformat_get_name(neighbour->format)))
        neighbour->preferred = TRUE;

      /* log neighbour to be added to the tree search list */
      for (e = neighbour->path; e; e = e->next) {
        OSyncFormatConverter *edge = e->data;
        count ++;
        if (count == 1) {
          g_string_append(string, osync_objformat_get_name(osync_converter_get_sourceformat(edge)));
          g_string_append(string, " -> ");
        }
        g_string_append(string, osync_objformat_get_name(osync_converter_get_targetformat(edge)));
        if (size > 1 && count < size)
          g_string_append(string, " -> ");
      }
      osync_trace(TRACE_INTERNAL, "%s's neighbour : %s (%s)", osync_objformat_get_name(current->format), osync_objformat_get_name(neighbour->format), string->str);
      g_string_free(string, TRUE);

      /* We found a neighbour and insert it sorted in our search queue 
         If vertices are equals in losses, objtypes and conversions, first registered is inserted before the others 
         in the same OSyncFormatConverterPathVertice group (vertice_id) */
      tree->search = g_list_insert_sorted(tree->search, neighbour, osync_format_converter_path_vertice_compare_distance); 

      /* Optimization:
       * We found a possible target. Save it. */
      if (target_fn(fndata, neighbour->format)) {
        osync_trace(TRACE_INTERNAL, "Possible target found.");
        result = neighbour;
        osync_format_converter_path_vertice_ref(result);
      }
    }

    if (osync_error_is_set(error))
      goto error_free_tree;
		
    /* Done, drop the reference to the OSyncFormatConverterPathVertice */
    osync_format_converter_path_vertice_unref(current);
  }
			
  if (!result) {
    osync_error_set(error, OSYNC_ERROR_GENERIC, "Unable to find conversion path");
    goto error_free_tree;
  }
	
  /* Found it. Create a path object */
  path = osync_converter_path_new(error);
  if (!path)
    goto error;
	
  for (e = result->path; e; e = e->next) {
    OSyncFormatConverter *edge = e->data;
    osync_converter_path_add_edge(path, edge);
  }
	
  /* Drop the reference to the result OSyncFormatConverterPathVertice */
  osync_format_converter_path_vertice_unref(result);
	
  /* Free the tree */
  osync_converter_tree_free(tree);
	
  osync_trace(TRACE_EXIT, "%s: %p", __func__, path);
  return path;

 error_free_tree:
  osync_converter_tree_free(tree);
 error:
  osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error));
  return NULL;
}
コード例 #13
0
static osync_bool osync_format_env_load_modules(OSyncFormatEnv *env, const char *path, osync_bool must_exist, OSyncError **error)
{
  GDir *dir = NULL;
  GError *gerror = NULL;
  char *filename = NULL;
  OSyncModule *module = NULL;
  const gchar *de = NULL;
  GList *m = NULL;
	
  osync_trace(TRACE_ENTRY, "%s(%p, %s, %i, %p)", __func__, env, path, must_exist, error);
  osync_assert(env);
  osync_assert(path);
	
  //Load all available shared libraries (plugins)
  if (!g_file_test(path, G_FILE_TEST_IS_DIR)) {
    if (must_exist) {
      osync_error_set(error, OSYNC_ERROR_GENERIC, "Path is not loadable");
      goto error;
    } else {
      osync_trace(TRACE_EXIT, "%s: Directory does not exist (non-fatal)", __func__);
      return TRUE;
    }
  }
	
  dir = g_dir_open(path, 0, &gerror);
  if (!dir) {
    osync_error_set(error, OSYNC_ERROR_IO_ERROR, "Unable to open directory %s: %s", path, gerror->message);
    g_error_free(gerror);
    goto error;
  }
	
  while ((de = g_dir_read_name(dir))) {
    filename = g_strdup_printf ("%s%c%s", path, G_DIR_SEPARATOR, de);
		
    if (!g_file_test(filename, G_FILE_TEST_IS_REGULAR) || !g_pattern_match_simple("*."G_MODULE_SUFFIX, filename)) {
      g_free(filename);
      continue;
    }
		
    module = osync_module_new(error);
    if (!module)
      goto error_free_filename;
		
    if (!osync_module_load(module, filename, error)) {
      osync_trace(TRACE_INTERNAL, "Unable to load module %s: %s", filename, osync_error_print(error));
      osync_module_free(module);
      g_free(filename);
      continue;
    }
		
    if (!osync_module_check(module, error)) {
      if (osync_error_is_set(error)) {
        osync_trace(TRACE_INTERNAL, "Module check error for %s: %s", filename, osync_error_print(error));
      }
      osync_module_free(module);
      g_free(filename);
      continue;
    }
	
    if (!osync_module_get_format_info(module, env, error) && !osync_module_get_function(module, "get_conversion_info", NULL)) {
      if (osync_error_is_set(error)) {
        osync_trace(TRACE_ERROR, "Module load format plugin error for %s: %s", filename, osync_error_print(error));
      }
      osync_error_set(error, OSYNC_ERROR_GENERIC, "Unable to load format plugin %s. Neither a converter nor a format could be initialized.", __NULLSTR(filename));
      osync_trace(TRACE_ERROR, "%s", osync_error_print(error));
      osync_module_free(module);
      g_free(filename);
      continue;
    }
		
    env->modules = g_list_append(env->modules, module);
		
    g_free(filename);
  }
	
  g_dir_close(dir);
	
  /* Load the converters, filters, etc */
  for (m = env->modules; m; m = m->next) {
    module = m->data;
    if (!osync_module_get_conversion_info(module, env, error)) {
      osync_trace(TRACE_INTERNAL, "Module get conversion error %s", osync_error_print(error));
      osync_error_unref(error);
    }
  }
	
  osync_trace(TRACE_EXIT, "%s", __func__);
  return TRUE;

 error_free_filename:
  g_free(filename);
  g_dir_close(dir);
 error:
  osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error));
  return FALSE;
}
コード例 #14
0
static osync_bool init(OSyncError **error) {
	OSyncPluginConfig *config;
	assert(!plugin);
	assert(!plugin_env);

	if (!(plugin_env = osync_plugin_env_new(error)))
		goto error;

	if (!(format_env = osync_format_env_new(error)))
		goto error_free_pluginenv;

	if (!osync_format_env_load_plugins(format_env, formatpath, error))
		goto error_free_formatenv;

	if (osync_error_is_set(error)) {
		fprintf(stderr, "WARNING! Some plugins couldn't get loaded in "
				"format plugin environment: %s\n", osync_error_print(error));
		osync_error_unref(error);
	}

	if (!osync_plugin_env_load(plugin_env, pluginpath, error))
		goto error_free_pluginenv;

	if (osync_error_is_set(error)) {
		fprintf(stderr, "WARNING! Some plugins couldn't get loaded in "
				"plugin environment: %s\n", osync_error_print(error));
		osync_error_unref(error);
	}

	if (!(plugin = osync_plugin_env_find_plugin(plugin_env, pluginname))) {
		osync_error_set(error, OSYNC_ERROR_PLUGIN_NOT_FOUND, "Plugin not found: \"%s\"", pluginname);
		goto error_free_pluginenv;
	}

	if (!(plugin_info = osync_plugin_info_new(error)))
		goto error_free_pluginenv;

	config = osync_plugin_config_new(error);
	if (!config)
		goto error_free_plugininfo;

	if (osync_plugin_get_config_type(plugin) != OSYNC_PLUGIN_NO_CONFIGURATION && configfile) {
		OSyncList *r = NULL;
		if (!osync_plugin_config_file_load(config, configfile, error))
			goto error_free_pluginconfig;

		osync_plugin_info_set_config(plugin_info, config);

		/** Redudant(aka. stolen) code from opensync/client/opensync_client.c */
		/* Enable active sinks */

		if (config)
			r = osync_plugin_config_get_resources(config);

		for (; r; r = r->next) {
			OSyncPluginResource *res = r->data;
			OSyncObjTypeSink *sink;

			const char *objtype = osync_plugin_resource_get_objtype(res); 
			OSyncList *o = NULL;
			/* Check for ObjType sink */
			if (!(sink = osync_plugin_info_find_objtype(plugin_info, objtype))) {
				sink = osync_objtype_sink_new(objtype, error);
				if (!sink)
					goto error_free_pluginconfig;

				osync_plugin_info_add_objtype(plugin_info, sink);
			}
			OSyncList *objformats = osync_plugin_resource_get_objformat_sinks(res);
			for ( o = objformats; o; o = o->next) {
				OSyncObjFormatSink *format_sink = (OSyncObjFormatSink *) o->data; 
				osync_objtype_sink_add_objformat_sink(sink, format_sink);
			}
			osync_list_free(objformats);
		}

		osync_plugin_config_unref(config);

	}

	if (!configfile && osync_plugin_get_config_type(plugin) == OSYNC_PLUGIN_NEEDS_CONFIGURATION) {
		osync_error_set(error, OSYNC_ERROR_MISCONFIGURATION, "Plugin \"%s\" requires configuration!", pluginname); 
		goto error_free_pluginconfig;
	}

	assert(!ctx);
	ctx = g_main_context_new();

	osync_plugin_info_set_configdir(plugin_info, configdir);
	osync_plugin_info_set_loop(plugin_info, ctx);
	osync_plugin_info_set_format_env(plugin_info, format_env);
	osync_plugin_info_set_groupname(plugin_info, syncgroup);

	return TRUE;

	/*
		error_free_loop:
		g_main_context_unref(ctx);
	*/
 error_free_pluginconfig:
	osync_plugin_config_unref(config);
 error_free_plugininfo:
	osync_plugin_info_unref(plugin_info);
 error_free_formatenv:
	osync_format_env_unref(format_env);
	format_env = NULL;
 error_free_pluginenv:
	osync_plugin_env_unref(plugin_env);
	plugin_env = NULL;
 error:	
	return FALSE;
}