コード例 #1
0
/*! @brief Check if group configuration is up to date. 
 * 
 * @param group The group
 * @returns TRUE if the group configuration is up to date, FALSE otherwise. 
 */
osync_bool osync_group_is_uptodate(OSyncGroup *group)
{
  xmlDocPtr doc = NULL;
  xmlNodePtr cur = NULL;
  OSyncError *error = NULL;
  unsigned int version_major;
  unsigned int version_minor;
  xmlChar *version_str = NULL;
  osync_bool uptodate = FALSE;
  char *config = NULL; 
  const char *configdir = NULL;

  osync_assert(group);
  osync_trace(TRACE_ENTRY, "%s(%p)", __func__, group);
        
  configdir = osync_group_get_configdir(group);
  if (!configdir){
    osync_trace(TRACE_EXIT, "%s(%p) - No configdir set", __func__, group);
    return FALSE;
  }

  config = g_strdup_printf("%s%c%s",
                           configdir,
                           G_DIR_SEPARATOR, "syncgroup.conf");
	
  /* If syncgroup isn't present, we assume that update is required. */
  if (!osync_xml_open_file(&doc, &cur, config, "syncgroup", &error)) {
    osync_trace(TRACE_ERROR, "%s: %s", __func__, osync_error_print(&error));
    osync_error_unref(&error);
    goto end;
  }

  version_str = xmlGetProp(cur->parent, (const xmlChar *)"version");

  /* No version node, means very outdated version. */
  if (!version_str)
    goto end;

  sscanf((const char *) version_str, "%u.%u", &version_major, &version_minor);

  osync_trace(TRACE_INTERNAL, "Version: %s (current %u.%u required %u.%u)",
              version_str, version_major, version_minor, 
              OSYNC_GROUP_MAJOR_VERSION, OSYNC_GROUP_MINOR_VERSION ); 

  if (OSYNC_GROUP_MAJOR_VERSION == version_major 
      && OSYNC_GROUP_MINOR_VERSION == version_minor)
    uptodate = TRUE;

  osync_xml_free(version_str);
 end:
  g_free(config);

  if (doc)
    osync_xml_free_doc(doc);

  osync_trace(TRACE_EXIT, "%s(%p)", __func__, group);
  return uptodate;
}
コード例 #2
0
OSyncCapabilitiesObjType *osync_capabilities_objtype_parse_and_add(OSyncCapabilities *capabilities, xmlNode *node, OSyncError **error)
{
	xmlChar *objtype;
	xmlNode *cur;
	OSyncCapability *cap = NULL;
	OSyncCapabilitiesObjType *capobjtype = NULL;
	osync_assert(capabilities);
	osync_assert(node);

	osync_assert(!xmlStrcmp(node->name, (const xmlChar *)"ObjType"));
	objtype = xmlGetProp(node, (const xmlChar *)"Name");

	/* XXX: Bad cast from unsigned char* to const char* - is there a better way? */
	if (!(capobjtype = osync_capabilities_objtype_new((const char *) objtype, error)))
		goto error;

	osync_xml_free(objtype);

	cur = node->children;
	for(; cur != NULL; cur = cur->next) {

		if (cur->type != XML_ELEMENT_NODE)
			continue;

		if (!(cap = osync_capability_parse_and_add(capobjtype, cur, error))) {
			goto error;
		}
		else {
			// we don't need our copy of the capability
			osync_capability_unref(cap);
		}
	}

	osync_capabilities_add_objtype(capabilities, capobjtype);

	return capobjtype;

error:
	osync_xml_free(objtype);
	if (capobjtype)
		osync_capabilities_objtype_unref(capobjtype);

	osync_trace(TRACE_EXIT_ERROR, "%s: %s" , __func__, osync_error_print(error));
	return NULL;
}
コード例 #3
0
/*! @brief Loads a group from a directory
 * 
 * Loads a group from a directory
 * 
 * @param group The group object to load into
 * @param path The path to the config directory of the group
 * @param error Pointer to an error struct
 * @returns TRUE on success, FALSE otherwise
 * 
 */
