Changeset 2

Show
Ignore:
Timestamp:
11/30/04 21:16:17 (4 years ago)
Author:
azrael
Message:

Made osync_debug available to plugins

new random_modify and delete function

Location:
trunk
Files:
15 modified

Legend:

Unmodified
Added
Removed
  • trunk/plugins/file-sync/src/file_sync.c

    r1 r2  
    4444static void *fs_initialize(OSyncMember *member) 
    4545{ 
     46        osync_debug("FILE-SYNC", 4, "start: %s", __func__); 
    4647        char *configdata; 
    4748        int configsize; 
     
    8485static void fs_connect(OSyncContext *ctx) 
    8586{ 
     87        osync_debug("FILE-SYNC", 4, "start: %s", __func__); 
    8688        filesyncinfo *fsinfo = (filesyncinfo *)osync_context_get_plugin_data(ctx); 
    8789        GError *direrror = NULL; 
     
    108110static void fs_get_changeinfo(OSyncContext *ctx) 
    109111{ 
     112        osync_debug("FILE-SYNC", 4, "start: %s", __func__); 
    110113        filesyncinfo *fsinfo = (filesyncinfo *)osync_context_get_plugin_data(ctx); 
    111114        if (fsinfo->dir) { 
     
    145148static void fs_get_data(OSyncContext *ctx, OSyncChange *change) 
    146149{ 
     150        osync_debug("FILE-SYNC", 4, "start: %s", __func__); 
    147151        filesyncinfo *fsinfo = (filesyncinfo *)osync_context_get_plugin_data(ctx); 
    148152        fs_fileinfo *file_info = (fs_fileinfo *)osync_change_get_data(change); 
     
    158162static osync_bool fs_access(OSyncContext *ctx, OSyncChange *change) 
    159163{ 
     164        osync_debug("FILE-SYNC", 4, "start: %s", __func__); 
    160165        filesyncinfo *fsinfo = (filesyncinfo *)osync_context_get_plugin_data(ctx); 
    161166        fs_fileinfo *file_info = (fs_fileinfo *)osync_change_get_data(change); 
     
    167172                case CHANGE_DELETED: 
    168173                        if (!remove(filename) == 0) { 
    169                                 //osync_context_report_error(ctx, OSYNC_ERROR_FILE_NOT_FOUND, "Unable to write"); 
    170                                 osync_context_report_success(ctx); 
     174                                osync_debug("FILE-SYNC", 0, "Unable to remove file %s", filename); 
     175                                osync_context_report_error(ctx, OSYNC_ERROR_FILE_NOT_FOUND, "Unable to write"); 
    171176                                g_free(filename); 
    172177                                return FALSE; 
     
    175180                case CHANGE_ADDED: 
    176181                        if (g_file_test(filename, G_FILE_TEST_EXISTS)) { 
     182                                osync_debug("FILE-SYNC", 0, "File %s already exists", filename); 
    177183                                osync_context_report_error(ctx, OSYNC_ERROR_EXISTS, "Entry already exists"); 
    178184                                g_free(filename); 
     
    181187                case CHANGE_MODIFIED: 
    182188                        if (!osync_file_write(filename, file_info->data, file_info->size)) { 
    183                                 //osync_context_report_error(ctx, OSYNC_ERROR_FILE_NOT_FOUND, "Unable to write"); 
    184                                 osync_context_report_success(ctx); 
     189                                osync_debug("FILE-SYNC", 0, "Unable to write to file %s", filename); 
     190                                osync_context_report_error(ctx, OSYNC_ERROR_FILE_NOT_FOUND, "Unable to write"); 
    185191                                g_free(filename); 
    186192                                return FALSE; 
     
    190196                        break; 
    191197                default: 
    192                         printf("Error1 %i\n", osync_change_get_changetype(change)); 
     198                        osync_debug("FILE-SYNC", 0, "Unknown change type"); 
    193199        } 
    194200        osync_context_report_success(ctx); 
     
    199205static void fs_commit_change(OSyncContext *ctx, OSyncChange *change) 
    200206{ 
     207        osync_debug("FILE-SYNC", 4, "start: %s", __func__); 
     208        osync_debug("FILE-SYNC", 3, "Writing change %s with changetype %i", osync_change_get_uid(change), osync_change_get_changetype(change)); 
    201209        fs_access(ctx, change); 
    202210 
     
    207215static void fs_sync_done(OSyncContext *ctx) 
    208216{ 
     217        osync_debug("FILE-SYNC", 4, "start: %s", __func__); 
    209218        filesyncinfo *fsinfo = (filesyncinfo *)osync_context_get_plugin_data(ctx); 
    210219        osync_hashtable_forget(fsinfo->hashtable); 
     
    215224static void fs_disconnect(OSyncContext *ctx) 
    216225{ 
     226        osync_debug("FILE-SYNC", 4, "start: %s", __func__); 
    217227        filesyncinfo *fsinfo = (filesyncinfo *)osync_context_get_plugin_data(ctx); 
    218228        g_dir_close(fsinfo->dir); 
     
    222232static void fs_finalize(void *data) 
    223233{ 
     234        osync_debug("FILE-SYNC", 4, "start: %s", __func__); 
    224235        filesyncinfo *fsinfo = (filesyncinfo *)data; 
    225236        osync_hashtable_close(fsinfo->hashtable); 
  • trunk/src/opensync.h

    r1 r2  
    116116 
    117117char *osync_rand_str(int maxlength); 
     118void osync_debug(char *subpart, int level, const char *message, ...); 
     119void osync_print_binary(unsigned char *data, int len); 
    118120 
    119121/************************************************************** 
  • trunk/src/opensync_change.c

    r1 r2  
    1111void osync_change_free(OSyncChange *change) 
    1212{ 
     13         
    1314        g_assert(change); 
    1415        //FIXME cleanly release the change! 
    1516        if (change->mapping) 
    1617                osync_mapping_remove_entry(change->mapping, change); 
     18        if (change->member) 
     19                osync_member_remove_changeentry(change->member, change); 
    1720        g_free(change); 
    1821} 
  • trunk/src/opensync_change.h

    r1 r2  
    3131void osync_change_marshal(OSyncChange *change, DBT *dbt); 
    3232osync_bool osync_change_has_data(OSyncChange *change); 
     33void osync_change_free(OSyncChange *change); 
  • trunk/src/opensync_convert.c

    r1 r2  
    3131        /* Check if this platform supports dynamic 
    3232         * loading of modules */ 
    33         _osync_debug("OSFRM", 3, "Loading formats plugin from %s", path); 
     33        osync_debug("OSFRM", 3, "Loading formats plugin from %s", path); 
    3434        if (!g_module_supported()) { 
    35                 _osync_debug("OSPLG", 0, "This platform does not support loading of modules"); 
     35                osync_debug("OSPLG", 0, "This platform does not support loading of modules"); 
    3636                return; 
    3737        } 
     
    4040        GModule *plugin = g_module_open(path, 0); 
    4141        if (!plugin) { 
    42                 _osync_debug("OSPLG", 0, "Unable to open plugin: %s", g_module_error()); 
     42                osync_debug("OSPLG", 0, "Unable to open plugin: %s", g_module_error()); 
    4343                return; 
    4444        } 
     
    4747        void (** fct_infop)(OSyncConvEnv *env) = &fct_info; 
    4848        if (!g_module_symbol(plugin, "get_info", (void **)fct_infop)) { 
    49                 _osync_debug("OSPLG", 0, "Unable to open format plugin %s: %s", path, g_module_error()); 
     49                osync_debug("OSPLG", 0, "Unable to open format plugin %s: %s", path, g_module_error()); 
    5050                return; 
    5151        } 
     
    6060        GDir *dir; 
    6161        GError *error = NULL; 
    62         _osync_debug("OSPLG", 3, "Trying to open formats plugin directory %s", env->pluginpath); 
     62        osync_debug("OSPLG", 3, "Trying to open formats plugin directory %s", env->pluginpath); 
    6363         
    6464        if (!g_file_test(env->pluginpath, G_FILE_TEST_EXISTS)) { 
     
    6868        dir = g_dir_open(env->pluginpath, 0, &error); 
    6969        if (error) { 
    70                 _osync_debug("OSPLG", 0, "Unable to open formats plugin directory %s: %s", env->pluginpath, error->message); 
     70                osync_debug("OSPLG", 0, "Unable to open formats plugin directory %s: %s", env->pluginpath, error->message); 
    7171                g_error_free (error); 
    7272                return; 
  • trunk/src/opensync_debug.c

    r1 r2  
    22#include "opensync_internals.h" 
    33 
    4 void _osync_debug(char *subpart, int level, const char *message, ...) 
     4void osync_debug(char *subpart, int level, const char *message, ...) 
    55{ 
    66                va_list arglist; 
    77                char *buffer; 
    8                 const gchar *debug = NULL; 
     8                int debug = -1; 
    99 
    1010                va_start(arglist, message); 
    1111                g_vasprintf(&buffer, message, arglist); 
    12  
    13                 debug = g_getenv ("OSYNC_DEBUG"); 
    14                 if (debug) { 
    15                         printf("[%s] ERROR: %s\n", subpart, buffer); 
     12                 
     13                const char *dbgstr = g_getenv("OSYNC_DEBUG"); 
     14                if (!dbgstr) 
     15                        return; 
     16                debug = atoi(dbgstr); 
     17                if (debug < level) 
     18                        return; 
     19                 
     20                switch (level) { 
     21                        case 0: 
     22                                //Error 
     23                                printf("[%s] ERROR: %s\n", subpart, buffer); 
     24                                break; 
     25                        case 1: 
     26                                // Warning 
     27                                printf("[%s] WARNING: %s\n", subpart, buffer); 
     28                                break; 
     29                case 2: 
     30                                //Information 
     31                                printf("[%s] INFORMATION: %s\n", subpart, buffer); 
     32                                break; 
     33                case 3: 
     34                                //debug 
     35                                printf("[%s] DEBUG: %s\n", subpart, buffer); 
     36                                break; 
     37                case 4: 
     38                                //fulldebug 
     39                                printf("[%s] FULL DEBUG: %s\n", subpart, buffer); 
     40                                break; 
    1641                } 
    17                  
    18                 /* 
    19                 if (debug) { 
    20                         switch (level) { 
    21                                 case 0: 
    22                                         //Error 
    23                                         printf("[%s] ERROR: %s\n", subpart, buffer); 
    24                                         break; 
    25                                 case 1: 
    26                                         // Warning 
    27                                         printf("[%s] WARNING: %s\n", subpart, buffer); 
    28                                         break; 
    29                         case 2: 
    30                                         //Information 
    31                                         printf("[%s] INFORMATION: %s\n", subpart, buffer); 
    32                                         break; 
    33                         case 3: 
    34                                         //debug 
    35                                         printf("[%s] DEBUG: %s\n", subpart, buffer); 
    36                                         break; 
    37                         case 4: 
    38                                         //fulldebug 
    39                                         printf("[%s] FULL DEBUG: %s\n", subpart, buffer); 
    40                                         break; 
    41                         } 
    42                 }*/ 
    4342                va_end(arglist); 
    4443} 
  • trunk/src/opensync_env.c

    r1 r2  
    1212        os_env->conv_env = osync_conv_env_new(); 
    1313 
    14         _osync_debug("os_env", 3, "Generating new os_env:"); 
    15         _osync_debug("os_env", 3, "Configdirectory: %s", os_env->configdir); 
     14        osync_debug("os_env", 3, "Generating new os_env:"); 
     15        osync_debug("os_env", 3, "Configdirectory: %s", os_env->configdir); 
    1616        return os_env; 
    1717} 
     
    2929                index = g_list_length(os_env->groups); 
    3030                _osync_append_group(os_env, group); 
    31                 _osync_debug("os_env", 3, "Appending group %s to list with index %i", osync_group_get_name(group), index); 
    32         } else { 
    33                 _osync_debug("os_env", 3, "Found group %s in list with index %i", osync_group_get_name(group), index); 
     31                osync_debug("os_env", 3, "Appending group %s to list with index %i", osync_group_get_name(group), index); 
     32        } else { 
     33                osync_debug("os_env", 3, "Found group %s in list with index %i", osync_group_get_name(group), index); 
    3434        } 
    3535        return index; 
     
    4646        //Load all available shared libraries (plugins) 
    4747        if (!g_file_test(os_env->plugindir, G_FILE_TEST_EXISTS)) { 
    48                 _osync_debug("OSGRP", 3, "%s exists, but is no dir", os_env->plugindir); 
     48                osync_debug("OSGRP", 3, "%s exists, but is no dir", os_env->plugindir); 
    4949                return FALSE; 
    5050        } 
     
    5959        GDir *dir; 
    6060        GError *error = NULL; 
    61         _osync_debug("OSGRP", 3, "Trying to open main confdir %s to load groups", osync_env_get_configdir(osyncinfo)); 
     61        osync_debug("OSGRP", 3, "Trying to open main confdir %s to load groups", osync_env_get_configdir(osyncinfo)); 
    6262         
    6363        if (!g_file_test(osync_env_get_configdir(osyncinfo), G_FILE_TEST_EXISTS)) { 
     
    6565        } else { 
    6666                if (!g_file_test(osync_env_get_configdir(osyncinfo), G_FILE_TEST_IS_DIR)) { 
    67                         _osync_debug("OSGRP", 3, "%s exists, but is now dir", osync_env_get_configdir(osyncinfo)); 
     67                        osync_debug("OSGRP", 3, "%s exists, but is now dir", osync_env_get_configdir(osyncinfo)); 
    6868                        return FALSE; 
    6969                } 
     
    7272        dir = g_dir_open(osync_env_get_configdir(osyncinfo), 0, &error); 
    7373        if (error) { 
    74                 _osync_debug("OSGRP", 3, "Unable to open main configdir %s: %s", osync_env_get_configdir(osyncinfo), error->message); 
     74                osync_debug("OSGRP", 3, "Unable to open main configdir %s: %s", osync_env_get_configdir(osyncinfo), error->message); 
    7575                g_error_free (error); 
    7676                return FALSE; 
     
    144144{ 
    145145        if (!g_file_test(path, G_FILE_TEST_EXISTS)) { 
    146                 _osync_debug("OSXML", 1, "File %s does not exist", path); 
     146                osync_debug("OSXML", 1, "File %s does not exist", path); 
    147147                return FALSE; 
    148148        } 
     
    151151 
    152152        if (!*doc) { 
    153                 _osync_debug("OSXML", 1, "Could not open: %s", path); 
     153                osync_debug("OSXML", 1, "Could not open: %s", path); 
    154154                return FALSE; 
    155155        } 
     
    158158 
    159159        if (!*cur) { 
    160                 _osync_debug("OSXML", 0, "%s seems to be empty", path); 
     160                osync_debug("OSXML", 0, "%s seems to be empty", path); 
    161161                xmlFreeDoc(*doc); 
    162162                return FALSE; 
     
    164164 
    165165        if (xmlStrcmp((*cur)->name, (const xmlChar *) topentry)) { 
    166                 _osync_debug("OSXML", 0, "%s seems not to be a valid configfile.\n", path); 
     166                osync_debug("OSXML", 0, "%s seems not to be a valid configfile.\n", path); 
    167167                xmlFreeDoc(*doc); 
    168168                return FALSE; 
     
    181181        GIOChannel *chan = g_io_channel_new_file(filename, "w", &error); 
    182182        if (!chan) { 
    183                 _osync_debug("OSYNC", 3, "Unable to open file %s for writing: %s", filename, error->message); 
     183                osync_debug("OSYNC", 3, "Unable to open file %s for writing: %s", filename, error->message); 
    184184                return FALSE; 
    185185        } 
     
    187187        g_io_channel_set_encoding(chan, NULL, NULL); 
    188188        if (g_io_channel_write_chars(chan, data, size, &writen, &error) != G_IO_STATUS_NORMAL) { 
    189                 _osync_debug("OSYNC", 3, "Unable to read contents of file %s: %s", filename, error->message); 
     189                osync_debug("OSYNC", 3, "Unable to read contents of file %s: %s", filename, error->message); 
    190190        } else { 
    191191                g_io_channel_flush(chan, NULL); 
     
    205205        GIOChannel *chan = g_io_channel_new_file(filename, "r", &error); 
    206206        if (!chan) { 
    207                 _osync_debug("OSYNC", 3, "Unable to read file %s: %s", filename, error->message); 
     207                osync_debug("OSYNC", 3, "Unable to read file %s: %s", filename, error->message); 
    208208                return FALSE; 
    209209        } 
    210210        g_io_channel_set_encoding(chan, NULL, NULL); 
    211211        if (g_io_channel_read_to_end(chan, data, size, &error) != G_IO_STATUS_NORMAL) { 
    212                 _osync_debug("OSYNC", 3, "Unable to read contents of file %s: %s", filename, error->message); 
     212                osync_debug("OSYNC", 3, "Unable to read contents of file %s: %s", filename, error->message); 
    213213        } else { 
    214214                ret = TRUE; 
  • trunk/src/opensync_group.c

    r1 r2  
    1212        group->configdir = filename; 
    1313        group->env = osinfo; 
    14         _osync_debug("OSGRP", 3, "Generated new group:"); 
    15         //_osync_debug("OSMEM", 3, "Name: %s", group->name); 
    16         _osync_debug("OSGRP", 3, "Configdirectory: %s", filename); 
     14        osync_debug("OSGRP", 3, "Generated new group:"); 
     15        //osync_debug("OSMEM", 3, "Name: %s", group->name); 
     16        osync_debug("OSGRP", 3, "Configdirectory: %s", filename); 
    1717        return group; 
    1818} 
     
    2828void osync_group_set_name(OSyncGroup *group, char *name) 
    2929{ 
    30         _osync_debug("OSGRP", 3, "Setting name of group %s to %s", group->name, name); 
     30        osync_debug("OSGRP", 3, "Setting name of group %s to %s", group->name, name); 
    3131        group->name = g_strdup(name); 
    3232} 
     
    4040{ 
    4141        char *filename = NULL; 
    42         _osync_debug("OSGRP", 3, "Trying to open configdirectory %s to save group %s", group->configdir, group->name); 
     42        osync_debug("OSGRP", 3, "Trying to open configdirectory %s to save group %s", group->configdir, group->name); 
    4343        int i; 
    4444                 
    4545        if (!g_file_test(group->configdir, G_FILE_TEST_IS_DIR)) { 
    46                 _osync_debug("OSGRP", 3, "Creating configdirectory %s", group->configdir); 
     46                osync_debug("OSGRP", 3, "Creating configdirectory %s", group->configdir); 
    4747                mkdir(group->configdir, 0777); 
    4848        } 
    4949         
    5050        filename = g_strdup_printf ("%s/syncgroup.conf", group->configdir); 
    51         _osync_debug("OSGRP", 3, "Saving group to file %s", filename); 
     51        osync_debug("OSGRP", 3, "Saving group to file %s", filename); 
    5252         
    5353        xmlDocPtr doc; 
     
    7373        char *filename = NULL; 
    7474         
    75         _osync_debug("OSGRP", 3, "Trying to load group from directory %s", path); 
     75        osync_debug("OSGRP", 3, "Trying to load group from directory %s", path); 
    7676        OSyncGroup *group = osync_group_new(env); 
    7777        osync_group_set_configdir(group, path); 
     
    105105        dir = g_dir_open(osync_group_get_configdir(group), 0, &error); 
    106106        if (error) { 
    107                 _osync_debug("OSGRP", 3, "Unable to open group configdir %s", error->message); 
     107                osync_debug("OSGRP", 3, "Unable to open group configdir %s", error->message); 
    108108                g_error_free (error); 
    109109                osync_group_free(group); 
     
    150150void osync_group_set_configdir(OSyncGroup *group, char *path) 
    151151{ 
    152         _osync_debug("OSGRP", 3, "Setting configdirectory of group %s to %s", group->name, path); 
     152        osync_debug("OSGRP", 3, "Setting configdirectory of group %s to %s", group->name, path); 
    153153        group->configdir = g_strdup(path); 
    154154} 
     
    175175                } 
    176176        } 
    177         _osync_debug("OSPLG", 0, "Couldnt find the group with the name %s", name); 
     177        osync_debug("OSPLG", 0, "Couldnt find the group with the name %s", name); 
    178178        return NULL; 
    179179} 
  • trunk/src/opensync_internals.h

    r1 r2  
    88 
    99osync_bool osync_plugin_load_dir(OSyncEnv *os_env, char *path); 
    10 void _osync_debug(char *subpart, int level, const char *message, ...); 
    1110OSyncUserInfo *_osync_get_user(void); 
    1211osync_bool _osync_open_xml_file(xmlDocPtr *doc, xmlNodePtr *cur, char *path, char *topentry); 
    13 void osync_print_binary(unsigned char *data, int len); 
    1412osync_bool osync_conv_find_shortest_path(GList *vertices, OSyncObjFormat *start, OSyncObjFormat *end, GList **retlist); 
    1513void osync_error_set_vargs(OSyncError *error, OSyncErrorType type, const char *format, va_list args); 
  • trunk/src/opensync_mapping.c

    r1 r2  
    1111void osync_mappingtable_free(OSyncMappingTable *table) 
    1212{ 
    13         g_list_free(table->mappings); 
     13        GList *c = NULL; 
     14        GList *m = NULL; 
     15        GList *mappings = g_list_copy(table->mappings); 
     16        GList *unmapped = g_list_copy(table->unmapped); 
     17 
     18        for (m = mappings; m; m = m->next) { 
     19                OSyncMapping *mapping = m->data; 
     20                osync_mapping_free(mapping); 
     21        } 
     22        for (c = unmapped; c; c = c->next) { 
     23                OSyncChange *change = c->data; 
     24                osync_change_free(change); 
     25        } 
     26        g_list_free(mappings); 
     27        g_list_free(unmapped); 
    1428        g_free(table->db_path); 
    15         g_list_free(table->unmapped); 
    1629        g_free(table); 
    1730} 
     
    144157void osync_mapping_free(OSyncMapping *mapping) 
    145158{ 
     159        GList *c = NULL; 
     160        GList *entries = g_list_copy(mapping->entries); 
     161        for (c = entries; c; c = c->next) { 
     162                OSyncChange *change = c->data; 
     163                osync_change_free(change); 
     164        } 
     165        g_list_free(entries); 
    146166        osync_mappingtable_remove_mapping(mapping->table, mapping); 
    147167        g_free(mapping); 
     
    221241        for (i = 0; i < g_list_length(mapping->entries); i++) { 
    222242                OSyncChange *change = g_list_nth_data(mapping->entries, i); 
    223                 if (change->member == member) 
     243                if (osync_member_get_id(change->member) == osync_member_get_id(member)) 
    224244                        return change; 
    225245        } 
  • trunk/src/opensync_mapping.h

    r1 r2  
    3838void osync_mapping_remove_entry(OSyncMapping *mapping, OSyncChange *entry); 
    3939void osync_mappingtable_free(OSyncMappingTable *table); 
     40void osync_mapping_free(OSyncMapping *mapping); 
  • trunk/src/opensync_member.c

    r1 r2  
    2424        member->memberfunctions = osync_memberfunctions_new(); 
    2525        //printf("hashtable: %p\n", member->hashtable); 
    26         _osync_debug("OSMEM", 3, "Generated new member"); 
    27         //_osync_debug("OSMEM", 3, "Name: %s, %p", member->name, member); 
    28         //_osync_debug("OSMEM", 3, "Configdirectory: %s", filename); 
     26        osync_debug("OSMEM", 3, "Generated new member"); 
     27        //osync_debug("OSMEM", 3, "Name: %s, %p", member->name, member); 
     28        //osync_debug("OSMEM", 3, "Configdirectory: %s", filename); 
    2929 
    3030        return member; 
     
    3838osync_bool osync_member_instance_plugin(OSyncMember *member, OSyncPlugin *plugin) 
    3939{ 
    40         _osync_debug("OSMEM", 3, "Insstancing plugin %s for member %i", osync_plugin_get_name(plugin), member->id); 
     40        osync_debug("OSMEM", 3, "Insstancing plugin %s for member %i", osync_plugin_get_name(plugin), member->id); 
    4141        if (plugin->info.is_threadsafe) { 
    4242                member->plugin = plugin; 
     
    7777osync_bool osync_member_set_configdir(OSyncMember *member, char *path) 
    7878{ 
    79         _osync_debug("OSMEM", 3, "Setting configdirectory for member %i to %s", member->id, path); 
     79        osync_debug("OSMEM", 3, "Setting configdirectory for member %i to %s", member->id, path); 
    8080        member->configdir = g_strdup(path); 
    8181        return TRUE; //FIXME