static int default_layout(struct supertype *st, int level, int verbose) { int layout = UnSet; if (st && st->ss->default_geometry) st->ss->default_geometry(st, &level, &layout, NULL); if (layout == UnSet) switch(level) { default: /* no layout */ layout = 0; break; case 10: layout = 0x102; /* near=2, far=1 */ if (verbose > 0) pr_err("layout defaults to n2\n"); break; case 5: case 6: layout = map_name(r5layout, "default"); if (verbose > 0) pr_err("layout defaults to %s\n", map_num(r5layout, layout)); break; case LEVEL_FAULTY: layout = map_name(faultylayout, "default"); if (verbose > 0) pr_err("layout defaults to %s\n", map_num(faultylayout, layout)); break; } return layout; }
/* read the next troff request; return zero if a request was executed. */ int tr_nextreq(void) { char *mac; char *arg0 = NULL; int c; if (!tr_nl) return 1; c = cp_next(); /* transparent line indicator */ if (c == c_ec) { int c2 = cp_next(); if (c2 == '!') { char *args[NARGS + 3] = {"\\!"}; struct sbuf sbuf; sbuf_init(&sbuf); cp_copymode(1); mkargs_eol(&sbuf); cp_copymode(0); chopargs(&sbuf, args + 1); tr_transparent(args); sbuf_done(&sbuf); return 0; } cp_back(c2); } /* not a request, a blank line, or a line with leading spaces */ if (c < 0 || (c != c_cc && c != c_c2 && (c != '\n' || tr_bm < 0) && (c != ' ' || tr_sm < 0))) { cp_back(c); return 1; } cp_reqbeg(); if (c == '\n') { /* blank line macro */ mac = malloc(strlen(map_name(tr_bm)) + 1); strcpy(mac, map_name(tr_bm)); arg0 = dotted(mac, '.'); tr_nextreq_exec(mac, arg0, 0); } else if (c == ' ') { /* leading space macro */ int i; mac = malloc(strlen(map_name(tr_sm)) + 1); strcpy(mac, map_name(tr_sm)); for (i = 0; c == ' '; i++) c = cp_next(); cp_back(c); n_lsn = i; arg0 = dotted(mac, '.'); tr_nextreq_exec(mac, arg0, 0); } else { mac = read_name(n_cp); arg0 = dotted(mac, c); tr_nextreq_exec(mac, arg0, 1); } free(arg0); free(mac); return 0; }
static void store_listed( int sts, void *aux ) { MVARS(aux) string_list_t *box; switch (sts) { case DRV_CANCELED: return; case DRV_OK: mvars->ctx[t]->listed = 1; if (mvars->ctx[t]->conf->flat_delim) { for (box = mvars->ctx[t]->boxes; box; box = box->next) { if (map_name( box->string, mvars->ctx[t]->conf->flat_delim, '/' ) < 0) { error( "Error: flattened mailbox name '%s' contains canonical hierarchy delimiter\n", box->string ); mvars->ret = mvars->skip = 1; } } } if (mvars->ctx[t]->conf->map_inbox) add_string_list( &mvars->ctx[t]->boxes, mvars->ctx[t]->conf->map_inbox ); break; default: mvars->ret = mvars->skip = 1; break; } mvars->state[t] = ST_OPEN; sync_chans( mvars, E_OPEN ); }
int cmd_breakup_components(char *str, char *sep, nvlist_t **hc_nvl) { char namebuf[64], instbuf[64]; char *token, *tokbuf; int i, j, namelen, instlen; i = 0; for (token = strtok_r(str, sep, &tokbuf); token != NULL; token = strtok_r(NULL, sep, &tokbuf)) { namelen = strcspn(token, "0123456789"); instlen = strspn(token+namelen, "0123456789"); (void) strncpy(namebuf, token, namelen); namebuf[namelen] = '\0'; if ((j = map_name(namebuf)) < 0) continue; /* skip names that don't map */ if (instlen == 0) { (void) strncpy(instbuf, "0", 2); } else { (void) strncpy(instbuf, token+namelen, instlen); instbuf[instlen] = '\0'; } if (nvlist_add_string(hc_nvl[i], FM_FMRI_HC_NAME, tr_tbl[j].hc_component) != 0 || nvlist_add_string(hc_nvl[i], FM_FMRI_HC_ID, instbuf) != 0) return (-1); i++; } return (1); }
static gint post_sync (GnomePilotConduit *conduit, GnomePilotDBInfo *dbi, EAddrConduitContext *ctxt) { GList *changed; gchar *filename, *change_id; LOG (g_message ( "post_sync: Address Conduit v.%s", CONDUIT_VERSION )); g_free (ctxt->cfg->last_uri); ctxt->cfg->last_uri = g_strdup (e_book_get_uri (ctxt->ebook)); addrconduit_save_configuration (ctxt->cfg); filename = map_name (ctxt); e_pilot_map_write (filename, ctxt->map); g_free (filename); /* FIX ME ugly hack - our changes musn't count, this does introduce * a race condition if anyone changes a record elsewhere during sycnc */ change_id = g_strdup_printf ("pilot-sync-evolution-addressbook-%d", ctxt->cfg->pilot_id); if (e_book_get_changes (ctxt->ebook, change_id, &changed, NULL)) e_book_free_change_list (changed); g_free (change_id); LOG (g_message ( "---------------------------------------------------------\n" )); return 0; }
static int npmodule_map (lua_State *L) { const char *mname = lua_tolstring(L,1,0); std::stringstream ss(""); if ( mname ) { NPString map_name(mname); if ( !MapsManager::existsMap(map_name) ) { ss << "Map '" << map_name << "' doesn't exists"; } else { ss << "Switching to map '" << map_name << "'"; GameControlRulesDaemon::forceMapChange(map_name); } } else { ss << "Missing map name parameter"; } lua_pushstring( L, ss.str().c_str() ); return 1; }
static gint post_sync (GnomePilotConduit *conduit, GnomePilotDBInfo *dbi, EMemoConduitContext *ctxt) { GList *changed; gchar *filename, *change_id; unsigned char *buf; int dlpRetVal, len; buf = (unsigned char*)g_malloc (0xffff); len = pack_MemoAppInfo (&(ctxt->ai), buf, 0xffff); dlpRetVal = dlp_WriteAppBlock (dbi->pilot_socket, dbi->db_handle, (unsigned char *)buf, len); g_free (buf); if (dlpRetVal < 0) { WARN (_("Could not write pilot's Memo application block")); WARN ("dlp_WriteAppBlock(...) = %d", dlpRetVal); gnome_pilot_conduit_error (conduit, _("Could not write pilot's Memo application block")); return -1; } LOG (g_message ( "post_sync: Memo Conduit v.%s", CONDUIT_VERSION )); g_free (ctxt->cfg->last_uri); ctxt->cfg->last_uri = g_strdup (e_cal_get_uri (ctxt->client)); memoconduit_save_configuration (ctxt->cfg); filename = map_name (ctxt); e_pilot_map_write (filename, ctxt->map); g_free (filename); /* FIX ME ugly hack - our changes musn't count, this does introduce * a race condition if anyone changes a record elsewhere during sycnc */ change_id = g_strdup_printf ("pilot-sync-evolution-memo-%d", ctxt->cfg->pilot_id); if (e_cal_get_changes (ctxt->client, change_id, &changed, NULL)) e_cal_free_change_list (changed); g_free (change_id); LOG (g_message ( "---------------------------------------------------------\n" )); return 0; }
int cmd_count_components(const char *str, char sep) { int num = 0; const char *cptr = str; if (*cptr == sep) cptr++; /* skip initial sep */ if (strlen(cptr) > 0) num = 1; while ((cptr = strchr(cptr, sep)) != NULL) { cptr++; if (cptr == NULL || strcmp(cptr, "") == 0) break; if (map_name(cptr) >= 0) num++; } return (num); }
int map_read (char *file, long pos, struct drop **drops, int noisy) { register int i, md, msgp; register char *cp; struct drop d; register struct drop *mp, *dp; if ((md = open (cp = map_name (file), O_RDONLY)) == NOTOK || map_chk (cp, md, mp = &d, pos, noisy)) { if (md != NOTOK) close (md); return 0; } msgp = mp->d_id; dp = (struct drop *) calloc ((size_t) (msgp + 1), sizeof(*dp)); if (dp == NULL) { close (md); return 0; } memcpy((char *) dp, (char *) mp, sizeof(*dp)); lseek (md, (off_t) sizeof(*mp), SEEK_SET); if ((i = read (md, (char *) (dp + 1), msgp * sizeof(*dp))) < (int) sizeof(*dp)) { i = 0; free ((char *) dp); } else { #ifdef NTOHLSWAP register struct drop *tdp; int j; for (j = 0, tdp = dp; j < i / sizeof(*dp); j++, tdp++) { tdp->d_id = ntohl(tdp->d_id); tdp->d_size = ntohl(tdp->d_size); tdp->d_start = ntohl(tdp->d_start); tdp->d_stop = ntohl(tdp->d_stop); } #endif *drops = dp; } close (md); return (i / sizeof(*dp)); }
void sync_boxes( store_t *ctx[], const char *names[], channel_conf_t *chan, void (*cb)( int sts, void *aux ), void *aux ) { sync_vars_t *svars; int t; svars = nfcalloc( sizeof(*svars) ); svars->t[1] = 1; svars->ref_count = 1; svars->cb = cb; svars->aux = aux; svars->ctx[0] = ctx[0]; svars->ctx[1] = ctx[1]; svars->chan = chan; svars->uidval[0] = svars->uidval[1] = -1; svars->srecadd = &svars->srecs; for (t = 0; t < 2; t++) { ctx[t]->orig_name = (!names[t] || (ctx[t]->conf->map_inbox && !strcmp( ctx[t]->conf->map_inbox, names[t] ))) ? "INBOX" : names[t]; ctx[t]->name = nfstrdup( ctx[t]->orig_name ); if (ctx[t]->conf->flat_delim && map_name( ctx[t]->name, '/', ctx[t]->conf->flat_delim ) < 0) { error( "Error: canonical mailbox name '%s' contains flattened hierarchy delimiter\n", ctx[t]->name ); svars->ret = SYNC_FAIL; sync_bail3( svars ); return; } ctx[t]->uidvalidity = -1; set_bad_callback( ctx[t], store_bad, AUX ); svars->drv[t] = ctx[t]->conf->driver; } /* Both boxes must be fully set up at this point, so that error exit paths * don't run into uninitialized variables. */ for (t = 0; t < 2; t++) { info( "Selecting %s %s...\n", str_ms[t], ctx[t]->orig_name ); DRIVER_CALL(select( ctx[t], (chan->ops[t] & OP_CREATE) != 0, box_selected, AUX )); } }
void CMapReader::LoadResources() { CResourcesManager* rs = CResourcesManager::GetInstance(); CCamera* c = rs->_camera; _map_type = rs->_map_type; wstring folder_background(MAP_FOLDER); //Thư mục chứa toàn bộ background wstring map_name(_map_name); wstring full_folder_path(folder_background + map_name + L"/"); //Đường dẫn full đến background wstring file_object(full_folder_path + L"object_" + map_name + L".txt"); wstring file_quadtree(full_folder_path + L"quadtree_" + map_name + L".png"); ifstream infile(file_object); infile >> _total_object; int id; int type; float x; float y; int width; int height; while (infile >> id >> type >> x >> y >> width >> height) { SpecificType ptype = (SpecificType)type; D3DXVECTOR3 pos = c->Transform(x, y); CObject* obj = CreateObject(id, ptype, pos, width, height); if (obj != NULL) { _list_object[id] = obj; obj->LoadResources(); } } }
int Build(char *mddev, struct mddev_dev *devlist, struct shape *s, struct context *c) { /* Build a linear or raid0 arrays without superblocks * We cannot really do any checks, we just do it. * For md_version < 0.90.0, we call REGISTER_DEV * with the device numbers, and then * START_MD giving the "geometry" * geometry is 0xpp00cc * where pp is personality: 1==linear, 2=raid0 * cc = chunk size factor: 0==4k, 1==8k etc. * * For md_version >= 0.90.0 we call * SET_ARRAY_INFO, ADD_NEW_DISK, RUN_ARRAY * */ int i; int vers; struct stat stb; int subdevs = 0, missing_disks = 0; struct mddev_dev *dv; int bitmap_fd; unsigned long long bitmapsize; int mdfd; char chosen_name[1024]; int uuid[4] = {0,0,0,0}; struct map_ent *map = NULL; /* scan all devices, make sure they really are block devices */ for (dv = devlist; dv; dv=dv->next) { subdevs++; if (strcmp("missing", dv->devname) == 0) { missing_disks++; continue; } if (stat(dv->devname, &stb)) { pr_err("Cannot find %s: %s\n", dv->devname, strerror(errno)); return 1; } if ((stb.st_mode & S_IFMT) != S_IFBLK) { pr_err("%s is not a block device.\n", dv->devname); return 1; } } if (s->raiddisks != subdevs) { pr_err("requested %d devices in array but listed %d\n", s->raiddisks, subdevs); return 1; } if (s->layout == UnSet) switch(s->level) { default: /* no layout */ s->layout = 0; break; case 10: s->layout = 0x102; /* near=2, far=1 */ if (c->verbose > 0) pr_err("layout defaults to n1\n"); break; case 5: case 6: s->layout = map_name(r5layout, "default"); if (c->verbose > 0) pr_err("layout defaults to %s\n", map_num(r5layout, s->layout)); break; case LEVEL_FAULTY: s->layout = map_name(faultylayout, "default"); if (c->verbose > 0) pr_err("layout defaults to %s\n", map_num(faultylayout, s->layout)); break; } /* We need to create the device. It can have no name. */ map_lock(&map); mdfd = create_mddev(mddev, NULL, c->autof, LOCAL, chosen_name); if (mdfd < 0) { map_unlock(&map); return 1; } mddev = chosen_name; map_update(&map, fd2devnm(mdfd), "none", uuid, chosen_name); map_unlock(&map); vers = md_get_version(mdfd); /* looks Ok, go for it */ if (vers >= 9000) { mdu_array_info_t array; array.level = s->level; if (s->size == MAX_SIZE) s->size = 0; array.size = s->size; array.nr_disks = s->raiddisks; array.raid_disks = s->raiddisks; array.md_minor = 0; if (fstat(mdfd, &stb)==0) array.md_minor = minor(stb.st_rdev); array.not_persistent = 1; array.state = 0; /* not clean, but no errors */ if (s->assume_clean) array.state |= 1; array.active_disks = s->raiddisks - missing_disks; array.working_disks = s->raiddisks - missing_disks; array.spare_disks = 0; array.failed_disks = missing_disks; if (s->chunk == 0 && (s->level==0 || s->level==LEVEL_LINEAR)) s->chunk = 64; array.chunk_size = s->chunk*1024; array.layout = s->layout; if (ioctl(mdfd, SET_ARRAY_INFO, &array)) { pr_err("SET_ARRAY_INFO failed for %s: %s\n", mddev, strerror(errno)); goto abort; } } else if (s->bitmap_file) { pr_err("bitmaps not supported with this kernel\n"); goto abort; } if (s->bitmap_file && strcmp(s->bitmap_file, "none") == 0) s->bitmap_file = NULL; if (s->bitmap_file && s->level <= 0) { pr_err("bitmaps not meaningful with level %s\n", map_num(pers, s->level)?:"given"); goto abort; }
struct mdinfo *sysfs_read(int fd, char *devnm, unsigned long options) { char fname[PATH_MAX]; char buf[PATH_MAX]; char *base; char *dbase; struct mdinfo *sra; struct mdinfo *dev, **devp; DIR *dir = NULL; struct dirent *de; sra = xcalloc(1, sizeof(*sra)); sysfs_init(sra, fd, devnm); if (sra->sys_name[0] == 0) { free(sra); return NULL; } sprintf(fname, "/sys/block/%s/md/", sra->sys_name); base = fname + strlen(fname); sra->devs = NULL; if (options & GET_VERSION) { strcpy(base, "metadata_version"); if (load_sys(fname, buf, sizeof(buf))) goto abort; if (strncmp(buf, "none", 4) == 0) { sra->array.major_version = sra->array.minor_version = -1; strcpy(sra->text_version, ""); } else if (strncmp(buf, "external:", 9) == 0) { sra->array.major_version = -1; sra->array.minor_version = -2; strcpy(sra->text_version, buf+9); } else { sscanf(buf, "%d.%d", &sra->array.major_version, &sra->array.minor_version); strcpy(sra->text_version, buf); } } if (options & GET_LEVEL) { strcpy(base, "level"); if (load_sys(fname, buf, sizeof(buf))) goto abort; sra->array.level = map_name(pers, buf); } if (options & GET_LAYOUT) { strcpy(base, "layout"); if (load_sys(fname, buf, sizeof(buf))) goto abort; sra->array.layout = strtoul(buf, NULL, 0); } if (options & GET_DISKS) { strcpy(base, "raid_disks"); if (load_sys(fname, buf, sizeof(buf))) goto abort; sra->array.raid_disks = strtoul(buf, NULL, 0); } if (options & GET_DEGRADED) { strcpy(base, "degraded"); if (load_sys(fname, buf, sizeof(buf))) goto abort; sra->array.failed_disks = strtoul(buf, NULL, 0); } if (options & GET_COMPONENT) { strcpy(base, "component_size"); if (load_sys(fname, buf, sizeof(buf))) goto abort; sra->component_size = strtoull(buf, NULL, 0); /* sysfs reports "K", but we want sectors */ sra->component_size *= 2; } if (options & GET_CHUNK) { strcpy(base, "chunk_size"); if (load_sys(fname, buf, sizeof(buf))) goto abort; sra->array.chunk_size = strtoul(buf, NULL, 0); } if (options & GET_CACHE) { strcpy(base, "stripe_cache_size"); if (load_sys(fname, buf, sizeof(buf))) /* Probably level doesn't support it */ sra->cache_size = 0; else sra->cache_size = strtoul(buf, NULL, 0); } if (options & GET_MISMATCH) { strcpy(base, "mismatch_cnt"); if (load_sys(fname, buf, sizeof(buf))) goto abort; sra->mismatch_cnt = strtoul(buf, NULL, 0); } if (options & GET_SAFEMODE) { int scale = 1; int dot = 0; unsigned i; unsigned long msec; size_t len; strcpy(base, "safe_mode_delay"); if (load_sys(fname, buf, sizeof(buf))) goto abort; /* remove a period, and count digits after it */ len = strlen(buf); for (i = 0; i < len; i++) { if (dot) { if (isdigit(buf[i])) { buf[i-1] = buf[i]; scale *= 10; } buf[i] = 0; } else if (buf[i] == '.') { dot=1; buf[i] = 0; } } msec = strtoul(buf, NULL, 10); msec = (msec * 1000) / scale; sra->safe_mode_delay = msec; } if (options & GET_BITMAP_LOCATION) { strcpy(base, "bitmap/location"); if (load_sys(fname, buf, sizeof(buf))) goto abort; if (strncmp(buf, "file", 4) == 0) sra->bitmap_offset = 1; else if (strncmp(buf, "none", 4) == 0) sra->bitmap_offset = 0; else if (buf[0] == '+') sra->bitmap_offset = strtol(buf+1, NULL, 10); else goto abort; } if (options & GET_ARRAY_STATE) { strcpy(base, "array_state"); if (load_sys(fname, sra->sysfs_array_state, sizeof(sra->sysfs_array_state))) goto abort; } else sra->sysfs_array_state[0] = 0; if (! (options & GET_DEVS)) return sra; /* Get all the devices as well */ *base = 0; dir = opendir(fname); if (!dir) goto abort; sra->array.spare_disks = 0; devp = &sra->devs; sra->devs = NULL; while ((de = readdir(dir)) != NULL) { char *ep; if (de->d_ino == 0 || strncmp(de->d_name, "dev-", 4) != 0) continue; strcpy(base, de->d_name); dbase = base + strlen(base); *dbase++ = '/'; dev = xcalloc(1, sizeof(*dev)); /* Always get slot, major, minor */ strcpy(dbase, "slot"); if (load_sys(fname, buf, sizeof(buf))) { /* hmm... unable to read 'slot' maybe the device * is going away? */ strcpy(dbase, "block"); if (readlink(fname, buf, sizeof(buf)) < 0 && errno != ENAMETOOLONG) { /* ...yup device is gone */ free(dev); continue; } else { /* slot is unreadable but 'block' link * still intact... something bad is happening * so abort */ free(dev); goto abort; } } strcpy(dev->sys_name, de->d_name); dev->disk.raid_disk = strtoul(buf, &ep, 10); if (*ep) dev->disk.raid_disk = -1; strcpy(dbase, "block/dev"); if (load_sys(fname, buf, sizeof(buf))) { /* assume this is a stale reference to a hot * removed device */ free(dev); continue; } sra->array.nr_disks++; sscanf(buf, "%d:%d", &dev->disk.major, &dev->disk.minor); /* special case check for block devices that can go 'offline' */ strcpy(dbase, "block/device/state"); if (load_sys(fname, buf, sizeof(buf)) == 0 && strncmp(buf, "offline", 7) == 0) { free(dev); continue; } /* finally add this disk to the array */ *devp = dev; devp = & dev->next; dev->next = NULL; if (options & GET_OFFSET) { strcpy(dbase, "offset"); if (load_sys(fname, buf, sizeof(buf))) goto abort; dev->data_offset = strtoull(buf, NULL, 0); strcpy(dbase, "new_offset"); if (load_sys(fname, buf, sizeof(buf)) == 0) dev->new_data_offset = strtoull(buf, NULL, 0); else dev->new_data_offset = dev->data_offset; } if (options & GET_SIZE) { strcpy(dbase, "size"); if (load_sys(fname, buf, sizeof(buf))) goto abort; dev->component_size = strtoull(buf, NULL, 0) * 2; } if (options & GET_STATE) { dev->disk.state = 0; strcpy(dbase, "state"); if (load_sys(fname, buf, sizeof(buf))) goto abort; if (strstr(buf, "in_sync")) dev->disk.state |= (1<<MD_DISK_SYNC); if (strstr(buf, "faulty")) dev->disk.state |= (1<<MD_DISK_FAULTY); if (dev->disk.state == 0) sra->array.spare_disks++; } if (options & GET_ERROR) { strcpy(buf, "errors"); if (load_sys(fname, buf, sizeof(buf))) goto abort; dev->errors = strtoul(buf, NULL, 0); } } closedir(dir); return sra; abort: if (dir) closedir(dir); sysfs_free(sra); return NULL; }
/*! * \brief * Processes an xml document to parse the map part definition it contains and add it to the list. * * \param definition_path * The path to the xml document on disk. * * \returns * Returns true if the xml was valid and processed successfully otherwise returns false. * * Processes an xml document to parse the map part definition it contains and add it to the list. */ static bool AddMapDefinition(const char* definition_path) { TiXmlDocument definition; // load the map part definition definition.LoadFile(definition_path); // check the xml loaded correctly if(definition.Error()) { blam::console_printf("Failed to load and parse the map part definition\nError: %s", definition.ErrorDesc()); return false; } // get the xml root TiXmlElement* root_node = definition.FirstChildElement("osHTTPServer"); if(!root_node) { blam::console_printf(false, "The map part definition has no osHTTPServer root node"); return false; } // get the map element const TiXmlElement* map_node = root_node->FirstChildElement("map_download"); if(!map_node) { blam::console_printf(false, "The map part definition has no map_download node"); return false; } const char* name = map_node->Attribute("name"); const char* md5 = map_node->Attribute("md5"); const char* algorithm = map_node->Attribute("algorithm"); const char* host_directory = map_node->Attribute("host_directory"); // check the md5 string is the correct length bool md5_valid = false; if(md5) md5_valid = (strlen(md5) == 32); // if the map is valid, create a new map element if(name && md5 && md5_valid && algorithm) { // remove the extension from the map name std::string map_name(name); std::string::size_type extension_offset = std::string::npos; if((extension_offset = map_name.find(Cache::K_MAP_FILE_EXTENSION)) != std::string::npos) map_name.resize(extension_offset); else if((extension_offset = map_name.find(Cache::K_MAP_FILE_EXTENSION_YELO)) != std::string::npos) map_name.resize(extension_offset); if(FindMap(map_name.c_str())) { blam::console_printf(false, "Map definition for %s already exists", map_name.c_str()); return false; } c_map_element* map_element = new c_map_element(); map_element->Ctor(); // assign the name of the map and remove its extension for later comparisons map_element->m_name = map_name; // create a copy of the maps part definition to send to the client // remove the host_directory attribute from the client copy as it is unnecessary map_element->m_part_definition = map_node->Clone()->ToElement(); map_element->m_part_definition->RemoveAttribute("host_directory"); // add the parts to the map element, host_directory can be null if(!AddMapParts(map_element, map_node, host_directory)) { // a problem occurred when adding the maps part elements so delete the map element and return delete map_element; return false; } // add the completed map element to the definition lists if(!AddMapToList(map_element)) { RemoveMapParts(map_element); delete map_element; return false; } } else { if(!name) blam::console_printf(false, "A map node is missing its name"); if(!md5) blam::console_printf(false, "A map node is missing its md5 checksum"); else if(!md5_valid) blam::console_printf(false, "A map nodes md5 checksum is too long/short"); if(!algorithm) blam::console_printf(false, "A map node does not state its compression algorithm"); if(!host_directory) blam::console_printf(false, "A map node is missing its host_directory"); return false; } return true; }
void arrayline(char *line) { char *w; struct mddev_ident_s mis; mddev_ident_t mi; mis.uuid_set = 0; mis.super_minor = UnSet; mis.level = UnSet; mis.raid_disks = UnSet; mis.spare_disks = UnSet; mis.devices = NULL; mis.devname = NULL; mis.spare_group = NULL; mis.autof = 0; mis.next = NULL; mis.st = NULL; mis.bitmap_fd = -1; mis.name[0] = 0; for (w=dl_next(line); w!=line; w=dl_next(w)) { if (w[0] == '/') { if (mis.devname) fprintf(stderr, Name ": only give one device per ARRAY line: %s and %s\n", mis.devname, w); else mis.devname = w; } else if (strncasecmp(w, "uuid=", 5)==0 ) { if (mis.uuid_set) fprintf(stderr, Name ": only specify uuid once, %s ignored.\n", w); else { if (parse_uuid(w+5, mis.uuid)) mis.uuid_set = 1; else fprintf(stderr, Name ": bad uuid: %s\n", w); } } else if (strncasecmp(w, "super-minor=", 12)==0 ) { if (mis.super_minor != UnSet) fprintf(stderr, Name ": only specify super-minor once, %s ignored.\n", w); else { char *endptr; mis.super_minor= strtol(w+12, &endptr, 10); if (w[12]==0 || endptr[0]!=0 || mis.super_minor < 0) { fprintf(stderr, Name ": invalid super-minor number: %s\n", w); mis.super_minor = UnSet; } } } else if (strncasecmp(w, "name=", 5)==0) { if (mis.name[0]) fprintf(stderr, Name ": only specify name once, %s ignored.\n", w); else if (strlen(w+5) > 32) fprintf(stderr, Name ": name too long, ignoring %s\n", w); else strcpy(mis.name, w+5); } else if (strncasecmp(w, "devices=", 8 ) == 0 ) { if (mis.devices) fprintf(stderr, Name ": only specify devices once (use a comma separated list). %s ignored\n", w); else mis.devices = strdup(w+8); } else if (strncasecmp(w, "spare-group=", 12) == 0 ) { if (mis.spare_group) fprintf(stderr, Name ": only specify one spare group per array. %s ignored.\n", w); else mis.spare_group = strdup(w+12); } else if (strncasecmp(w, "level=", 6) == 0 ) { /* this is mainly for compatability with --brief output */ mis.level = map_name(pers, w+6); } else if (strncasecmp(w, "disks=", 6) == 0 ) { /* again, for compat */ mis.raid_disks = atoi(w+6); } else if (strncasecmp(w, "num-devices=", 12) == 0 ) { /* again, for compat */ mis.raid_disks = atoi(w+12); } else if (strncasecmp(w, "spares=", 7) == 0 ) { /* for warning if not all spares present */ mis.spare_disks = atoi(w+7); } else if (strncasecmp(w, "metadata=", 9) == 0) { /* style of metadata on the devices. */ int i; for(i=0; superlist[i] && !mis.st; i++) mis.st = superlist[i]->match_metadata_desc(w+9); if (!mis.st) fprintf(stderr, Name ": metadata format %s unknown, ignored.\n", w+9); } else if (strncasecmp(w, "auto=", 5) == 0 ) { /* whether to create device special files as needed */ if (strcasecmp(w+5, "no")==0) mis.autof = 0; else if (strcasecmp(w+5,"yes")==0 || strcasecmp(w+5,"md")==0) mis.autof = -1; else { /* There might be digits, and maybe a hyphen, at the end */ char *e = w+5 + strlen(w+5); int num = 4; int len; while (e > w+5 && isdigit(e[-1])) e--; if (*e) { num = atoi(e); if (num <= 0) num = 1; } if (e > w+5 && e[-1] == '-') e--; len = e - (w+5); if ((len == 3 && strncasecmp(w+5,"mdp",3)==0) || (len == 1 && strncasecmp(w+5,"p",1)==0) || (len >= 4 && strncasecmp(w+5,"part",4)==0)) mis.autof = num; else fprintf(stderr, Name ": auto type of \"%s\" ignored for %s\n", w+5, mis.devname?mis.devname:"unlabeled-array"); } } else { fprintf(stderr, Name ": unrecognised word on ARRAY line: %s\n", w); } } if (mis.devname == NULL) fprintf(stderr, Name ": ARRAY line with no device\n"); else if (mis.uuid_set == 0 && mis.devices == NULL && mis.super_minor == UnSet && mis.name[0] == 0) fprintf(stderr, Name ": ARRAY line %s has no identity information.\n", mis.devname); else { mi = malloc(sizeof(*mi)); *mi = mis; mi->devname = strdup(mis.devname); mi->next = NULL; *mddevlp = mi; mddevlp = &mi->next; } }
void arrayline(char *line) { char *w; struct mddev_ident_s mis; mddev_ident_t mi; mis.uuid_set = 0; mis.super_minor = UnSet; mis.level = UnSet; mis.raid_disks = UnSet; mis.spare_disks = 0; mis.devices = NULL; mis.devname = NULL; mis.spare_group = NULL; mis.autof = 0; mis.next = NULL; mis.st = NULL; mis.bitmap_fd = -1; mis.bitmap_file = NULL; mis.name[0] = 0; for (w=dl_next(line); w!=line; w=dl_next(w)) { if (w[0] == '/') { if (mis.devname) fprintf(stderr, Name ": only give one device per ARRAY line: %s and %s\n", mis.devname, w); else mis.devname = w; } else if (strncasecmp(w, "uuid=", 5)==0 ) { if (mis.uuid_set) fprintf(stderr, Name ": only specify uuid once, %s ignored.\n", w); else { if (parse_uuid(w+5, mis.uuid)) mis.uuid_set = 1; else fprintf(stderr, Name ": bad uuid: %s\n", w); } } else if (strncasecmp(w, "super-minor=", 12)==0 ) { if (mis.super_minor != UnSet) fprintf(stderr, Name ": only specify super-minor once, %s ignored.\n", w); else { char *endptr; mis.super_minor= strtol(w+12, &endptr, 10); if (w[12]==0 || endptr[0]!=0 || mis.super_minor < 0) { fprintf(stderr, Name ": invalid super-minor number: %s\n", w); mis.super_minor = UnSet; } } } else if (strncasecmp(w, "name=", 5)==0) { if (mis.name[0]) fprintf(stderr, Name ": only specify name once, %s ignored.\n", w); else if (strlen(w+5) > 32) fprintf(stderr, Name ": name too long, ignoring %s\n", w); else strcpy(mis.name, w+5); } else if (strncasecmp(w, "bitmap=", 7) == 0) { if (mis.bitmap_file) fprintf(stderr, Name ": only specify bitmap file once. %s ignored\n", w); else mis.bitmap_file = strdup(w+7); } else if (strncasecmp(w, "devices=", 8 ) == 0 ) { if (mis.devices) fprintf(stderr, Name ": only specify devices once (use a comma separated list). %s ignored\n", w); else mis.devices = strdup(w+8); } else if (strncasecmp(w, "spare-group=", 12) == 0 ) { if (mis.spare_group) fprintf(stderr, Name ": only specify one spare group per array. %s ignored.\n", w); else mis.spare_group = strdup(w+12); } else if (strncasecmp(w, "level=", 6) == 0 ) { /* this is mainly for compatability with --brief output */ mis.level = map_name(pers, w+6); } else if (strncasecmp(w, "disks=", 6) == 0 ) { /* again, for compat */ mis.raid_disks = atoi(w+6); } else if (strncasecmp(w, "num-devices=", 12) == 0 ) { /* again, for compat */ mis.raid_disks = atoi(w+12); } else if (strncasecmp(w, "spares=", 7) == 0 ) { /* for warning if not all spares present */ mis.spare_disks = atoi(w+7); } else if (strncasecmp(w, "metadata=", 9) == 0) { /* style of metadata on the devices. */ int i; for(i=0; superlist[i] && !mis.st; i++) mis.st = superlist[i]->match_metadata_desc(w+9); if (!mis.st) fprintf(stderr, Name ": metadata format %s unknown, ignored.\n", w+9); } else if (strncasecmp(w, "auto=", 5) == 0 ) { /* whether to create device special files as needed */ mis.autof = parse_auto(w+5, "auto type", 0); } else { fprintf(stderr, Name ": unrecognised word on ARRAY line: %s\n", w); } } if (mis.devname == NULL) fprintf(stderr, Name ": ARRAY line with no device\n"); else if (mis.uuid_set == 0 && mis.devices == NULL && mis.super_minor == UnSet && mis.name[0] == 0) fprintf(stderr, Name ": ARRAY line %s has no identity information.\n", mis.devname); else { mi = malloc(sizeof(*mi)); *mi = mis; mi->devname = strdup(mis.devname); mi->next = NULL; *mddevlp = mi; mddevlp = &mi->next; } }
void arrayline(char *line) { char *w; struct mddev_ident mis; struct mddev_ident *mi; mis.uuid_set = 0; mis.super_minor = UnSet; mis.level = UnSet; mis.raid_disks = UnSet; mis.spare_disks = 0; mis.devices = NULL; mis.devname = NULL; mis.spare_group = NULL; mis.autof = 0; mis.next = NULL; mis.st = NULL; mis.bitmap_fd = -1; mis.bitmap_file = NULL; mis.name[0] = 0; mis.container = NULL; mis.member = NULL; for (w=dl_next(line); w!=line; w=dl_next(w)) { if (w[0] == '/' || strchr(w, '=') == NULL) { /* This names the device, or is '<ignore>'. * The rules match those in create_mddev. * 'w' must be: * /dev/md/{anything} * /dev/mdNN * /dev/md_dNN * <ignore> * or anything that doesn't start '/' or '<' */ if (strcasecmp(w, "<ignore>") == 0 || strncmp(w, "/dev/md/", 8) == 0 || (w[0] != '/' && w[0] != '<') || (strncmp(w, "/dev/md", 7) == 0 && is_number(w+7)) || (strncmp(w, "/dev/md_d", 9) == 0 && is_number(w+9)) ) { /* This is acceptable */; if (mis.devname) pr_err("only give one " "device per ARRAY line: %s and %s\n", mis.devname, w); else mis.devname = w; }else { pr_err("%s is an invalid name for " "an md device - ignored.\n", w); } } else if (strncasecmp(w, "uuid=", 5)==0 ) { if (mis.uuid_set) pr_err("only specify uuid once, %s ignored.\n", w); else { if (parse_uuid(w+5, mis.uuid)) mis.uuid_set = 1; else pr_err("bad uuid: %s\n", w); } } else if (strncasecmp(w, "super-minor=", 12)==0 ) { if (mis.super_minor != UnSet) pr_err("only specify super-minor once, %s ignored.\n", w); else { char *endptr; int minor = strtol(w+12, &endptr, 10); if (w[12]==0 || endptr[0]!=0 || minor < 0) pr_err("invalid super-minor number: %s\n", w); else mis.super_minor = minor; } } else if (strncasecmp(w, "name=", 5)==0) { if (mis.name[0]) pr_err("only specify name once, %s ignored.\n", w); else if (strlen(w+5) > 32) pr_err("name too long, ignoring %s\n", w); else strcpy(mis.name, w+5); } else if (strncasecmp(w, "bitmap=", 7) == 0) { if (mis.bitmap_file) pr_err("only specify bitmap file once. %s ignored\n", w); else mis.bitmap_file = xstrdup(w+7); } else if (strncasecmp(w, "devices=", 8 ) == 0 ) { if (mis.devices) pr_err("only specify devices once (use a comma separated list). %s ignored\n", w); else mis.devices = xstrdup(w+8); } else if (strncasecmp(w, "spare-group=", 12) == 0 ) { if (mis.spare_group) pr_err("only specify one spare group per array. %s ignored.\n", w); else mis.spare_group = xstrdup(w+12); } else if (strncasecmp(w, "level=", 6) == 0 ) { /* this is mainly for compatability with --brief output */ mis.level = map_name(pers, w+6); } else if (strncasecmp(w, "disks=", 6) == 0 ) { /* again, for compat */ mis.raid_disks = atoi(w+6); } else if (strncasecmp(w, "num-devices=", 12) == 0 ) { /* again, for compat */ mis.raid_disks = atoi(w+12); } else if (strncasecmp(w, "spares=", 7) == 0 ) { /* for warning if not all spares present */ mis.spare_disks = atoi(w+7); } else if (strncasecmp(w, "metadata=", 9) == 0) { /* style of metadata on the devices. */ int i; for(i=0; superlist[i] && !mis.st; i++) mis.st = superlist[i]->match_metadata_desc(w+9); if (!mis.st) pr_err("metadata format %s unknown, ignored.\n", w+9); } else if (strncasecmp(w, "auto=", 5) == 0 ) { /* whether to create device special files as needed */ mis.autof = parse_auto(w+5, "auto type", 0); } else if (strncasecmp(w, "member=", 7) == 0) { /* subarray within a container */ mis.member = xstrdup(w+7); } else if (strncasecmp(w, "container=", 10) == 0) { /* the container holding this subarray. Either a device name * or a uuid */ mis.container = xstrdup(w+10); } else { pr_err("unrecognised word on ARRAY line: %s\n", w); } } if (mis.uuid_set == 0 && mis.devices == NULL && mis.super_minor == UnSet && mis.name[0] == 0 && (mis.container == NULL || mis.member == NULL)) pr_err("ARRAY line %s has no identity information.\n", mis.devname); else { mi = xmalloc(sizeof(*mi)); *mi = mis; mi->devname = mis.devname ? xstrdup(mis.devname) : NULL; mi->next = NULL; *mddevlp = mi; mddevlp = &mi->next; } }
static void find_server_names(const char *hdr, struct query *ctl, struct idlist **xmit_names) /* parse names out of a RFC822 header into an ID list */ /* hdr: RFC822 header in question */ /* ctl: list of permissible aliases */ /* xmit_names: list of recipient names parsed out */ { if (hdr == (char *)NULL) return; else { char *cp; for (cp = nxtaddr(hdr); cp != NULL; cp = nxtaddr(NULL)) { char *atsign; /* * Handle empty address from a To: header containing only * a comment. */ if (!*cp) continue; /* * If the name of the user begins with a qmail virtual * domain prefix, ignore the prefix. Doing this here * means qvirtual will work either with ordinary name * mapping or with a localdomains option. */ if (ctl->server.qvirtual) { int sl = strlen(ctl->server.qvirtual); if (!strncasecmp((char *)cp, ctl->server.qvirtual, sl)) cp += sl; } if ((atsign = strchr((char *)cp, '@'))) { struct idlist *idp; /* try to match full address first, this takes * precedence over localdomains and alias mappings */ if (map_address(cp, ctl, xmit_names)) goto nomap; /* * Does a trailing segment of the hostname match something * on the localdomains list? If so, save the whole name * and keep going. */ for (idp = ctl->server.localdomains; idp; idp = idp->next) { char *rhs; rhs = atsign + (strlen(atsign) - strlen(idp->id)); if (rhs > atsign && (rhs[-1] == '.' || rhs[-1] == '@') && strcasecmp(rhs, idp->id) == 0) { if (outlevel >= O_DEBUG) report(stdout, GT_("passed through %s matching %s\n"), cp, idp->id); save_str(xmit_names, (const char *)cp, XMIT_ACCEPT); accept_count++; goto nomap; } } /* if we matched a local domain, idp != NULL */ if (!idp) { /* * Check to see if the right-hand part is an alias * or MX equivalent of the mailserver. If it's * not, skip this name. If it is, we'll keep * going and try to find a mapping to a client name. */ if (!is_host_alias(atsign+1, ctl, &ai0)) { save_str(xmit_names, cp, XMIT_REJECT); reject_count++; continue; } } atsign[0] = '\0'; map_name(cp, ctl, xmit_names); nomap:; } } } }
int map_write (char *mailbox, int md, int id, long last, off_t start, off_t stop, long pos, int size, int noisy) { register int i; int clear, fd, td; char *file; register struct drop *dp; struct drop d1, d2, *rp; register FILE *fp; struct stat st; if ((fd = map_open (file = map_name (mailbox), md)) == NOTOK) return NOTOK; if ((fstat (fd, &st) == OK) && (st.st_size > 0)) clear = 0; else clear = 1; if (!clear && map_chk (file, fd, &d1, pos, noisy)) { (void) m_unlink (file); mbx_close (file, fd); if ((fd = map_open (file, md)) == NOTOK) return NOTOK; clear++; } if (clear) { if ((td = dup (md)) == NOTOK || (fp = fdopen (td, "r")) == NULL) { if (noisy) admonish (file, "unable to %s", td != NOTOK ? "fdopen" : "dup"); if (td != NOTOK) close (td); mbx_close (file, fd); return NOTOK; } switch (i = mbx_read (fp, 0, &rp, noisy)) { case NOTOK: fclose (fp); mbx_close (file, fd); return NOTOK; case OK: fclose (fp); break; default: d1.d_id = 0; for (dp = rp; i-- >0; dp++) { if (dp->d_start == start) dp->d_id = id; lseek (fd, (off_t) (++d1.d_id * sizeof(*dp)), SEEK_SET); if (write (fd, (char *) dp, sizeof(*dp)) != sizeof(*dp)) { if (noisy) admonish (file, "write error"); mbx_close (file, fd); fclose (fp); return NOTOK; } } free ((char *) rp); fclose (fp); break; } } else { if (last == 0) last = d1.d_start; dp = &d2; dp->d_id = id; dp->d_size = (long) (size ? size : mbx_size (fd, start, stop)); dp->d_start = start; dp->d_stop = stop; lseek (fd, (off_t) (++d1.d_id * sizeof(*dp)), SEEK_SET); if (write (fd, (char *) dp, sizeof(*dp)) != sizeof(*dp)) { if (noisy) admonish (file, "write error"); mbx_close (file, fd); return NOTOK; } } dp = &d1; dp->d_size = DRVRSN; dp->d_start = (long) last; dp->d_stop = lseek (md, (off_t) 0, SEEK_CUR); lseek (fd, (off_t) 0, SEEK_SET); if (write (fd, (char *) dp, sizeof(*dp)) != sizeof(*dp)) { if (noisy) admonish (file, "write error"); mbx_close (file, fd); return NOTOK; } mbx_close (file, fd); return OK; }
/* Pilot syncing callbacks */ static gint pre_sync (GnomePilotConduit *conduit, GnomePilotDBInfo *dbi, EMemoConduitContext *ctxt) { GnomePilotConduitSyncAbs *abs_conduit; GList *l; int len; unsigned char *buf; char *filename, *change_id; icalcomponent *icalcomp; gint num_records, add_records = 0, mod_records = 0, del_records = 0; #ifdef PILOT_LINK_0_12 pi_buffer_t * buffer; #endif abs_conduit = GNOME_PILOT_CONDUIT_SYNC_ABS (conduit); LOG (g_message ( "---------------------------------------------------------\n" )); LOG (g_message ( "pre_sync: Memo Conduit v.%s", CONDUIT_VERSION )); g_message ("Memo Conduit v.%s", CONDUIT_VERSION); ctxt->dbi = dbi; ctxt->client = NULL; if (start_calendar_server (ctxt) != 0) { WARN(_("Could not start evolution-data-server")); gnome_pilot_conduit_error (conduit, _("Could not start evolution-data-server")); return -1; } /* Get the timezone */ ctxt->timezone = get_default_timezone (); if (ctxt->timezone == NULL) return -1; LOG (g_message ( " Using timezone: %s", icaltimezone_get_tzid (ctxt->timezone) )); /* Set the default timezone on the backend. */ if (ctxt->timezone && !e_cal_set_default_timezone (ctxt->client, ctxt->timezone, NULL)) return -1; /* Get the default component */ if (!e_cal_get_default_object (ctxt->client, &icalcomp, NULL)) return -1; ctxt->default_comp = e_cal_component_new (); if (!e_cal_component_set_icalcomponent (ctxt->default_comp, icalcomp)) { g_object_unref (ctxt->default_comp); icalcomponent_free (icalcomp); return -1; } /* Load the uid <--> pilot id map */ filename = map_name (ctxt); e_pilot_map_read (filename, &ctxt->map); g_free (filename); /* Get the local database */ if (!e_cal_get_object_list_as_comp (ctxt->client, "#t", &ctxt->comps, NULL)) return -1; /* Count and hash the changes */ change_id = g_strdup_printf ("pilot-sync-evolution-memo-%d", ctxt->cfg->pilot_id); if (!e_cal_get_changes (ctxt->client, change_id, &ctxt->changed, NULL)) return -1; ctxt->changed_hash = g_hash_table_new (g_str_hash, g_str_equal); g_free (change_id); for (l = ctxt->changed; l != NULL; l = l->next) { ECalChange *ccc = l->data; const char *uid; e_cal_component_get_uid (ccc->comp, &uid); if (!e_pilot_map_uid_is_archived (ctxt->map, uid)) { g_hash_table_insert (ctxt->changed_hash, g_strdup (uid), ccc); switch (ccc->type) { case E_CAL_CHANGE_ADDED: add_records++; break; case E_CAL_CHANGE_MODIFIED: mod_records++; break; case E_CAL_CHANGE_DELETED: del_records++; break; } } else if (ccc->type == E_CAL_CHANGE_DELETED) { e_pilot_map_remove_by_uid (ctxt->map, uid); } } /* Set the count information */ num_records = g_list_length (ctxt->comps); gnome_pilot_conduit_sync_abs_set_num_local_records(abs_conduit, num_records); gnome_pilot_conduit_sync_abs_set_num_new_local_records (abs_conduit, add_records); gnome_pilot_conduit_sync_abs_set_num_updated_local_records (abs_conduit, mod_records); gnome_pilot_conduit_sync_abs_set_num_deleted_local_records(abs_conduit, del_records); g_message("num_records: %d\nadd_records: %d\nmod_records: %d\ndel_records: %d\n", num_records, add_records, mod_records, del_records); #ifdef PILOT_LINK_0_12 buffer = pi_buffer_new(DLP_BUF_SIZE); if(buffer == NULL){ pi_set_error(dbi->pilot_socket, PI_ERR_GENERIC_MEMORY); return -1; } len = dlp_ReadAppBlock (dbi->pilot_socket, dbi->db_handle, 0, DLP_BUF_SIZE, buffer); #else buf = (unsigned char*)g_malloc (0xffff); len = dlp_ReadAppBlock (dbi->pilot_socket, dbi->db_handle, 0, (unsigned char *)buf, 0xffff); #endif if (len < 0) { WARN (_("Could not read pilot's Memo application block")); WARN ("dlp_ReadAppBlock(...) = %d", len); gnome_pilot_conduit_error (conduit, _("Could not read pilot's Memo application block")); return -1; } #ifdef PILOT_LINK_0_12 buf = g_new0 (unsigned char,buffer->used); memcpy(buf, buffer->data, buffer->used); unpack_MemoAppInfo (&(ctxt->ai), buf, len); pi_buffer_free(buffer); #else unpack_MemoAppInfo (&(ctxt->ai), buf, len); #endif g_free (buf); lastDesktopUniqueID = 128; check_for_slow_setting (conduit, ctxt); if (ctxt->cfg->sync_type == GnomePilotConduitSyncTypeCopyToPilot || ctxt->cfg->sync_type == GnomePilotConduitSyncTypeCopyFromPilot) ctxt->map->write_touched_only = TRUE; return 0; }
/* Pilot syncing callbacks */ static gint pre_sync (GnomePilotConduit *conduit, GnomePilotDBInfo *dbi, EAddrConduitContext *ctxt) { GnomePilotConduitSyncAbs *abs_conduit; EBookQuery *query; GList *l; int len; char *filename; char *change_id; char *auth; gint num_records, add_records = 0, mod_records = 0, del_records = 0; #ifdef PILOT_LINK_0_12 pi_buffer_t *buffer; #else unsigned char *buf; #endif abs_conduit = GNOME_PILOT_CONDUIT_SYNC_ABS (conduit); LOG (g_message ( "---------------------------------------------------------\n" )); LOG (g_message ( "pre_sync: Addressbook Conduit v.%s", CONDUIT_VERSION )); /* g_message ("Addressbook Conduit v.%s", CONDUIT_VERSION); */ ctxt->dbi = dbi; if (ctxt->cfg->source) { ctxt->ebook = e_book_new (ctxt->cfg->source, NULL); } else { ctxt->ebook = e_book_new_default_addressbook (NULL); } auth = (gchar *)e_source_get_property (ctxt->cfg->source, "auth"); if (auth) { LOG (g_message ("contacts needs authentication\n")); g_signal_connect (ctxt->ebook, "auth_required", G_CALLBACK (addressbook_authenticate), ctxt->cfg->source); } if (!ctxt->ebook || !e_book_open (ctxt->ebook, TRUE, NULL)) { WARN(_("Could not load addressbook")); gnome_pilot_conduit_error (conduit, _("Could not load addressbook")); return -1; } /* Load the uid <--> pilot id mappings */ filename = map_name (ctxt); e_pilot_map_read (filename, &ctxt->map); g_free (filename); /* Get a list of all contacts */ if (!(query = e_book_query_any_field_contains (""))) { LOG (g_warning ("Failed to get EBookQuery")); return -1; } if (!e_book_get_contacts (ctxt->ebook, query, &ctxt->cards, NULL)) { LOG (g_warning ("Failed to get Contacts")); e_book_query_unref (query); return -1; } e_book_query_unref (query); /* Count and hash the changes */ change_id = g_strdup_printf ("pilot-sync-evolution-addressbook-%d", ctxt->cfg->pilot_id); if (!e_book_get_changes (ctxt->ebook, change_id, &ctxt->changed, NULL)) return -1; ctxt->changed_hash = g_hash_table_new (g_str_hash, g_str_equal); g_free (change_id); for (l = ctxt->changed; l != NULL; l = l->next) { EBookChange *ebc = l->data; const char *uid; uid = e_contact_get_const (ebc->contact, E_CONTACT_UID); if (!e_pilot_map_uid_is_archived (ctxt->map, uid)) { g_hash_table_insert (ctxt->changed_hash, g_strdup (uid), ebc); switch (ebc->change_type) { case E_BOOK_CHANGE_CARD_ADDED: add_records++; break; case E_BOOK_CHANGE_CARD_MODIFIED: mod_records++; break; case E_BOOK_CHANGE_CARD_DELETED: del_records++; break; } } else if (ebc->change_type == E_BOOK_CHANGE_CARD_DELETED) { e_pilot_map_remove_by_uid (ctxt->map, uid); } } /* Set the count information */ num_records = g_list_length (ctxt->cards); gnome_pilot_conduit_sync_abs_set_num_local_records(abs_conduit, num_records); gnome_pilot_conduit_sync_abs_set_num_new_local_records (abs_conduit, add_records); gnome_pilot_conduit_sync_abs_set_num_updated_local_records (abs_conduit, mod_records); gnome_pilot_conduit_sync_abs_set_num_deleted_local_records(abs_conduit, del_records); #ifdef PILOT_LINK_0_12 buffer = pi_buffer_new(DLP_BUF_SIZE); if(buffer == NULL){ return pi_set_error(dbi->pilot_socket, PI_ERR_GENERIC_MEMORY); } len = dlp_ReadAppBlock (dbi->pilot_socket, dbi->db_handle, 0, DLP_BUF_SIZE, buffer); #else buf = (unsigned char*)g_malloc (0xffff); len = dlp_ReadAppBlock (dbi->pilot_socket, dbi->db_handle, 0, (unsigned char *)buf, 0xffff); #endif if (len < 0) { WARN (_("Could not read pilot's Address application block")); WARN ("dlp_ReadAppBlock(...) = %d", len); gnome_pilot_conduit_error (conduit, _("Could not read pilot's Address application block")); return -1; } #ifdef PILOT_LINK_0_12 unpack_AddressAppInfo (&(ctxt->ai), buffer->data, len); pi_buffer_free (buffer); #else unpack_AddressAppInfo (&(ctxt->ai), buf, len); g_free (buf); #endif check_for_slow_setting (conduit, ctxt); if (ctxt->cfg->sync_type == GnomePilotConduitSyncTypeCopyToPilot || ctxt->cfg->sync_type == GnomePilotConduitSyncTypeCopyFromPilot) ctxt->map->write_touched_only = TRUE; return 0; }