osync_bool osync_group_load(OSyncGroup *group, const char *path, OSyncError **error)
{
  char *filename = NULL;
  char *real_path = NULL;
  xmlDocPtr doc;
  xmlNodePtr cur;
  //xmlNodePtr filternode;
	
  osync_assert(group);
  osync_assert(path);
  osync_trace(TRACE_ENTRY, "%s(%p, %s, %p)", __func__, group, path, error);
	
  if (!g_path_is_absolute(path)) {
    char *curdir = g_get_current_dir();
    real_path = g_strdup_printf("%s%c%s", curdir, G_DIR_SEPARATOR, path);
    g_free(curdir);
  } else {
    real_path = g_strdup(path);
  }
	
  osync_group_set_configdir(group, real_path);
  filename = g_strdup_printf("%s%csyncgroup.conf", real_path, G_DIR_SEPARATOR);
  g_free(real_path);
	
  if (!osync_xml_open_file(&doc, &cur, filename, "syncgroup", error)) {
    g_free(filename);
    goto error;
  }
  g_free(filename);
	
  while (cur != NULL) {
    char *str = (char*)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
    if (str) {
      if (!xmlStrcmp(cur->name, (const xmlChar *)"groupname"))
        osync_group_set_name(group, str);
	
      if (!xmlStrcmp(cur->name, (const xmlChar *)"last_sync"))
        group->last_sync = (time_t)atoi(str);
			
      //TODO: remove the next 2 lines later
      if (!xmlStrcmp(cur->name, (const xmlChar *)"enable_merger"))
        group->merger_enabled = (!g_ascii_strcasecmp("true", str)) ? TRUE : FALSE;
      //TODO: remove the next 2 lines later
      if (!xmlStrcmp(cur->name, (const xmlChar *)"enable_converter"))
        group->converter_enabled = (!g_ascii_strcasecmp("true", str)) ? TRUE : FALSE;

      if (!xmlStrcmp(cur->name, (const xmlChar *)"merger_enabled"))
        group->merger_enabled = (!g_ascii_strcasecmp("true", str)) ? TRUE : FALSE;

      if (!xmlStrcmp(cur->name, (const xmlChar *)"converter_enabled"))
        group->converter_enabled = (!g_ascii_strcasecmp("true", str)) ? TRUE : FALSE;

      // TODO: reimplement the filter!
      /*if (!xmlStrcmp(cur->name, (const xmlChar *)"filter")) {
        filternode = cur->xmlChildrenNode;
        OSyncFilter *filter = osync_filter_new();
        filter->group = group;
				
        while (filternode != NULL) {
        if (!xmlStrcmp(filternode->name, (const xmlChar *)"sourceobjtype"))
        filter->sourceobjtype = (char*)xmlNodeListGetString(doc, filternode->xmlChildrenNode, 1);
					
        if (!xmlStrcmp(filternode->name, (const xmlChar *)"destobjtype"))
        filter->destobjtype = (char*)xmlNodeListGetString(doc, filternode->xmlChildrenNode, 1);
					
        if (!xmlStrcmp(filternode->name, (const xmlChar *)"detectobjtype"))
        filter->detectobjtype = (char*)xmlNodeListGetString(doc, filternode->xmlChildrenNode, 1);
					
        if (!xmlStrcmp(filternode->name, (const xmlChar *)"config"))
        filter->config = (char*)xmlNodeListGetString(doc, filternode->xmlChildrenNode, 1);
					
        if (!xmlStrcmp(filternode->name, (const xmlChar *)"function_name")) {
        char *str = (char*)xmlNodeListGetString(doc, filternode->xmlChildrenNode, 1);
        if (!str) {
        filternode = filternode->next;
        continue;
        }
        osync_filter_update_hook(filter, group, str);
        osync_xml_free(str);
        }
					
        if (!xmlStrcmp(filternode->name, (const xmlChar *)"sourcemember")) {
        char *str = (char*)xmlNodeListGetString(doc, filternode->xmlChildrenNode, 1);
        if (!str) {
        filternode = filternode->next;
        continue;
        }
        filter->sourcememberid = atoll(str);
        osync_xml_free(str);
        }
					
        if (!xmlStrcmp(filternode->name, (const xmlChar *)"destmember")) {
        char *str = (char*)xmlNodeListGetString(doc, filternode->xmlChildrenNode, 1);
        if (!str) {
        filternode = filternode->next;
        continue;
        }
        filter->destmemberid = atoll(str);
        osync_xml_free(str);
        }
					
        if (!xmlStrcmp(filternode->name, (const xmlChar *)"action")) {
        char *str = (char*)xmlNodeListGetString(doc, filternode->xmlChildrenNode, 1);
        if (!str) {
        filternode = filternode->next;
        continue;
        }
        filter->action = atoi(str);
        osync_xml_free(str);
        }
        filternode = filternode->next;
        }
        osync_filter_register(group, filter);
        }*/
		
      osync_xml_free(str);
    }
    cur = cur->next;
  }
  osync_xml_free_doc(doc);
	
  /* Check for sanity */
  if (!group->name) {
    osync_error_set(error, OSYNC_ERROR_MISCONFIGURATION, "Loaded a group without a name");
    goto error;
  }
	
  if (!_osync_group_load_members(group, group->configdir, error))
    goto error;
	
  osync_trace(TRACE_EXIT, "%s: %p", __func__, group);
  return TRUE;

 error:
  osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error));
  return FALSE;
}