static void callback_modified_extent(area_context_t *context) { /* extent is third tab (page 2) */ if(!current_tab_is(context, TAB_LABEL_EXTENT)) return; pos_float_t center_lat, center_lon; if(unlikely(!pos_lat_get(context->extent.lat, center_lat) || !pos_lon_get(context->extent.lon, center_lon))) return; double vscale = DEG2RAD(POS_EQ_RADIUS / 1000.0); double hscale = DEG2RAD(cos(DEG2RAD(center_lat)) * POS_EQ_RADIUS / 1000.0); double height = pos_dist_get(context->extent.height, context->extent.is_mil); double width = pos_dist_get(context->extent.width, context->extent.is_mil); height /= 2 * vscale; context->bounds.min.lat = center_lat - height; context->bounds.max.lat = center_lat + height; width /= 2 * hscale; context->bounds.min.lon = center_lon - width; context->bounds.max.lon = center_lon + width; area_main_update(context); /* also update other tabs */ direct_update(context); map_update(context, false); }
/** * @brief Selects the system in the map. * * @param sys System to select. */ void map_select( StarSystem *sys ) { unsigned int wid; int i; wid = window_get(MAP_WDWNAME); if (sys == NULL) { map_selectCur(); } else { map_selected = sys - systems_stack; /* select the current system and make a path to it */ if (map_path) free(map_path); map_path = map_getJumpPath( &map_npath, cur_system->name, sys->name, 0 ); if (map_npath==0) hyperspace_target = -1; else { /* see if it is a valid hyperspace target */ for (i=0; i<cur_system->njumps; i++) { if (map_path[0]==system_getIndex(cur_system->jumps[i])) { planet_target = -1; /* override planet_target */ hyperspace_target = i; break; } } } } map_update(wid); }
int _aoi_update(lua_State *L) { struct aoi_context *aoi = lua_touserdata(L, 1); struct object *obj = lua_touserdata(L, 2); struct point np; np.x = luaL_checknumber(L, 3); np.y = luaL_checknumber(L, 4); if (np.x < 0 || np.y < 0 || np.x >= aoi->map.width || np.y >= aoi->map.high) { luaL_error(L,"[_aoi_update]invalid pos[%d:%d].",np.x,np.y); return 0; } lua_newtable(L); //-4 enter self lua_newtable(L); //-3 enter other lua_newtable(L); //-2 leave self lua_newtable(L); //-1 leave other int ret = 0; if ((ret = map_update(L,&aoi->map, obj, &np)) < 0) { luaL_error(L,"[_aoi_update]erro:%d.",ret); return 0; } return 4; }
void mmu_NRU::Process() { //printf("instr_size=%d\n",instr_size); global_pp_number=pp_number; for(int i=0;i<instr_size;i++) { current=i; if(o_option[0]) { printf("==> inst: %d %d\n",instruction[i].arrive_time,instruction[i].track_number); } //if the vp has been mapped to pp if(pte[instruction[i].track_number].f1==1) { update(instruction[i].arrive_time,instruction[i].track_number); if(mmutype!='N') { // get the pf_number of this vp_num int temp=pte[instruction[i].track_number].f5; alicia->mmu_update(temp); } //information information_print1(); continue; } //page fault if(pte[instruction[i].track_number].f1==0) { int pf_index=locatepage(); //get the physical frame number, specified by algorithm int vp_index=frametable[pf_index]; //get the virtual page number if(vp_index!=-1) { unmap_update(i,vp_index,pf_index); } map_update(i,instruction[i].track_number,pf_index); } //information information_print1(); } information_print(); totalcost=(unsigned long long)(stats.maps+stats.umaps)*400+ (unsigned long long)(stats.ins+stats.outs)*3000+(unsigned long long)(stats.zeros)*150+(unsigned long long)instr_size*1; if(o_option[3]) { printf("SUM %d U=%d M=%d I=%d O=%d Z=%d ===> %llu\n",instr_size,stats.umaps,stats.maps,stats.ins,stats.outs,stats.zeros,totalcost); } }
/* is becoming visible */ static void on_page_switch(GtkNotebook *nb, GtkWidget *pg, guint pgnum, area_context_t *context) { #ifdef FREMANTLE // the pages of the normal notebook are not used on FREMANTLE, so the sender // widget is not the one the one that can be queried for the actual title pg = gtk_notebook_get_nth_page(nb, pgnum); #else (void)pgnum; #endif if(context->map.needs_redraw && current_tab_is(nb, pg, TAB_LABEL_MAP)) map_update(context, true); }
bool address_resolv(const address_t * address, char ** phostname, int mask_cache) { struct hostent * hp; bool found = false; const void * data; if (!address) goto ERR_INVALID_PARAMETER; #ifdef USE_CACHE if (cache_ip_hostname && (mask_cache & CACHE_READ)) { found = map_find(cache_ip_hostname, address, &data); //phostname); if (found) { // We've to strdup the cached value, otherwise the function // calling address_resolv will erase this cached value. *phostname = strdup(data); } } #endif #ifdef USE_CACHE if (!found) { #endif if (!(hp = gethostbyaddr(&address->ip, address_get_size(address), address->family))) { // see h_error goto ERR_GETHOSTBYADDR; } if (!(*phostname = strdup(hp->h_name))) { goto ERR_STRDUP; } #ifdef USE_CACHE if (mask_cache & CACHE_WRITE) { map_update(cache_ip_hostname, address, *phostname); } } #endif return true; ERR_GETHOSTBYADDR: // This is to avoid to get errno set to 22 (EINVAL) if the DNS lookup fails. errno = 0; ERR_STRDUP: ERR_INVALID_PARAMETER: return false; }
static void callback_fetch_mm_clicked(area_context_t *context) { dbus_mm_pos_t mmpos; if(!dbus_mm_set_position(&mmpos)) { error_dlg(_("Unable to communicate with Maemo Mapper. " "You need to have Maemo Mapper installed to use this feature."), context->dialog.get()); return; } if(!mmpos.valid) { error_dlg(_("No valid position received yet. You need to " "scroll or zoom the Maemo Mapper view in order to force it to send " "its current view position to osm2go."), context->dialog.get()); return; } /* maemo mapper is fourth tab (page 3) */ if(!current_tab_is(context, "M.Mapper")) return; /* maemo mapper pos data ... */ pos_float_t center_lat = mmpos.pos.lat; pos_float_t center_lon = mmpos.pos.lon; int zoom = mmpos.zoom; if(!pos_lat_valid(center_lat) || !pos_lon_valid(center_lon)) return; double vscale = DEG2RAD(POS_EQ_RADIUS); double height = 8 * (1<<zoom) / vscale; context->bounds.min.lat = center_lat - height; context->bounds.max.lat = center_lat + height; double hscale = DEG2RAD(cos(DEG2RAD(center_lat)) * POS_EQ_RADIUS); double width = 16 * (1<<zoom) / hscale; context->bounds.min.lon = center_lon - width; context->bounds.max.lon = center_lon + width; area_main_update(context); /* also update other tabs */ direct_update(context); extent_update(context); map_update(context, false); }
static void callback_modified_direct(area_context_t *context) { /* direct is second tab (page 1) */ if(!current_tab_is(context, TAB_LABEL_DIRECT)) return; /* parse the fields from the direct entry pad */ if(unlikely(!pos_lat_get(context->direct.minlat, context->bounds.min.lat) || !pos_lon_get(context->direct.minlon, context->bounds.min.lon) || !pos_lat_get(context->direct.maxlat, context->bounds.max.lat) || !pos_lon_get(context->direct.maxlon, context->bounds.max.lon))) return; area_main_update(context); /* also adjust other views */ extent_update(context); map_update(context, false); }
static struct variable *binary_op_lst(struct context *context, enum Opcode op, const struct variable *u, const struct variable *v) { vm_assert(context, u->type==VAR_LST && v->type==VAR_LST, "list op with non-lists"); struct variable *w = NULL; switch (op) { case VM_ADD: w = variable_copy(context, v); for (int i=0; i<u->list->length; i++) array_add(w->list, array_get(u->list, i)); map_update(w->map, u->map); break; default: return (struct variable*)vm_exit_message(context, "unknown string operation"); } return w; }
static void push_list(struct context *context, struct byte_array *program) { int32_t num_items = serial_decode_int(program); DEBUGPRINT("LST %d", num_items); if (!context->runtime) VM_DEBUGPRINT("\n"); struct array *items = array_new(); struct map *map = NULL; while (num_items--) { struct variable* v = variable_pop(context); if (v->type == VAR_MAP) { if (!map) map = map_new(context, NULL); map_update(map, v->map); // mapped values are stored in the map, not list } else array_insert(items, 0, v); } struct variable *list = variable_new_list(context, items); list->map = map; DEBUGPRINT(": %s\n", variable_value_str(context, list)); variable_push(context, list); }
static PyObject * Map_update(Map *self, PyObject *args, PyObject *kwds) { Scan * py_scan = NULL; Position * py_position = NULL; int map_quality = 0; double hole_width_mm = 0; if (!PyArg_ParseTuple(args, "OOid", &py_scan, &py_position, &map_quality, &hole_width_mm)) { return null_on_raise_argument_exception("Map", "update"); } if (error_on_check_argument_type((PyObject *)py_scan, &pybreezyslam_ScanType, 0, "pybreezyslam.Scan", "Map", "update") || error_on_check_argument_type((PyObject *)py_position, &pybreezyslam_PositionType, 0, "pybreezyslam.Position", "Map", "update")) { return NULL; } position_t position = pypos2cpos(py_position); map_update( &self->map, &py_scan->scan, position, map_quality, hole_width_mm); Py_RETURN_NONE; }
/** * @brief Opens the map window. */ void map_open (void) { unsigned int wid; StarSystem *cur; int w, h, x, y, rw; /* Not under manual control. */ if (pilot_isFlag( player.p, PILOT_MANUAL_CONTROL )) return; /* Destroy window if exists. */ wid = window_get(MAP_WDWNAME); if (wid > 0) { window_destroy( wid ); return; } /* set position to focus on current system */ map_xpos = cur_system->pos.x; map_ypos = cur_system->pos.y; /* mark systems as needed */ mission_sysMark(); /* Attempt to select current map if none is selected */ if (map_selected == -1) map_selectCur(); /* get the selected system. */ cur = system_getIndex( map_selected ); /* Set up window size. */ w = MAX(600, SCREEN_W - 100); h = MAX(540, SCREEN_H - 100); /* create the window. */ wid = window_create( MAP_WDWNAME, -1, -1, w, h ); window_setCancel( wid, window_close ); window_handleKeys( wid, map_keyHandler ); /* * SIDE TEXT * * $System * * Faction: * $Faction (or Multiple) * * Status: * $Status * * Planets: * $Planet1, $Planet2, ... * * Services: * $Services * * ... * [Autonav] * [ Find ] * [ Close ] */ x = -70; /* Right column X offset. */ y = -20; rw = ABS(x) + 60; /* Right column indented width maximum. */ /* System Name */ window_addText( wid, -90 + 80, y, 160, 20, 1, "txtSysname", &gl_defFont, &cDConsole, cur->name ); y -= 10; /* Faction image */ window_addImage( wid, -90 + 32, y - 32, 0, 0, "imgFaction", NULL, 0 ); y -= 64 + 10; /* Faction */ window_addText( wid, x, y, 90, 20, 0, "txtSFaction", &gl_smallFont, &cDConsole, "Faction:" ); window_addText( wid, x + 50, y-gl_smallFont.h-5, rw, 100, 0, "txtFaction", &gl_smallFont, &cBlack, NULL ); y -= 2 * gl_smallFont.h + 5 + 15; /* Standing */ window_addText( wid, x, y, 90, 20, 0, "txtSStanding", &gl_smallFont, &cDConsole, "Standing:" ); window_addText( wid, x + 50, y-gl_smallFont.h-5, rw, 100, 0, "txtStanding", &gl_smallFont, &cBlack, NULL ); y -= 2 * gl_smallFont.h + 5 + 15; /* Presence. */ window_addText( wid, x, y, 90, 20, 0, "txtSPresence", &gl_smallFont, &cDConsole, "Presence:" ); window_addText( wid, x + 50, y-gl_smallFont.h-5, rw, 100, 0, "txtPresence", &gl_smallFont, &cBlack, NULL ); y -= 2 * gl_smallFont.h + 5 + 15; /* Planets */ window_addText( wid, x, y, 90, 20, 0, "txtSPlanets", &gl_smallFont, &cDConsole, "Planets:" ); window_addText( wid, x + 50, y-gl_smallFont.h-5, rw, 150, 0, "txtPlanets", &gl_smallFont, &cBlack, NULL ); y -= 2 * gl_smallFont.h + 5 + 15; /* Services */ window_addText( wid, x, y, 90, 20, 0, "txtSServices", &gl_smallFont, &cDConsole, "Services:" ); window_addText( wid, x + 50, y-gl_smallFont.h-5, rw, 100, 0, "txtServices", &gl_smallFont, &cBlack, NULL ); y -= 2 * gl_smallFont.h + 5 + 15; /* Close button */ window_addButton( wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT, "btnClose", "Close", window_close ); /* Find button */ window_addButton( wid, -20 - (BUTTON_WIDTH+20), 20, BUTTON_WIDTH, BUTTON_HEIGHT, "btnFind", "Find", map_inputFind ); /* Autonav button */ window_addButton( wid, -20 - 2*(BUTTON_WIDTH+20), 20, BUTTON_WIDTH, BUTTON_HEIGHT, "btnAutonav", "Autonav", player_autonavStartWindow ); /* * Bottom stuff * * [+] [-] Nebula, Interference */ /* Zoom buttons */ window_addButton( wid, 40, 20, 30, 30, "btnZoomIn", "+", map_buttonZoom ); window_addButton( wid, 80, 20, 30, 30, "btnZoomOut", "-", map_buttonZoom ); /* Situation text */ window_addText( wid, 140, 10, w - 80 - 30 - 30, 30, 0, "txtSystemStatus", &gl_smallFont, &cBlack, NULL ); /* * The map itself. */ map_show( wid, 20, -40, w-200, h-100, 1. ); /* Reset zoom. */ map_update( wid ); /* * Disable Autonav button if player lacks fuel. */ if ((player.p->fuel < HYPERSPACE_FUEL) || pilot_isFlag( player.p, PILOT_NOJUMP)) window_disableButton( wid, "btnAutonav" ); }
/** * Update the current frame, as many times as it's accumulated */ static void ps_update() { GFraMe_event_update_begin(); GFraMe_object *pObj; GFraMe_ret rv; int h, w; if (gv_getValue(BOSS_ISDEAD) >= 4) { if (_timerTilCredits == 0) { timer_stop(); audio_playVictory(); } else if (_timerTilCredits > 5000) { _psRunning = 0; } _timerTilCredits += GFraMe_event_elapsed; if (_timerTilCredits >= 2000) return; } else if (gv_nIsZero(SWITCH_MAP)) { return; } else if (_ps_text) { textWnd_update(GFraMe_event_elapsed); return; } #ifdef DEBUG _updCalls++; #endif pObj = 0; // Check if any player should teleport player_checkTeleport(p1); player_checkTeleport(p2); // Update everything map_update(m, GFraMe_event_elapsed); rg_updateMobs(GFraMe_event_elapsed); rg_updateObjects(GFraMe_event_elapsed); rg_updateBullets(GFraMe_event_elapsed); player_update(p1, GFraMe_event_elapsed); player_update(p2, GFraMe_event_elapsed); ui_update(GFraMe_event_elapsed); signal_update(GFraMe_event_elapsed); // Collide everythin against everything else map_getDimensions(m, &w, &h); rv = qt_initCol(-8, -8, w + 16, h + 16); GFraMe_assertRet(rv == GFraMe_ret_ok, "Error initializing collision", __err_ret); rv = rg_qtAddWalls(); GFraMe_assertRet(rv == GFraMe_ret_ok, "Error adding map to collision", __err_ret); rv = rg_qtAddObjects(); GFraMe_assertRet(rv == GFraMe_ret_ok, "Error adding object to quadtree", __err_ret); rv = rg_qtAddMob(); GFraMe_assertRet(rv == GFraMe_ret_ok, "Error adding mob to quadtree", __err_ret); rv = rg_qtAddEvents(); GFraMe_assertRet(rv == GFraMe_ret_ok, "Error adding events to quadtree", __err_ret); rv = rg_qtAddBullets(); GFraMe_assertRet(rv == GFraMe_ret_ok, "Error adding bullets to quadtree", __err_ret); rv = qt_addPl(p1); GFraMe_assertRet(rv == GFraMe_ret_ok, "Error adding player to quadtree", __err_ret); rv = qt_addPl(p2); GFraMe_assertRet(rv == GFraMe_ret_ok, "Error adding player to quadtree", __err_ret); // Collide both players, manually col_onPlayer(p1, p2); col_onPlayer(p2, p1); // Collide the carried player (if any) against the map if (player_isBeingCarried(p1)) player_getObject(&pObj, p1); else if (player_isBeingCarried(p2)) player_getObject(&pObj, p2); // Fix a bug that would let players clip into ceilings if (pObj) rg_collideObjWall(pObj); // Update camera cam_setPosition(); // If the player is trying to switch maps, do it if (player_cmpDestMap(p1, p2) == GFraMe_ret_ok) { gv_setValue(SWITCH_MAP, 1); return; } if (!player_isAlive(p1) && !player_isInsideMap(p1)) { GFraMe_ret rv; // Recover previous state rv = gv_load(SAVEFILE); GFraMe_assertRet(rv == GFraMe_ret_ok, "Error loading map", __err_ret); // Increase death counter gv_inc(PL1_DEATH); // Save death counter gv_setValue(GAME_TIME, timer_getTime()); rv = gv_save(SAVEFILE); GFraMe_assertRet(rv == GFraMe_ret_ok, "Error saving map", __err_ret); // Force reload gv_setValue(SWITCH_MAP, 1); } if (!player_isAlive(p2) && !player_isInsideMap(p2)) { GFraMe_ret rv; // Recover previous state rv = gv_load(SAVEFILE); GFraMe_assertRet(rv == GFraMe_ret_ok, "Error loading map", __err_ret); // Increase death counter gv_inc(PL2_DEATH); // Save death counter gv_setValue(GAME_TIME, timer_getTime()); rv = gv_save(SAVEFILE); GFraMe_assertRet(rv == GFraMe_ret_ok, "Error saving map", __err_ret); // Force reload gv_setValue(SWITCH_MAP, 1); } GFraMe_event_update_end(); return; __err_ret: gl_running = 0; return; }
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; }
/** * @brief Opens the map window. */ void map_open (void) { unsigned int wid; StarSystem *cur; int w,h; /* Destroy window if exists. */ wid = window_get(MAP_WDWNAME); if (wid > 0) { window_destroy( wid ); return; } /* set position to focus on current system */ map_xpos = cur_system->pos.x; map_ypos = cur_system->pos.y; /* mark systems as needed */ mission_sysMark(); /* Attempt to select current map if none is selected */ if (map_selected == -1) map_selectCur(); /* get the selected system. */ cur = system_getIndex( map_selected ); /* Set up window size. */ w = MAX(600, SCREEN_W - 100); h = MAX(540, SCREEN_H - 100); /* create the window. */ wid = window_create( MAP_WDWNAME, -1, -1, w, h ); window_setCancel( wid, window_close ); /* * SIDE TEXT * * $System * * Faction: * $Faction (or Multiple) * * Status: * $Status * * Planets: * $Planet1, $Planet2, ... * * Services: * $Services * * ... * * [Close] */ /* System Name */ window_addText( wid, -20, -20, 100, 20, 1, "txtSysname", &gl_defFont, &cDConsole, cur->name ); /* Faction */ window_addImage( wid, -20-64, -60-64, "imgFaction", NULL, 0 ); window_addText( wid, -20, -60, 90, 20, 0, "txtSFaction", &gl_smallFont, &cDConsole, "Faction:" ); window_addText( wid, -20, -60-gl_smallFont.h-5, 80, 100, 0, "txtFaction", &gl_smallFont, &cBlack, NULL ); /* Standing */ window_addText( wid, -20, -100, 90, 20, 0, "txtSStanding", &gl_smallFont, &cDConsole, "Standing:" ); window_addText( wid, -20, -100-gl_smallFont.h-5, 80, 100, 0, "txtStanding", &gl_smallFont, &cBlack, NULL ); /* Security. */ window_addText( wid, -20, -140, 90, 20, 0, "txtSSecurity", &gl_smallFont, &cDConsole, "Security:" ); window_addText( wid, -20, -140-gl_smallFont.h-5, 80, 100, 0, "txtSecurity", &gl_smallFont, &cBlack, NULL ); /* Planets */ window_addText( wid, -20, -180, 90, 20, 0, "txtSPlanets", &gl_smallFont, &cDConsole, "Planets:" ); window_addText( wid, -20, -180-gl_smallFont.h-5, 80, 100, 0, "txtPlanets", &gl_smallFont, &cBlack, NULL ); /* Services */ window_addText( wid, -20, -220, 90, 20, 0, "txtSServices", &gl_smallFont, &cDConsole, "Services:" ); window_addText( wid, -20, -220-gl_smallFont.h-5, 80, 100, 0, "txtServices", &gl_smallFont, &cBlack, NULL ); /* Close button */ window_addButton( wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT, "btnClose", "Close", window_close ); /* * Bottom stuff * * [+] [-] Nebula, Asteroids, Interference */ /* Zoom buttons */ window_addButton( wid, 40, 20, 30, 30, "btnZoomIn", "+", map_buttonZoom ); window_addButton( wid, 80, 20, 30, 30, "btnZoomOut", "-", map_buttonZoom ); /* Situation text */ window_addText( wid, 140, 10, w - 80 - 30 - 30, 30, 0, "txtSystemStatus", &gl_smallFont, &cBlack, NULL ); /* * The map itself. */ map_show( wid, 20, -40, w-150, h-100, 1. ); /* Reset zoom. */ map_update( wid ); }
static void lka_imsg(struct imsgev *iev, struct imsg *imsg) { struct submit_status *ss; struct secret *secret; struct mapel *mapel; struct rule *rule; struct map *map; struct map *mp; void *tmp; if (imsg->hdr.type == IMSG_DNS_HOST || imsg->hdr.type == IMSG_DNS_MX || imsg->hdr.type == IMSG_DNS_PTR) { dns_async(iev, imsg->hdr.type, imsg->data); return; } if (iev->proc == PROC_MFA) { switch (imsg->hdr.type) { case IMSG_LKA_MAIL: ss = imsg->data; ss->code = 530; if (ss->u.maddr.user[0] == '\0' && ss->u.maddr.domain[0] == '\0') ss->code = 250; else if (lka_verify_mail(&ss->u.maddr)) ss->code = 250; imsg_compose_event(iev, IMSG_LKA_MAIL, 0, 0, -1, ss, sizeof *ss); return; case IMSG_LKA_RULEMATCH: ss = imsg->data; rule = ruleset_match(&ss->envelope); if (rule == NULL) ss->code = (errno == EAGAIN) ? 451 : 530; else ss->code = (rule->r_decision == R_ACCEPT) ? 250 : 530; imsg_compose_event(iev, IMSG_LKA_RULEMATCH, 0, 0, -1, ss, sizeof *ss); return; case IMSG_LKA_RCPT: lka_session(imsg->data); return; } } if (iev->proc == PROC_MTA) { switch (imsg->hdr.type) { case IMSG_LKA_SECRET: { struct map_credentials *map_credentials; secret = imsg->data; map = map_findbyname(secret->mapname); if (map == NULL) { log_warn("warn: lka: credentials map %s is missing", secret->mapname); imsg_compose_event(iev, IMSG_LKA_SECRET, 0, 0, -1, secret, sizeof *secret); return; } map_credentials = map_lookup(map->m_id, secret->host, K_CREDENTIALS); log_debug("debug: lka: %s credentials lookup (%d)", secret->host, map_credentials != NULL); secret->secret[0] = '\0'; if (map_credentials == NULL) log_warnx("warn: %s credentials not found", secret->host); else if (lka_encode_credentials(secret->secret, sizeof secret->secret, map_credentials) == 0) log_warnx("warn: %s credentials parse fail", secret->host); imsg_compose_event(iev, IMSG_LKA_SECRET, 0, 0, -1, secret, sizeof *secret); free(map_credentials); return; } } } if (iev->proc == PROC_PARENT) { switch (imsg->hdr.type) { case IMSG_CONF_START: env->sc_rules_reload = xcalloc(1, sizeof *env->sc_rules, "lka:sc_rules_reload"); env->sc_maps_reload = xcalloc(1, sizeof *env->sc_maps, "lka:sc_maps_reload"); TAILQ_INIT(env->sc_rules_reload); TAILQ_INIT(env->sc_maps_reload); return; case IMSG_CONF_RULE: rule = xmemdup(imsg->data, sizeof *rule, "lka:rule"); TAILQ_INSERT_TAIL(env->sc_rules_reload, rule, r_entry); return; case IMSG_CONF_MAP: map = xmemdup(imsg->data, sizeof *map, "lka:map"); TAILQ_INIT(&map->m_contents); TAILQ_INSERT_TAIL(env->sc_maps_reload, map, m_entry); tmp = env->sc_maps; env->sc_maps = env->sc_maps_reload; mp = map_open(map); if (mp == NULL) errx(1, "lka: could not open map \"%s\"", map->m_name); map_close(map, mp); env->sc_maps = tmp; return; case IMSG_CONF_RULE_SOURCE: rule = TAILQ_LAST(env->sc_rules_reload, rulelist); tmp = env->sc_maps; env->sc_maps = env->sc_maps_reload; rule->r_sources = map_findbyname(imsg->data); if (rule->r_sources == NULL) fatalx("lka: maps inconsistency"); env->sc_maps = tmp; return; case IMSG_CONF_MAP_CONTENT: map = TAILQ_LAST(env->sc_maps_reload, maplist); mapel = xmemdup(imsg->data, sizeof *mapel, "lka:mapel"); TAILQ_INSERT_TAIL(&map->m_contents, mapel, me_entry); return; case IMSG_CONF_END: if (env->sc_rules) purge_config(PURGE_RULES); if (env->sc_maps) purge_config(PURGE_MAPS); env->sc_rules = env->sc_rules_reload; env->sc_maps = env->sc_maps_reload; /* start fulfilling requests */ event_add(&env->sc_ievs[PROC_MTA]->ev, NULL); event_add(&env->sc_ievs[PROC_MFA]->ev, NULL); event_add(&env->sc_ievs[PROC_SMTP]->ev, NULL); return; case IMSG_CTL_VERBOSE: log_verbose(*(int *)imsg->data); return; case IMSG_PARENT_FORWARD_OPEN: lka_session_forward_reply(imsg->data, imsg->fd); return; } } if (iev->proc == PROC_CONTROL) { switch (imsg->hdr.type) { case IMSG_LKA_UPDATE_MAP: map = map_findbyname(imsg->data); if (map == NULL) { log_warnx("warn: lka: no such map \"%s\"", (char *)imsg->data); return; } map_update(map); return; } } errx(1, "lka_imsg: unexpected %s imsg", imsg_to_str(imsg->hdr.type)); }
static gboolean on_map_configure(area_context_t *context) { map_update(context, false); return FALSE; }