| 72 | | cur = xmlDocGetRootElement(doc); |
| 73 | | |
| 74 | | if (!cur) { |
| 75 | | osync_error_set(error, OSYNC_ERROR_GENERIC, "Unable to get configuration XML root element"); |
| 76 | | goto error_free_doc; |
| 77 | | } |
| 78 | | |
| 79 | | if (xmlStrcmp(cur->name, (xmlChar*)"config")) { |
| 80 | | osync_error_set(error, OSYNC_ERROR_GENERIC, "Configuration file root node name is invalid"); |
| 81 | | goto error_free_doc; |
| 82 | | } |
| 83 | | |
| 84 | | cur = cur->xmlChildrenNode; |
| 85 | | |
| 86 | | while (cur != NULL) { |
| 87 | | if(cur->type == XML_ELEMENT_NODE) { |
| 88 | | char *str = (char *)xmlNodeGetContent(cur); |
| 89 | | if (str) { |
| 90 | | if (!xmlStrcmp(cur->name, (const xmlChar *)"username")) { |
| 91 | | g_free(env->username); |
| 92 | | env->username = g_strdup(str); |
| 93 | | } else if (!xmlStrcmp(cur->name, (const xmlChar *)"password")) { |
| 94 | | g_free(env->password); |
| 95 | | env->password = g_strdup(str); |
| 96 | | } else if (!xmlStrcmp(cur->name, (const xmlChar *)"hostname")) { |
| 97 | | g_free(env->host); |
| 98 | | env->host = g_strdup(str); |
| 99 | | } else if (!xmlStrcmp(cur->name, (const xmlChar *)"url")) { |
| 100 | | osync_trace(TRACE_INTERNAL, "The 'url' configuration parameter is deprecated - please use 'hostname' instead"); |
| 101 | | g_free(env->host); |
| 102 | | env->host = g_strdup(str); |
| 103 | | } else if (!xmlStrcmp(cur->name, (const xmlChar *)"port")) { |
| 104 | | env->device_port = atoi(str); |
| 105 | | } else if (!xmlStrcmp(cur->name, (const xmlChar *)"device")) { |
| 106 | | if (!strcasecmp(str, "qtopia2")) |
| 107 | | env->device_type = OPIE_SYNC_QTOPIA_2; |
| 108 | | else |
| 109 | | env->device_type = OPIE_SYNC_OPIE; |
| 110 | | } else if (!xmlStrcmp(cur->name, (const xmlChar *)"conntype")) { |
| 111 | | if (!strcasecmp(str, "scp")) |
| 112 | | env->conn_type = OPIE_CONN_SCP; |
| 113 | | else if ( strcasecmp(str, "none") == 0 ) |
| 114 | | env->conn_type = OPIE_CONN_NONE; |
| 115 | | else |
| 116 | | env->conn_type = OPIE_CONN_FTP; |
| 117 | | } else if (!xmlStrcmp(cur->name, (const xmlChar *)"use_qcop")) { |
| 118 | | if ( strcasecmp(str, "false") == 0 ) |
| 119 | | env->use_qcop = FALSE; |
| 120 | | else |
| 121 | | env->use_qcop = TRUE; |
| 122 | | } else if (!xmlStrcmp(cur->name, (const xmlChar *)"backupdir")) { |
| 123 | | if(strlen(str) > 0) |
| 124 | | env->backupdir = g_strdup(str); |
| 125 | | } else if (!xmlStrcmp(cur->name, (const xmlChar *)"localdir")) { |
| 126 | | g_free(env->localdir); |
| 127 | | env->localdir = g_strdup(str); |
| 128 | | } else if (!xmlStrcmp(cur->name, (const xmlChar *)"notestype")) { |
| 129 | | if ( (!strcasecmp(str, "opie-notes")) || (!strcasecmp(str, "opie_notes")) ) |
| 130 | | env->notes_type = NOTES_TYPE_OPIE_NOTES; |
| 131 | | else if ( strcasecmp(str, "basic") == 0 ) |
| 132 | | env->notes_type = NOTES_TYPE_BASIC; |
| 133 | | else { |
| 134 | | osync_error_set(error, OSYNC_ERROR_GENERIC, "Invalid value \"%s\" for configuration option \"%s\"", str, cur->name); |
| 135 | | goto error_free_doc; |
| 136 | | } |
| 137 | | } else { |
| 138 | | osync_error_set(error, OSYNC_ERROR_GENERIC, "Invalid configuration file option \"%s\"", cur->name); |
| 139 | | goto error_free_doc; |
| 140 | | } |
| 141 | | xmlFree(str); |
| 142 | | } |
| 143 | | } |
| 144 | | cur = cur->next; |
| 145 | | } |
| 146 | | |
| 147 | | xmlFreeDoc(doc); |
| 148 | | osync_trace(TRACE_EXIT, "%s", __func__); |
| 149 | | return TRUE; |
| 150 | | |
| 151 | | error_free_doc: |
| 152 | | xmlFreeDoc(doc); |
| | 69 | OSyncPluginConnection *conn = osync_plugin_config_get_connection(config); |
| | 70 | if(conn) { |
| | 71 | const char *addr = osync_plugin_connection_net_get_address(conn); |
| | 72 | if(addr) { |
| | 73 | g_free(env->host); |
| | 74 | env->host = g_strdup(addr); |
| | 75 | } |
| | 76 | unsigned int port = osync_plugin_connection_net_get_port(conn); |
| | 77 | if(port > 0) |
| | 78 | env->device_port = port; |
| | 79 | } |
| | 80 | |
| | 81 | OSyncPluginAuthentication *auth = osync_plugin_config_get_authentication(config); |
| | 82 | if(auth) { |
| | 83 | const char *username = osync_plugin_authentication_get_username(auth); |
| | 84 | if(username) { |
| | 85 | g_free(env->username); |
| | 86 | env->username = g_strdup(username); |
| | 87 | } |
| | 88 | const char *password = osync_plugin_authentication_get_password(auth); |
| | 89 | if(password) { |
| | 90 | g_free(env->password); |
| | 91 | env->password = g_strdup(password); |
| | 92 | } |
| | 93 | } |
| | 94 | |
| | 95 | OSyncList *advoptions = osync_plugin_config_get_advancedoptions(config); |
| | 96 | for (; advoptions; advoptions = advoptions->next) { |
| | 97 | OSyncPluginAdvancedOption *option = advoptions->data; |
| | 98 | |
| | 99 | const char *val = osync_plugin_advancedoption_get_value(option); |
| | 100 | const char *name = osync_plugin_advancedoption_get_name(option); |
| | 101 | g_assert(name); |
| | 102 | g_assert(val); |
| | 103 | const char *key = NULL; |
| | 104 | |
| | 105 | if (!strcmp(name, "ClientType")) { |
| | 106 | if (!strcasecmp(val, "qtopia2")) |
| | 107 | env->device_type = OPIE_SYNC_QTOPIA_2; |
| | 108 | else |
| | 109 | env->device_type = OPIE_SYNC_OPIE; |
| | 110 | } |
| | 111 | else if (!strcmp(name, "ConnType")) { |
| | 112 | if (!strcasecmp(val, "scp")) |
| | 113 | env->conn_type = OPIE_CONN_SCP; |
| | 114 | else if ( strcasecmp(val, "none") == 0 ) |
| | 115 | env->conn_type = OPIE_CONN_NONE; |
| | 116 | else |
| | 117 | env->conn_type = OPIE_CONN_FTP; |
| | 118 | } |
| | 119 | else if (!strcmp(name, "NotesType")) { |
| | 120 | if ( (!strcasecmp(val, "opie-notes")) || (!strcasecmp(val, "opie_notes")) ) |
| | 121 | env->notes_type = NOTES_TYPE_OPIE_NOTES; |
| | 122 | else if ( strcasecmp(val, "basic") == 0 ) |
| | 123 | env->notes_type = NOTES_TYPE_BASIC; |
| | 124 | else { |
| | 125 | osync_error_set(error, OSYNC_ERROR_GENERIC, "Invalid value \"%s\" for configuration option \"%s\"", val, name); |
| | 126 | goto error; |
| | 127 | } |
| | 128 | } |
| | 129 | else if (!strcmp(name, "BackupDir")) { |
| | 130 | if(strlen(val) > 0) |
| | 131 | env->backupdir = g_strdup(val); |
| | 132 | } |
| | 133 | else if (!strcmp(name, "LocalDir")) { |
| | 134 | if(strlen(val) > 0) { |
| | 135 | g_free(env->localdir); |
| | 136 | env->localdir = g_strdup(val); |
| | 137 | } |
| | 138 | } |
| | 139 | else if (!strcmp(name, "DisableQcop")) { |
| | 140 | if(atoi(val)) |
| | 141 | env->use_qcop = FALSE; |
| | 142 | else |
| | 143 | env->use_qcop = TRUE; |
| | 144 | } |
| | 145 | else { |
| | 146 | osync_error_set(error, OSYNC_ERROR_GENERIC, "Invalid configuration file advanced option \"%s\"", name); |
| | 147 | goto error; |
| | 148 | } |
| | 149 | } |
| | 150 | |