From: <svn...@op...> - 2009-03-30 18:23:23
|
Author: scriptor Date: Mon Mar 30 20:23:10 2009 New Revision: 5467 URL: http://www.opensync.org/changeset/5467 Log: Fixed 'ERROR: Could not find any node, where to add "AlarmAction"'. Modified: plugins/ldap-sync/src/ldap_connect.c plugins/ldap-sync/src/ldap_debug.c plugins/ldap-sync/src/ldap_format.c plugins/ldap-sync/src/ldap_format.h plugins/ldap-sync/src/ldap_plugin.c plugins/ldap-sync/src/ldap_plugin.h Modified: plugins/ldap-sync/src/ldap_connect.c ============================================================================== --- plugins/ldap-sync/src/ldap_connect.c Mon Mar 30 17:16:11 2009 (r5466) +++ plugins/ldap-sync/src/ldap_connect.c Mon Mar 30 20:23:10 2009 (r5467) @@ -1794,10 +1794,20 @@ // --------------------------------------------------------------- /* Search all entries that apply to the filter */ if (!ldap_plugin_call_ldap_search(ctx, sinkenv->ld, base, filter, LDAP_SCOPE_ONELEVEL, USER_ATTRIBUTES, sinkenv, &all_results, error)) { + int result_code = 0; + + if (!osync_error_is_set(error)) { osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: ldap_plugin_call_ldap_search() has failed.\n", __FILE__, __LINE__); } + + ldap_get_option(sinkenv->ld, LDAP_OPT_RESULT_CODE, &result_code); + if (result_code == LDAP_NO_SUCH_OBJECT) { + ldap_plugin_printf("%s:%i: Either the searchbase (\"%s\") is really wrong, or the user does not have sufficient access permissions to this particular part of the DIT.", __FILE__, __LINE__, base); + } + + goto error; } @@ -1904,7 +1914,6 @@ osync_context_report_osyncwarning(ctx, *error); osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); - osync_error_unref(error); return FALSE; } @@ -1996,7 +2005,6 @@ osync_context_report_osyncwarning(ctx, *error); osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); - osync_error_unref(error); return FALSE; } @@ -3080,7 +3088,6 @@ osync_context_report_osyncwarning(ctx, *error); osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); - osync_error_unref(error); return FALSE; } Modified: plugins/ldap-sync/src/ldap_debug.c ============================================================================== --- plugins/ldap-sync/src/ldap_debug.c Mon Mar 30 17:16:11 2009 (r5466) +++ plugins/ldap-sync/src/ldap_debug.c Mon Mar 30 20:23:10 2009 (r5467) @@ -340,7 +340,9 @@ /** * @brief Prints the contents of an LDAP entry to the screen. * Mainly for debugging purposes + * * @param ldapdata An LDAP entry. + * * @returns Nothing. */ Modified: plugins/ldap-sync/src/ldap_format.c ============================================================================== --- plugins/ldap-sync/src/ldap_format.c Mon Mar 30 17:16:11 2009 (r5466) +++ plugins/ldap-sync/src/ldap_format.c Mon Mar 30 20:23:10 2009 (r5467) @@ -1086,7 +1086,7 @@ * @returns TRUE on success, FALSE in case of any errors. */ -static osync_bool ldap_format_parse_subentry(const xmlNode *xmlnode, const gchar *dn, complex_elements *element_lists, GList **ldap_entries, OSyncError **error) +static osync_bool ldap_format_parse_xml_subentry(const xmlNode *xmlnode, const gchar *dn, complex_elements *element_lists, GList **ldap_entries, OSyncError **error) { xmlChar *name = NULL; xmlChar *value = NULL; @@ -1127,6 +1127,8 @@ goto error; } + + name = (xmlChar *)xmlnode->name; if (name == NULL) { osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: name = NULL.\n", __FILE__, __LINE__); @@ -1207,7 +1209,7 @@ new_id = g_strdup_printf("%s", name); - // Regular cases: All the other cases. + // Regular cases of subentries: // name must be different from those special cases: if ( strncmp((char *)name, "TimezoneRule", 12) && @@ -1247,10 +1249,6 @@ osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: value = NULL.\n", __FILE__, __LINE__); goto error; } - - if (value[0] == 0) { - osync_trace(TRACE_ERROR, "%s:%i: WARNING: value[0] = 0; name = \"%s\". Ignoring.", __FILE__, __LINE__, name); - } } @@ -1258,6 +1256,13 @@ ldapmods_subentry = ldap_format_append_ldapmod(ldapmods_subentry, (gchar *)"objectClass", (gchar *)"organizationalUnit"); +#if 1 + // xxx jl: Wasn't here before... + if (name && name[0]) { + ldapmods_subentry = ldap_format_append_ldapmod(ldapmods_subentry, (gchar *)"ou", (gchar *)name); + } +#endif + if (value && value[0]) { ldapmods_subentry = ldap_format_append_ldapmod(ldapmods_subentry, (gchar *)"description", (gchar *)value); xmlFree(value); @@ -1340,7 +1345,7 @@ } - // Special cases: "TimezoneRule" and "TimezoneComponent". + // Special cases: 2nd level: "TimezoneRule", "TimezoneComponent" etc. if ( !strncmp((char *)name, "TimezoneRule", 12) || !strncmp((char *)name, "TimezoneComponent", 17) || @@ -2647,7 +2652,11 @@ node = root_node->xmlChildrenNode; - while(node) { +#ifdef DEBUG_convert_ldap2xmlinternal + osync_trace(TRACE_INTERNAL, "%s:%i: XML children node = %p", __FILE__, __LINE__, node); +#endif + + while (node) { xmlNode *node2 = NULL; @@ -2656,16 +2665,26 @@ continue; } +#ifdef DEBUG_convert_ldap2xmlinternal + osync_trace(TRACE_INTERNAL, "node->name = \"%s\"", node->name); +#endif if (xmlStrcmp(node->name, (xmlChar *)"subentry")) { node = node->next; continue; } +#ifdef DEBUG_convert_ldap2xmlinternal + ldap_plugin_printf("Subentry found with name = \"%s\"", name); +#endif + // OK. We have found a subentry. node2 = node->xmlChildrenNode; if (!node2) { +#ifdef DEBUG_convert_ldap2xmlinternal + osync_trace(TRACE_INTERNAL, "%s:%i: WARNING: node2 = NULL. There is no XML children node.", __FILE__, __LINE__); +#endif node = node->next; continue; } @@ -2677,18 +2696,20 @@ continue; } - +#if 0 #ifdef DEBUG_convert_ldap2xmlinternal - ldap_plugin_printf("%s:%i: node2->name = \"%s\"", __FILE__, __LINE__, node2->name); + ldap_plugin_printf("%s:%i:", __FILE__, __LINE__); + ldap_plugin_printf("token = \"%s\"", token); + ldap_plugin_printf("node2->name = \"%s\"", node2->name); +#endif #endif - if (g_strstr_len((gchar *)token, -1, (gchar *)node2->name)) { possible_parent = node2; } node = node->next; - } + } // while(node) if (possible_parent) { @@ -2713,6 +2734,241 @@ + +/** + * @brief This function parses the list of LDAP attributes of an LDAP entry + * that is called a subentry throughout this plugin. This prepares + * for generating an XML element. + * + * @param entry_list_index This is the index in the GList holding all the + * different LDAP entries of a complete subtree + * in the LDAP DIT. 0 means, it is the base entry + * of this subtree. + * @param mod This is an LDAPMod struct an ldap_entry struct. It holds + * one LDAP attribute and its value. + * @param name This variable gets filled with what will be the name + * of an XML element. + * @param value This variable gets filled with what will be the value + * (or the content) of an XML element. + * @param attr1_name This variable gets filled with what will be the + * name of the first XML attribute of an XML element. + * @param attr1_value This variable gets filled with what will be the + * value of the first XML attribute of an XML element. + * @param attr2_name This variable gets filled with what will be the + * name of the second XML attribute of an XML element. + * @param attr2_value This variable gets filled with what will be the + * value of the second XML attribute of an XML element. + * @param call_continue This variable gets filled with whether the caller + * should call continue in the list of mods and + * advance to the next mod of an LDAP entry. + * @param error The libopensync error pointer. + * + * @returns TRUE on success, FALSE in case of any error + */ + +osync_bool ldap_plugin_parse_attribute_list(const int entry_list_index, const LDAPMod *mod, xmlChar **name, xmlChar **value, xmlChar **attr1_name, xmlChar **attr1_value, xmlChar **attr2_name, xmlChar **attr2_value, osync_bool *call_continue, OSyncError **error) +{ + osync_trace(TRACE_ENTRY, "%s(%i, %p, %p, %p, %p, %p, %p, %p, %p)", __func__, index, mod, name, value, attr1_name, attr1_value, attr2_name, attr2_value, call_continue, error); + + + if (mod == NULL) { + osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: mod = NULL.", __FILE__, __LINE__); + goto error; + } + + if (name == NULL) { + osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: name = NULL.", __FILE__, __LINE__); + goto error; + } + + if (value == NULL) { + osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: value = NULL.", __FILE__, __LINE__); + goto error; + } + + if (attr1_name == NULL) { + osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: attr1_name = NULL.", __FILE__, __LINE__); + goto error; + } + + if (attr1_value == NULL) { + osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: attr1_value = NULL.", __FILE__, __LINE__); + goto error; + } + + if (attr2_name == NULL) { + osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: attr2_name = NULL.", __FILE__, __LINE__); + goto error; + } + + if (attr2_value == NULL) { + osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: attr2_value = NULL.", __FILE__, __LINE__); + goto error; + } + + if (call_continue == NULL) { + osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: call_continue = NULL.", __FILE__, __LINE__); + goto error; + } + + if (mod->mod_type == NULL) { + osync_trace(TRACE_ERROR, "%s:%i: ERROR: mod->mod_type = NULL.", __FILE__, __LINE__); + goto error; + } + + if (mod->mod_bvalues == NULL) { + osync_trace(TRACE_ERROR, "%s:%i: ERROR: mod->mod_bvalues = NULL.", __FILE__, __LINE__); + goto error; + } + + + + if (entry_list_index == 0) { + // This is the base entry. Its attribute name ("description") is + // at the same time the name of the XML element + *name = xmlStrdup((xmlChar *)mod->mod_type); + *value = xmlStrdup((xmlChar *)mod->mod_bvalues[0]->bv_val); + + } else { + // This is one of the subentries. They have all the objectClass + // "organizationalUnit". The attribute names MUST NOT be + // taken literally. In fact, "ou", "description", "postalAddress" + // "physicalDeliveryOfficeName", "registeredAddress" and + // "street" are shamelessly being abused for storing + // name and value of an XML element, and additionally + // of any possible first and second XML attribute. + if (!strcmp(mod->mod_type, "objectClass") || !strcmp(mod->mod_type, "objectclass")) { + // Not needed in XML document. + *call_continue = TRUE; + + // "ou" holds the name of an XML element plus a possible counter suffix. + // This suffix has to be cut off before adding to the XML tree. + // With an LDAP entry, however, each LDAP attribute must be unique. + // And the counter was necessary to enforce such uniqueness. + } else if (!strcmp(mod->mod_type, "ou")) { + char *n = mod->mod_bvalues[0]->bv_val; + + + if (!strncmp((char *)n, "TimezoneRule", 12)) { + *name = xmlStrdup((xmlChar *)"TimezoneRule"); + *value = xmlStrdup((xmlChar *)""); + } else if (!strncmp((char *)n, "TimezoneComponent", 17)) { + *name = xmlStrdup((xmlChar *)"TimezoneComponent"); + *value = xmlStrdup((xmlChar *)""); + } else if (!strncmp((char *)n, "postalAddress", 13)) { + *name = xmlStrdup((xmlChar *)"postalAddress"); + *value = xmlStrdup((xmlChar *)""); + } else if (!strncmp((char *)n, "AlarmAudio", 10)) { + *name = xmlStrdup((xmlChar *)"AlarmAudio"); + *value = xmlStrdup((xmlChar *)""); + } else if (!strncmp((char *)n, "AlarmDisplay", 12)) { + *name = xmlStrdup((xmlChar *)"AlarmDisplay"); + *value = xmlStrdup((xmlChar *)""); + } else if (!strncmp((char *)n, "AlarmEmail", 10)) { + *name = xmlStrdup((xmlChar *)"AlarmEmail"); + *value = xmlStrdup((xmlChar *)""); + } else if (!strncmp((char *)n, "AlarmProcedure", 14)) { + *name = xmlStrdup((xmlChar *)"AlarmProcedure"); + *value = xmlStrdup((xmlChar *)""); + } else if (!strncmp((char *)n, "RecurrenceRule", 14)) { + *name = xmlStrdup((xmlChar *)"RecurrenceRule"); + *value = xmlStrdup((xmlChar *)""); + } else if (!strncmp((char *)n, "RecurrenceRuleExtended", 22)) { + *name = xmlStrdup((xmlChar *)"RecurrenceRuleExtended"); + *value = xmlStrdup((xmlChar *)""); + } else if (!strncmp((char *)n, "AddressLabel", 12)) { + *name = xmlStrdup((xmlChar *)"AddressLabel"); + *value = xmlStrdup((xmlChar *)""); + } else if (!strncmp((char *)n, "Address", 7)) { + *name = xmlStrdup((xmlChar *)"Address"); + *value = xmlStrdup((xmlChar *)""); + } else { + *name = xmlStrdup((xmlChar *)(mod->mod_bvalues[0]->bv_val)); + } + + // EMail MUST NOT be set here. Rather it must be treated as + // as regular case. But its counter must also be cut off... + // We do it later... + + // Same is true for AddressLabel + + // And for Telephone. + + + // "description" holds the value of an XML element. + } else if (!strcmp(mod->mod_type, "description")) { + if ((xmlChar *)mod->mod_bvalues[0]->bv_val) { + *value = xmlStrdup((xmlChar *)mod->mod_bvalues[0]->bv_val); + } else { + *value = xmlStrdup((xmlChar *)""); + } + + // "postalAddress" holds the name of the first XML attribute + // of an XML element + } else if (!strcmp(mod->mod_type, "postalAddress")) { + *attr1_name = xmlStrdup((xmlChar *)mod->mod_bvalues[0]->bv_val); + + // "physicalDeliveryOfficeName" holds the value of the + // first XML attribute of an XML element + } else if (!strcmp(mod->mod_type, "physicalDeliveryOfficeName")) { + *attr1_value = xmlStrdup((xmlChar *) mod->mod_bvalues[0]->bv_val); + + // "registeredAddress" holds the name of the + // second XML attribute of an XML element + } else if (!strcmp(mod->mod_type, "registeredAddress")) { + *attr2_name = xmlStrdup((xmlChar *) mod->mod_bvalues[0]->bv_val); + + // "street" holds the value of second XML attribute of an XML element. + } else if (!strcmp(mod->mod_type, "street")) { + *attr2_value = xmlStrdup((xmlChar *) mod->mod_bvalues[0]->bv_val); + + } else if (!strcmp(mod->mod_type, "DateTimeStart")) { + *call_continue = TRUE; + + } else if (!strcmp(mod->mod_type, "TZName")) { + *call_continue = TRUE; + + } else if (!strcmp(mod->mod_type, "TZOffsetFrom")) { + *call_continue = TRUE; + + } else if (!strcmp(mod->mod_type, "TZOffsetTo")) { + *call_continue = TRUE; + + } else if (!strcmp(mod->mod_type, "Frequency")) { + *call_continue = TRUE; + + } else if (!strcmp(mod->mod_type, "Count")) { + *call_continue = TRUE; + + } else if (!strcmp(mod->mod_type, "Interval")) { + *call_continue = TRUE; + + } else if (!strcmp(mod->mod_type, "ByDay")) { + *call_continue = TRUE; + + } else { + *call_continue = TRUE; + } + + } // if (entry_list_index == 0) + + + + osync_trace(TRACE_EXIT, "%s()", __func__); + return TRUE; + +error: + if (!osync_error_is_set(error)) + osync_error_set(error, OSYNC_ERROR_GENERIC, "Unknown reason.\n"); + + osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); + return FALSE; +} + + + + + /** * @brief This function converts a list of LDAP entries into an XML document. * @@ -2865,7 +3121,10 @@ #ifdef DEBUG_convert_ldap2xmlinternal + ldap_plugin_printf("Input:"); + ldap_plugin_dump_ldap_attributes(entry); ldap_plugin_printf("-----------------"); + ldap_plugin_printf("Parsing:"); ldap_plugin_printf("id = %s", entry->id); ldap_plugin_printf("dn = %s", entry->dn); #endif @@ -2876,151 +3135,79 @@ continue; } + + + // Add each LDAP entry (= base entry and its children) by looping // through all of the LDAP attributes xmlChar *name = NULL; xmlChar *value = NULL; - const xmlChar *attr1_name = NULL; - const xmlChar *attr1_value = NULL; - const xmlChar *attr2_name = NULL; - const xmlChar *attr2_value = NULL; + xmlChar *attr1_name = NULL; + xmlChar *attr1_value = NULL; + xmlChar *attr2_name = NULL; + xmlChar *attr2_value = NULL; + osync_bool first_level_still_to_be_added = FALSE; + for (j = 0 ; entry->mods[j] ; j++) { LDAPMod *mod = NULL; + osync_bool call_continue = FALSE; +#ifdef DEBUG_convert_ldap2xmlinternal + ldap_plugin_printf("j = %i", j); +#endif + mod = entry->mods[j]; if (mod == NULL) { - osync_trace(TRACE_ERROR, "%s:%i: ERROR: mod = NULL. Skipping this ldap entry.\n", __FILE__, __LINE__); - break; - } - - - if (mod->mod_type == NULL) { - osync_trace(TRACE_ERROR, "%s:%i: ERROR: mod->mod_type = NULL. Skipping this ldap entry.\n", __FILE__, __LINE__); - break; + osync_trace(TRACE_ERROR, "%s:%i: ERROR: mod = NULL. Skipping this LDAP attribute.\n", __FILE__, __LINE__); + continue; } + + // Actually, this would have been the function that would have had + // to advance in the list of mods, if appropriate - as it is for + // a subentry, for example. So that ALL of those names/values + // would have been defined. + if (!ldap_plugin_parse_attribute_list(i, mod, &name, &value, &attr1_name, &attr1_value, &attr2_name, &attr2_value, &call_continue, error)) { + if (!osync_error_is_set(error)) { + osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: %s:%i: ldap_plugin_parse_attribute_list() has failed.", __FILE__, __LINE__); + } - if (mod->mod_bvalues == NULL) { - osync_trace(TRACE_ERROR, "%s:%i: ERROR: mod->mod_bvalues = NULL. Skipping this ldap entry.\n", __FILE__, __LINE__); - break; + goto error; } - k = 0; // k = 1 would be the terminating NULL - { - if (i == 0) { - // This is the base entry. Its attribute name ("description") is - // at the same time the name of the XML element - name = (xmlChar *)mod->mod_type; - value = (xmlChar *)mod->mod_bvalues[k]->bv_val; - - } else { - // This is one of the subentries. They have all the objectClass - // "organizationalUnit". The attribute names MUST NOT be - // taken literally. In fact, "ou", "description", "postalAddress" - // "physicalDeliveryOfficeName", "registeredAddress" and - // "street" are shamelessly being abused for storing - // name and value of an XML element, and additionally - // of any possible first and second XML attribute. - if (!strcmp(mod->mod_type, "objectClass") || !strcmp(mod->mod_type, "objectclass")) { - // Not needed in XML document. - continue; - - } else if (!strcmp(mod->mod_type, "ou")) { - name = (xmlChar *)mod->mod_bvalues[k]->bv_val; - - // Cut off any counter suffixes that may have been added - // to allow insertion into a typical LDAP DIT. - if (!strncmp((char *)name, "TimezoneRule", 12)) { - name = (xmlChar *)"TimezoneRule"; - value = (xmlChar *)""; - } else if (!strncmp((char *)name, "TimezoneComponent", 17)) { - name = (xmlChar *)"TimezoneComponent"; - value = (xmlChar *)""; - } else if (!strncmp((char *)name, "postalAddress", 13)) { - name = (xmlChar *)"postalAddress"; - value = (xmlChar *)""; - } else if (!strncmp((char *)name, "AlarmAudio", 10)) { - name = (xmlChar *)"AlarmAudio"; - value = (xmlChar *)""; - } else if (!strncmp((char *)name, "AlarmDisplay", 12)) { - name = (xmlChar *)"AlarmDisplay"; - value = (xmlChar *)""; - } else if (!strncmp((char *)name, "AlarmEmail", 10)) { - name = (xmlChar *)"AlarmEmail"; - value = (xmlChar *)""; - } else if (!strncmp((char *)name, "AlarmProcedure", 14)) { - name = (xmlChar *)"AlarmProcedure"; - value = (xmlChar *)""; - } else if (!strncmp((char *)name, "RecurrenceRule", 14)) { - name = (xmlChar *)"RecurrenceRule"; - value = (xmlChar *)""; - } else if (!strncmp((char *)name, "RecurrenceRuleExtended", 22)) { - name = (xmlChar *)"RecurrenceRuleExtended"; - value = (xmlChar *)""; - } else if (!strncmp((char *)name, "AddressLabel", 12)) { - name = (xmlChar *)"AddressLabel"; - - } else if (!strncmp((char *)name, "Address", 7)) { - name = (xmlChar *)"Address"; - value = (xmlChar *)""; - } - - // EMail MUST NOT be set here. Rather it must be treated as - // as regular case. But its counter must also be cut off... - // We do it later... - - // Same is true for AddressLabel - - // And for Telephone. - - } else if (!strcmp(mod->mod_type, "description")) { - if ((xmlChar *)mod->mod_bvalues[k]->bv_val) { - value = (xmlChar *)mod->mod_bvalues[k]->bv_val; - } else { - value = (xmlChar *)""; - } - - } else if (!strcmp(mod->mod_type, "postalAddress")) { - attr1_name = (xmlChar *)mod->mod_bvalues[k]->bv_val; - - } else if (!strcmp(mod->mod_type, "physicalDeliveryOfficeName")) { - attr1_value = (xmlChar *) mod->mod_bvalues[k]->bv_val; - - } else if (!strcmp(mod->mod_type, "registeredAddress")) { - attr2_name = (xmlChar *) mod->mod_bvalues[k]->bv_val; + if (call_continue) { + continue; + } - } else if (!strcmp(mod->mod_type, "street")) { - attr2_value = (xmlChar *) mod->mod_bvalues[k]->bv_val; + if (name == NULL) { + continue; + } - } else if (!strcmp(mod->mod_type, "DateTimeStart")) { - continue; - } else if (!strcmp(mod->mod_type, "TZName")) { - continue; - } else if (!strcmp(mod->mod_type, "TZOffsetFrom")) { - continue; - } else if (!strcmp(mod->mod_type, "TZOffsetTo")) { - continue; - } else if (!strcmp(mod->mod_type, "Frequency")) { - continue; - } else if (!strcmp(mod->mod_type, "Count")) { - continue; - } else if (!strcmp(mod->mod_type, "Interval")) { - continue; - } else if (!strcmp(mod->mod_type, "ByDay")) { - continue; - } + if (attr1_name && (attr1_value == NULL)) { + continue; + } + + if (attr1_value && (attr1_name == NULL)) { + continue; + } - } // if (i == 0) - } // for (k = 0; mod->mod_bvalues[k]; k++) + if (attr2_name && (attr2_value == NULL)) { + continue; + } + if (attr2_value && (attr2_name == NULL)) { + continue; + } #ifdef DEBUG_convert_ldap2xmlinternal if (name) { ldap_plugin_printf("name = %s", name); + } else { + ldap_plugin_printf("name = NULL."); } if (value) { @@ -3048,6 +3235,7 @@ if (name == NULL) { + osync_trace(TRACE_ERROR, "%s:%i: ERROR: name = NULL. i = %u, j = %u, k = %u. Continuing.\n", __FILE__, __LINE__, i, j, k); continue; } @@ -3059,19 +3247,46 @@ // Hmmm. value = NULL does NOT ALWAYS seem to be a problem. Strange... + // 30.03.2009: Well, it IS a problem. It CAN lead to + // "...ERROR: Could not find any node, where to add..." in + // ldap_format_add_xml_subsubentry(). if (value == NULL) { + #ifdef DEBUG_convert_ldap2xmlinternal osync_trace(TRACE_INTERNAL, "%s:%i: WARNING: value = NULL. name = \"%s\". i = %u, j = %u, k = %u. Continuing.\n", __FILE__, __LINE__, name, i, j, k); +// osync_trace(TRACE_INTERNAL, "%s:%i: WARNING: value = NULL. name = \"%s\". i = %u, j = %u, k = %u. We set value to an empty string and proceed instead of continueing.\n", __FILE__, __LINE__, name, i, j, k); #endif + continue; + + // This is NOT correct, if it were a sub-sub entry. + // It is correct ONLY, if it is a sub entry. + // value = (xmlChar *)""; } // Add the name - value pairs to the XML document. if (i == 0) { + +#ifdef DEBUG_convert_ldap2xmlinternal + ldap_plugin_printf("\n\n\nBase entry is about to be added: \"%s\"\n\n\n", name); +#endif + // Then this is the LDAP base entry. // Add the node to the parent. xmlNewTextChild(root_node, NULL, name, value); + if (name) { + xmlFree(name); + name = NULL; + } + + if (value) { + xmlFree(value); + value = NULL; + } + + continue; + } else { // Then this is one of the subentries. @@ -3129,7 +3344,7 @@ if (name) { if (name[0]) { if (!strncmp((char *)name, "EMail", 5)) { - name = (xmlChar *)"EMail"; + name = xmlStrdup((xmlChar *)"EMail"); } } } @@ -3140,33 +3355,48 @@ if (name) { if (name[0]) { if (!strncmp((char *)name, "AddressLabel", 12)) { - name = (xmlChar *)"AddressLabel"; + name = xmlStrdup((xmlChar *)"AddressLabel"); } } } + // Telephone: Likewise. Oh, dear. I have to // rewrite that mess eventually. if (name) { if (name[0]) { if (!strncmp((char *)name, "Telephone", 9)) { - name = (xmlChar *)"Telephone"; + name = xmlStrdup((xmlChar *)"Telephone"); } } } - // One of those irregular cases (second level...) + + // Now, finally add that entry to the XML tree. + + // Second level: One of those irregular cases if (where && where != entry->dn) { +#ifdef DEBUG_convert_ldap2xmlinternal + ldap_plugin_printf("\n\n\nSecond level (irregular case) is about to be added: \"%s\"\n\n\n", name); +#endif // char *token = strtok_r(where, ",", &saveptr); // strtok_r() is POSIX.1-2001, but not C99. char *token = strtok(where, ","); + if (token == NULL) { osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: token = NULL.\n", __FILE__, __LINE__); goto error; } + + if (value == NULL || value == (xmlChar *)"") { + osync_trace(TRACE_INTERNAL, "%s:%i: value is empty with name = \"%s\". Continuing.", __FILE__, __LINE__, name); + continue; + } + +#if 0 #ifdef DEBUG_convert_ldap2xmlinternal if (token) { ldap_plugin_printf("\n\ntoken = \"%s\"", token); @@ -3177,6 +3407,7 @@ ldap_plugin_printf("entry->id = \"%s\"", entry->id); ldap_plugin_printf("\n"); #endif +#endif if (!ldap_format_add_xml_subsubentry(root_node, (xmlChar *)token, name, value, attr1_name, attr1_value, attr2_name, attr2_value, error)) { osync_trace(TRACE_ERROR, "%s:%i: ERROR: ldap_format_add_xml_subsubentry() has failed.\n", __FILE__, __LINE__); @@ -3187,18 +3418,87 @@ } } else { - // Regular cases: + first_level_still_to_be_added = TRUE; + + + + +#if 0 + // 1st level: Regular cases: +#ifdef DEBUG_convert_ldap2xmlinternal + ldap_plugin_printf("\n\n\nFirst level (regular case) is about to be added: \"%s\".\n\n\n", name); +#endif + if (!ldap_format_add_xml_subentry(root_node, name, value, attr1_name, attr1_value, attr2_name, attr2_value, error)) { osync_trace(TRACE_ERROR, "%s:%i: ERROR: ldap_format_add_xml_subentry() has failed.\n", __FILE__, __LINE__); if (!osync_error_is_set(error)) osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: ldap_format_add_xml_subentry() has failed.\n", __FILE__, __LINE__); goto error; - } - } + } // if (!ldap_format_add_xml_subentry()...) + +#endif + + + + + } // if (where && where != entry->dn) } // if (i == 0) } // for (j = 0 ; entry->mods[j] ; j++) + + + if (first_level_still_to_be_added) { + // 1st level: Regular cases: +#ifdef DEBUG_convert_ldap2xmlinternal + ldap_plugin_printf("\n\n\nFirst level (regular case) is about to be added: \"%s\".\n\n\n", name); +#endif + + if (!ldap_format_add_xml_subentry(root_node, name, value, attr1_name, attr1_value, attr2_name, attr2_value, error)) { + osync_trace(TRACE_ERROR, "%s:%i: ERROR: ldap_format_add_xml_subentry() has failed.\n", __FILE__, __LINE__); + if (!osync_error_is_set(error)) { + osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: ldap_format_add_xml_subentry() has failed.\n", __FILE__, __LINE__); + } + + goto error; + } // if (!ldap_format_add_xml_subentry()...) + + first_level_still_to_be_added = FALSE; // reset it to default setting + } // if (first_level_still_to_be_added) + + + + if (name) { + xmlFree(name); + name = NULL; + } + + if (value) { + xmlFree(value); + value = NULL; + } + + if (attr1_name) { + xmlFree(attr1_name); + attr1_name = NULL; + } + + if (attr1_value) { + xmlFree(attr1_value); + attr1_value = NULL; + } + + if (attr2_name) { + xmlFree(attr2_name); + attr2_name = NULL; + } + + if (attr2_value) { + xmlFree(attr2_value); + attr2_value = NULL; + } + + #ifdef DEBUG_convert_ldap2xmlinternal ldap_plugin_printf("\n"); #endif @@ -3540,11 +3840,11 @@ continue; } else { - if (!ldap_format_parse_subentry(subentry_node, dn, complex_element_lists, &ldap_subentries, error)) { + if (!ldap_format_parse_xml_subentry(subentry_node, dn, complex_element_lists, &ldap_subentries, error)) { if (!osync_error_is_set(error)) { - osync_trace(TRACE_ERROR, "%s:%i: ERROR: ldap_format_parse_subentry() has failed. Ignoring this xml subentry.\n", __FILE__, __LINE__); + osync_trace(TRACE_ERROR, "%s:%i: ERROR: ldap_format_parse_xml_subentry() has failed. Ignoring this xml subentry.\n", __FILE__, __LINE__); } else { - osync_trace(TRACE_ERROR, "%s:%i: ERROR: ldap_format_parse_subentry() has failed: \"%s\". Ignoring this xml subentry.\n", __FILE__, __LINE__, osync_error_print(error)); + osync_trace(TRACE_ERROR, "%s:%i: ERROR: ldap_format_parse_xml_subentry() has failed: \"%s\". Ignoring this xml subentry.\n", __FILE__, __LINE__, osync_error_print(error)); osync_error_unref(error); } @@ -3563,7 +3863,7 @@ for (i = 0; i < g_list_length(ldap_subentries); i++) { ldap_subentry = g_list_nth_data(ldap_subentries, i); if (!ldap_subentry) { - osync_trace(TRACE_ERROR, "%s:%i: ERROR: ldap_subentry is NULL. ldap_format_parse_subentry() must have failed. Ignoring this xml subentry.\n", __FILE__, __LINE__); + osync_trace(TRACE_ERROR, "%s:%i: ERROR: ldap_subentry is NULL. ldap_format_parse_xml_subentry() must have failed. Ignoring this xml subentry.\n", __FILE__, __LINE__); continue; } @@ -4683,7 +4983,7 @@ } - container = (glist_container *)g_malloc0(sizeof(glist_container)); + container = (glist_container *)g_malloc0(sizeof(glist_container) + 1); osync_assert(container); container->magic = "glist_container"; container->list = ldap_entries; Modified: plugins/ldap-sync/src/ldap_format.h ============================================================================== --- plugins/ldap-sync/src/ldap_format.h Mon Mar 30 17:16:11 2009 (r5466) +++ plugins/ldap-sync/src/ldap_format.h Mon Mar 30 20:23:10 2009 (r5467) @@ -71,7 +71,7 @@ static void ldap_format_free_ldap_entries (GList **entrylist); static void ldap_format_free_ldapmods_list(GList *ldapmods); static osync_bool ldap_format_get_attributes(const xmlNode *xmlnode, gchar **attr1_name, gchar **attr1_value, gchar **attr2_name, gchar **attr2_value, OSyncError **error); -static osync_bool ldap_format_parse_subentry(const xmlNode *xmlnode, const gchar *dn, complex_elements *complex_elements, GList **ldap_entries, OSyncError **error); +static osync_bool ldap_format_parse_xml_subentry(const xmlNode *xmlnode, const gchar *dn, complex_elements *complex_elements, GList **ldap_entries, OSyncError **error); static osync_bool ldap_format_parse_xmlinternal_child_nodes(xmlNode *xmlnode, const char *objtype, const char *dn, complex_elements *complex_elements, GList **potential_subentries, GList **ldapmods, OSyncError **error); static osync_bool ldap_format_post_stylesheet(OSyncXMLFormat *xmlformat, const char *objtype, const char *ldap_format_name, GList **ldap_entries, OSyncError **error); static osync_bool ldap_format_pre_stylesheet(GList *ldap_entries, const char *objtype, const char *ldap_format_name, xmlChar **xmlbuff, int *xmlbuff_size, OSyncError **error); Modified: plugins/ldap-sync/src/ldap_plugin.c ============================================================================== --- plugins/ldap-sync/src/ldap_plugin.c Mon Mar 30 17:16:11 2009 (r5466) +++ plugins/ldap-sync/src/ldap_plugin.c Mon Mar 30 20:23:10 2009 (r5467) @@ -2083,7 +2083,7 @@ if (!ldap_plugin_get_changed_ldap_entries(ctx, sinkenv, ldaplist_added, ldaplist_modified, deleted_uids, unmodified_uids, error)) { if (!osync_error_is_set(error)) { - osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: ldap_plugin_get_changed_ldap_entries.", __FILE__, __LINE__); + osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: ldap_plugin_get_changed_ldap_entries() has failed.", __FILE__, __LINE__); } goto error; Modified: plugins/ldap-sync/src/ldap_plugin.h ============================================================================== --- plugins/ldap-sync/src/ldap_plugin.h Mon Mar 30 17:16:11 2009 (r5466) +++ plugins/ldap-sync/src/ldap_plugin.h Mon Mar 30 20:23:10 2009 (r5467) @@ -445,6 +445,7 @@ int ldap_plugin_initialize_format(OSyncPluginInfo *info, sink_environment *sinkenv, OSyncPluginConfig *configdata, const char *objtype, const char *format, OSyncError **error); sink_environment *ldap_plugin_initialize_sink(OSyncPluginInfo *info, const char *objtype, const char *format, OSyncError **error); osync_bool ldap_plugin_is_on (const char *str); +osync_bool ldap_plugin_parse_attribute_list(const int entry_list_index, const LDAPMod *mod, xmlChar **name, xmlChar **value, xmlChar **attr1_name, xmlChar **attr1_value, xmlChar **attr2_name, xmlChar **attr2_value, osync_bool *call_continue, OSyncError **error); osync_bool ldap_plugin_parse_config (OSyncPluginInfo *info, sink_environment *sinkenv, const char *objtype, OSyncPluginConfig * config, OSyncError **error); osync_bool ldap_plugin_process_deleted_entries (OSyncContext *ctx, OSyncPluginInfo *info, sink_environment *sinkenv, OSyncError **error); osync_bool ldap_plugin_report_change(OSyncContext *ctx, const sink_environment *sinkenv, const osync_bool slow_sync_requested, OSyncChangeType changetype_from_caller, GList *to_be_reported, OSyncError **error); |