MODULE evaluate_numeric_comparison (void) { long lvalue, rvalue; /* Expression results */ int feedback, /* Feedback from lr_calculate () */ offset; /* Where is error in expr, if any */ feedback = lr_calculate (lexpr, &lvalue, &offset); if (feedback) token_posn = lposn + offset; /* Point to error in left expr */ else { feedback = lr_calculate (rexpr, &rvalue, &offset); if (feedback) /* Point to error in right expr */ token_posn = rposn + offset; } if (feedback) /* If error in expr, signal it */ signal_error (feedback); else /* Else make comparison */ switch (relator) { case OP_EQ: *result = (lvalue == rvalue); break; case OP_NE: *result = (lvalue != rvalue); break; case OP_LT: *result = (lvalue < rvalue); break; case OP_LE: *result = (lvalue <= rvalue); break; case OP_GT: *result = (lvalue > rvalue); break; case OP_GE: *result = (lvalue >= rvalue); break; default: signal_error (MSG_EVAL_INTERNAL_ERROR); } }
BOOLEANC dict_save_block( DICTIONARY *dict , char *toc_id , FILE *fo ) { DICT_TOC_ENTRY *dt_entry; int index, ret_code; char *block; index = dict_toc_index( dict , toc_id ); if ( index == -1 ) { signal_error( "dict_save_block: id not found " , toc_id , 1 ); return( FALSE ); } /* endif */ dt_entry = &(dict->toc[index]); block = (char*)(dt_entry->ptr); if ( block == NULL ) { signal_error( "dict_save_block: NULL block " , toc_id , 1 ); return( FALSE ); } /* endif */ /* dt_entry->offset = fseek( fo , 0 , SEEK_END ); */ dt_entry->checksum = compute_checksum( dt_entry->size , block ); ret_code = block_write( fo , dt_entry->ptr , dt_entry->size ); if ( ret_code == -1 ) { signal_error( "dict_save_block: block_write failed " , toc_id , 1 ); return( FALSE ); } /* endif */ if ( trace > 3 ) { fprintf( ft , "\nStored block\nTOC entry: id:%s offset:%lx size:%lx ptr:%p checksum:%lx type:%d\n" , dict->toc[index].id , dict->toc[index].offset , dict->toc[index].size , dict->toc[index].ptr , dict->toc[index].checksum , dict->toc[index].type ); } /* endif */ return( TRUE ); }
void YCbCrLabView::openSequence(char *fileName) { try { if (getState() == isValid) closeSequence(); m_pffSequence->readFile(fileName); m_pGraphicsView->setSceneRect(0, 0, m_pffSequence->getLumaSize().m_width, m_pffSequence->getLumaSize().m_height); } catch (ffmpegError eff) { char errorC[1000]; av_strerror(eff.getError(), errorC, 1000); QString message = tr("There was an error attempting to open the " "file. <<FFMPEG: ") + QString(eff.what()) + " (" + QString(errorC) + ")>>"; emit signal_stateChanged(isInvalid); emit signal_error(message); throw; // Pass up chain for proper UI handling. } catch (ffImportError eff) { QString message = tr("There was an error attempting to open the " "file. <<FFERROR: ") + QString(eff.what()) + " (" + QString::number(eff.getError()) + ")>>"; emit signal_stateChanged(isInvalid); emit signal_error(message); throw; // Pass up chain for proper UI handling. } }
void *dict_load_block( DICTIONARY *dict , char *toc_id , FILE *fi , void *block ) { DICT_TOC_ENTRY *dt_entry; static void *ptr; int index, ret_code; index = dict_toc_index( dict , toc_id ); if ( index != -1 ) { /* Found the id */ dt_entry = &(dict->toc[index]); } else { signal_error( "dict_load_block: could not find TOC_id" , toc_id , 1 ); return( NULL ); } /* endif */ if ( block == NULL ) { ptr = malloc( dt_entry->size ); if ( trace > 3 ) { fprintf( ft , "\ndict_load_block allocates %lx bytes at location %p\n" , dt_entry->size , ptr ); } /* endif */ } else { ptr = block; if ( trace > 3 ) { fprintf( ft , "\ndict_load_block uses memory at location %p\n" , ptr ); } /* endif */ } /* endif */ if ( ptr == NULL ) { signal_error( "dict_load_block: alloc failed " , toc_id , 1 ); return( NULL ); } /* endif */ ret_code = block_read( fi , (char*)ptr , dt_entry->size , dt_entry->offset ); if ( ret_code == -1 ) return( NULL ); if ( dt_entry->checksum != compute_checksum( dt_entry->size , (char*)ptr ) ) { signal_error( "dict_load_block: invalid checksum ", toc_id, 1); return( NULL ); } /* endif */ dt_entry->ptr = ptr; if ( trace > 3 ) { fprintf( ft , "\nLoaded block\nTOC entry: id:%s offset:%lx size:%lx ptr:%p checksum:%lx type:%d\n" , dict->toc[index].id , dict->toc[index].offset , dict->toc[index].size , dict->toc[index].ptr , dict->toc[index].checksum , dict->toc[index].type ); } /* endif */ return( ptr ); }
MODULE unstack_if_end_mark (void) { if (operator_stack [operator_ptr].token == end_mark_token) unstack_operator (); else signal_error (MSG_CALC_NO_RIGHT_PAR); }
static void handle_devmode_changes (Lisp_Devmode *ldm, HGLOBAL hDevNames, HGLOBAL hDevMode) { DEVNAMES *devnames = (DEVNAMES *) GlobalLock (hDevNames); Extbyte *new_name = devnames ? (Extbyte *) devnames + XETCHAR_SIZE * devnames->wDeviceOffset : NULL; DEVMODEW *devmode = (DEVMODEW *) GlobalLock (hDevMode); /* Size and name may have changed */ ldm->devmode = (DEVMODEW *) xrealloc (ldm->devmode, DEVMODE_SIZE (devmode)); if (new_name) ldm->printer_name = build_tstr_string (new_name); if (!NILP (ldm->device)) { /* Apply the new devmode to the printer and get a compete one back */ struct device *d = XDEVICE (ldm->device); if (!sync_printer_with_devmode (d, devmode, ldm->devmode, new_name ? ldm->printer_name : Qnil)) { global_free_2_maybe (hDevNames, hDevMode); signal_error (Qio_error, "Printer device initialization I/O error, device deleted", ldm->device); } } else { /* Just copy the devmode structure */ memcpy (ldm->devmode, devmode, DEVMODE_SIZE (devmode)); } }
static void get_relator_token (void) { char thisch; /* Current character */ while (is_relat (thisch = condition [column])) { column++; /* Store char and go for next */ token [token_len++] = thisch; } token [token_len] = 0; /* Terminate token string */ if (streq (token, "=") /* Encode relator */ || streq (token, "==")) /* and signal error */ relator = OP_EQ; /* if not valid */ else if (streq (token, "!=") || streq (token, "<>")) relator = OP_NE; else if (streq (token, "<")) relator = OP_LT; else if (streq (token, "<=")) relator = OP_LE; else if (streq (token, ">")) relator = OP_GT; else if (streq (token, ">=")) relator = OP_GE; else signal_error (MSG_EVAL_INV_RELATOR); }
MODULE get_next_token (void) { char thisch; while (condition [column] == ' ') /* Skip leading spaces */ column++; thisch = condition [column]; token_len = 0; token_posn = column; if (is_valid (thisch)) { get_normal_token (); the_next_event = normal_event; } else if (is_relat (thisch)) { get_relator_token (); the_next_event = relator_event; } else if (is_quote (thisch)) { get_string_token (); the_next_event = string_event; } else if (thisch == 0) the_next_event = finished_event; else signal_error (MSG_EVAL_INVALID_TOKEN); }
MODULE unstack_if_left_par (void) { if (operator_stack [operator_ptr].token == '(') operator_ptr--; else signal_error (MSG_CALC_NO_LEFT_PAR); }
static void get_string_token (void) { char delim, /* String delimiter " or ' */ thisch; /* Current character */ delim = condition [column++]; /* Get delimiter character */ FOREVER /* Loop until string is complete */ { /* or end of line */ thisch = condition [column++]; if (thisch == 0) { signal_error (MSG_EVAL_QUOTE_MISSING); break; } else if (thisch == delim) break; else if (thisch == '\\') { /* Handle escaped character */ thisch = condition [column++]; if (thisch == 'n') thisch = '\n'; /* Newline */ else if (thisch == 't') thisch = '\t'; /* Tab */ } token [token_len++] = thisch; } token [token_len] = 0; /* Terminate token string */ }
static Lisp_Object x_get_local_selection (Lisp_Object selection_symbol, Lisp_Object target_type, int local_request, struct mac_display_info *dpyinfo) { Lisp_Object local_value; Lisp_Object handler_fn, value, type, check; if (!x_selection_owner_p (selection_symbol, dpyinfo)) return Qnil; local_value = LOCAL_SELECTION (selection_symbol, dpyinfo); /* TIMESTAMP is a special case. */ if (EQ (target_type, QTIMESTAMP)) { handler_fn = Qnil; value = XCAR (XCDR (XCDR (local_value))); } else { /* Don't allow a quit within the converter. When the user types C-g, he would be surprised if by luck it came during a converter. */ ptrdiff_t count = SPECPDL_INDEX (); specbind (Qinhibit_quit, Qt); CHECK_SYMBOL (target_type); handler_fn = Fcdr (Fassq (target_type, Vselection_converter_alist)); /* gcpro is not needed here since nothing but HANDLER_FN is live, and that ought to be a symbol. */ if (!NILP (handler_fn)) value = call3 (handler_fn, selection_symbol, (local_request ? Qnil : target_type), XCAR (XCDR (local_value))); else value = Qnil; unbind_to (count, Qnil); } if (local_request) return value; /* Make sure this value is of a type that we could transmit to another application. */ type = target_type; check = value; if (CONSP (value) && SYMBOLP (XCAR (value))) type = XCAR (value), check = XCDR (value); if (NILP (value) || mac_valid_selection_value_p (check, type)) return value; signal_error ("Invalid data returned by selection-conversion function", list2 (handler_fn, value)); }
MODULE stack_the_number (void) { if (operand_ptr < operand_max - 1) { operand_ptr++; operand_stack [operand_ptr].number = the_number; } else signal_error (MSG_CALC_OPERAND_OVER); }
void bhvm::exec_pop (void) { if (stack.size() > 0) stack.pop_back(); else { signal_error(mtk::Alarm(MTK_HERE, "bhvm", MTK_SS("empty stack, endind program " << get_status()), mtk::alPriorCritic)); program_counter = int(program.size()); } }
void my_error(int key, int key2) { if (key == 1) signal_error(key2); else if (key == 2) client_usage(key2); else if (key == 3) wrong_param(key2); exit(0); }
/** * Parses port configuration. * @param[out] mode the filter mode. * @param[out] port_list port list. * @param[in] node_param the xml_node object represents the node params. * @param[in] port_node_name the node name for port number. */ static inline void parse_port_configuration( uint8_t& mode, PORT_LIST& port_list, const xml_node& node_param, const char_t* port_node_name) { xml_node node_port = node_param.child(port_node_name); if (!node_port.empty()) { if(parse_filter_mode(node_port, mode)) { for (xml_node node_number = node_port.child("number"); !node_number.empty(); node_number = node_number.next_sibling("number")) { if(xml_attribute attr = node_number.attribute("value")) { port_list.push_back(attr.as_uint()); } else { signal_error(port_node_name); } } if (port_list.empty()) { // checks whether the old specification is specified xml_attribute attr = node_port.attribute("number"); if(attr.empty()) { signal_error(port_node_name); } port_list.push_back(attr.as_uint()); } } else { signal_error(port_node_name); } } }
MODULE stack_the_operator (void) { if (operator_ptr < operator_max - 1) { operator_ptr++; operator_stack [operator_ptr].token = the_token; operator_stack [operator_ptr].priority = the_priority; } else signal_error (MSG_CALC_OPERATOR_OVER); }
void YCbCrLabView::saveSequence(void) { try { m_pffSequence->exportFiles(); } catch (ffExportError eff) { QString message = tr("There was an error attempting to export. " "<<FFEXPORTERROR: ") + QString(eff.what()) + " (" + QString::number(eff.getError()) + ")>>"; emit signal_error(message); throw; // Pass up chain for proper UI handling. } }
void bhvm::execute_program (void) { try{ while (program_counter < int(program.size())) { //std::cout << program[program_counter] << std::endl; // debug... traza todo exec_instruction(program[program_counter]); ++program_counter; } signal_debug(Alarm(MTK_HERE, "bhvm", MTK_SS("end of program." << std::endl << get_status()), alPriorDebug)); } catch(const mtk::Alarm& error) { Alarm al(MTK_HERE, "bhvm", get_status(), alPriorCritic); al.Add(error); signal_error(al); } catch (std::exception& e) { signal_error(Alarm(MTK_HERE, "bhvm", MTK_SS("c++ exception " << e.what() << get_status()), alPriorCritic)); } catch(...) { signal_error(Alarm(MTK_HERE, "bhvm", MTK_SS("unknown error " << get_status()), alPriorCritic)); } }
UUpdateWidget::UUpdateWidget(QWidget *parent) : QMainWindow(parent), ui(new Ui::UUpdateWidget) { ui->setupUi(this); this->setAttribute(Qt::WA_DeleteOnClose,true); setFixedSize(size()); ui->menubar->setHidden(true); ui->statusbar->setHidden(true); ui->toolBar->addAction(QPixmap(), "Install updates", this, SLOT(slot_downloadFileFinished())); ui->toolBar->addAction(QPixmap(), "Quit", this, SLOT(slot_closeWidget())); ui->toolBar->addSeparator(); ui->toolBar->addAction(QPixmap(), "Check updates", this, SLOT(slot_checkUpdates())); m_toolBarActions = ui->toolBar->actions(); m_toolBarActions.at(eINSTALL_UPDATES_ACTION)->setEnabled(false); m_stackedWidget = new QStackedWidget(this); m_checkUpdatesWidget = new UCheckUpdatesWidget(m_stackedWidget); m_updatesTableView = new UUpdatesTableView(m_stackedWidget); m_stackedWidget->addWidget(new QWidget(m_stackedWidget)); m_stackedWidget->addWidget(m_checkUpdatesWidget); m_stackedWidget->addWidget(m_updatesTableView); m_stackedWidget->setCurrentIndex(0); setCentralWidget(m_stackedWidget); connect(m_checkUpdatesWidget, SIGNAL(signal_processUpdatesFinished(UUpdatesModel *)), this, SLOT(slot_showUpdatesTable(UUpdatesModel *))); connect(m_checkUpdatesWidget, SIGNAL(signal_downloadFailed(QString)), this, SLOT(slot_checkUpdatesFailed(QString))); m_downloader = new UFileDownloader; connect(m_downloader, SIGNAL(signal_downloadFileFinished()), this, SLOT(slot_downloadFileFinished())); connect(m_downloader, SIGNAL(signal_error(QString)), this, SLOT(slot_error(QString))); m_currentDownloadFile = -1; connect(this, SIGNAL(signal_downloadUpdatesFinished()), this, SLOT(slot_installUpdates())); }
MODULE get_next_token (void) { while (expr [expr_ptr] == ' ') /* Skip spaces */ expr_ptr++; token_posn = expr_ptr; /* Save start of this token */ the_token = expr [expr_ptr++]; /* Get next token */ switch (the_token) { case '+': case '-': the_next_event = term_op_event; the_priority = term_op_priority; break; case '*': case '/': the_next_event = factor_op_event; the_priority = factor_op_priority; break; case '(': the_next_event = left_par_event; the_priority = left_par_priority; break; case ')': the_next_event = right_par_event; the_priority = right_par_priority; break; case '\0': the_next_event = end_mark_event; the_priority = end_mark_priority; break; default: if (isdigit (the_token)) { the_next_event = number_event; collect_number (); } else signal_error (MSG_CALC_INVALID_TOKEN); } }
MODULE evaluate_string_comparison (void) { int cmp; cmp = strcmp (lexpr, rexpr); switch (relator) { case OP_EQ: *result = (cmp == 0); break; case OP_NE: *result = (cmp != 0); break; case OP_LT: *result = (cmp < 0); break; case OP_LE: *result = (cmp <= 0); break; case OP_GT: *result = (cmp > 0); break; case OP_GE: *result = (cmp >= 0); break; default: signal_error (MSG_EVAL_INTERNAL_ERROR); } }
void bhvm::exec_jump (void) { std::string label2jump; if (stack.size() != 0) { label2jump = get_top(); exec_pop(); if (labels.find(label2jump) == labels.end()) { signal_error (Alarm(MTK_HERE, "bhvm", MTK_SS("inexistent label " << label2jump), alPriorCritic)); throw Alarm(MTK_HERE, "bhvm", MTK_SS("inexistent label " << label2jump), alPriorCritic); } else program_counter = labels[label2jump]; } else throw Alarm(MTK_HERE, "bhvm", MTK_SS("no label to jump (empty stack)"), alPriorCritic); }
static void unstack_operator (void) { cur_token = operator_stack [operator_ptr--].token; op_1 = operand_stack [operand_ptr].number; if (cur_token == '+' || cur_token == '-' || cur_token == '*' || cur_token == '/') { op_2 = op_1; op_1 = operand_stack [--operand_ptr].number; } switch (cur_token) { case '+': op_1 += op_2; break; case '-': op_1 -= op_2; break; case '*': op_1 *= op_2; break; case '/': op_1 /= op_2; break; case end_mark_token: *result = op_1; break; default: signal_error (MSG_CALC_INTERNAL_ERROR); break; } operand_stack [operand_ptr].number = op_1; }
BOOLEANC dict_set_parm_ids( DICTIONARY *dict ) { if ( dict==NULL || dict->sig == NULL ) { signal_error( "dict_set_parm_ids: Allocate dict and signature first." , "" , 0 ); return( FALSE ); } dict->sig->nparms = 14; strcpy( dict->parm[0].id , "FLAGS_______" ); strcpy( dict->parm[1].id , "ENTRY_COUNT_" ); strcpy( dict->parm[2].id , "ARRAY_SIZE__" ); strcpy( dict->parm[3].id , "ARRAY_USED__" ); strcpy( dict->parm[4].id , "ARR_GROW_CT_" ); strcpy( dict->parm[5].id , "STRING_MAX__" ); strcpy( dict->parm[6].id , "STR_GROW_CT_" ); strcpy( dict->parm[7].id , "LONG_CHAIN__" ); strcpy( dict->parm[8].id , "ALLOW_CHAIN_" ); strcpy( dict->parm[9].id , "HASH_TAB_SIZ" ); strcpy( dict->parm[10].id , "HASH_MASK___" ); strcpy( dict->parm[11].id , "HASH_GROW_CT" ); strcpy( dict->parm[12].id , "CHECK_VALUE_" ); strcpy( dict->parm[13].id , "SCAN_STR_IX_" ); return( TRUE ); }
void misc_signal_handler_impl() { signal_error(signal_number,signal_callstack_top); }
void factor_vm::synchronous_signal_handler_impl() { signal_error(signal_number); }
dso *load_elf(dso *loader, const char *name, const char *path, long fd, unsigned char rt_load, unsigned int rtld_mode, Elf32_auxv_t *auxv) { #ifdef D_LOAD sl_printf("\nLoading elf file: %s (%s)\n", path, name); #endif #ifdef SL_STATISTIC /* Some statistics */ loaded_dsos++; curr_loaded_dsos++; max_loaded_dsos = MAX(max_loaded_dsos, curr_loaded_dsos); #endif /* Get file information */ struct kernel_stat file_info; if(sl_fstat(fd, &file_info) == -1) { /* Close file */ sl_close(fd); /* Signal error (longjmp) if we load at runtime */ if(rt_load) signal_error(0, name, 0, "fstat failed"); /* Not at runtime -> fail */ sl_printf("Error load_elf: fstat failed while loading %s.\n", name); sl_exit(1); } /* Map entire file in memory */ void *file_map = sl_mmap(0, file_info.st_size, PROT_READ, MAP_PRIVATE, fd, 0); if ((long)file_map == -1) { /* Close file */ sl_close(fd); /* Signal error (longjmp) if we load at runtime */ if(rt_load) signal_error(0, name, 0, "mmap failed"); /* Not at runtime -> fail */ sl_printf("Error load_elf: mmap of file %s failed.\n", name); sl_exit(1); } /* Get ELF header and check file */ Elf32_Ehdr *elf_hdr = (Elf32_Ehdr *) file_map; long valid = check_elf(elf_hdr); if (valid != 0) { /* Invalid elf file */ sl_close(fd); /* Signal error (longjmp) if we load at runtime */ if(rt_load) signal_error(0, name, 0, "invalid ELF file"); /* Not at runtime -> fail */ sl_printf("Error load_elf: %s is not a valid ELF file (error: %d).\n", name, valid); sl_exit(1); } /* Get program and section header */ Elf32_Phdr *program_hdr = (Elf32_Phdr *) (file_map + elf_hdr->e_phoff); Elf32_Shdr *shdr = (Elf32_Shdr *) (file_map + elf_hdr->e_shoff); /* Segments (text and data) which we have to map in memory */ Elf32_Phdr *load_segments[2]; long num_load = 0; /* Create new shared object */ dso *so = sl_calloc(sizeof(dso), 1); /* Iterate over program headers */ unsigned long i = 0; for(i = 0; i < elf_hdr->e_phnum; ++i) { switch (program_hdr[i].p_type) { case PT_DYNAMIC: /* Dynamic Header */ so->dynamic_section = (Elf32_Dyn *)(program_hdr[i].p_vaddr); break; case PT_LOAD: /* Section must be mapped in memory */ if (num_load >= 2) { sl_printf("Error load_elf: more than two PT_LOAD segments!"); sl_exit(1); } load_segments[num_load++] = program_hdr+i; break; case PT_TLS: /* Thread Local Storage information*/ if (program_hdr[i].p_memsz == 0) break; /* Initialize TLS information */ so->tls_blocksize = program_hdr[i].p_memsz; so->tls_align = program_hdr[i].p_align; so->tls_initimage_size = program_hdr[i].p_filesz; /* TLS image (addr later adjusted) */ so->tls_initimage = (void *) program_hdr[i].p_vaddr; /* Assign next module ID */ so->tls_modid = ++GL(_dl_tls_max_dtv_idx); break; /* case PT_GNU_STACK: if (program_hdr[i].p_flags & PF_X) { sl_printf("Warning: executable stack\n"); sl_exit(1); } break; */ case PT_GNU_RELRO: /* Sections to set readonly after relocation */ /* Address is later adjusted */ so->relro = program_hdr[i].p_vaddr; so->relro_size = program_hdr[i].p_memsz; break; } } /* Map segments into memory and intitialize dso struct */ if(rtld_mode == 1 && auxv != NULL) { Elf32_Phdr *program_hdr_auxv; Elf32_Phdr *load_segments_auxv[2]; program_hdr_auxv = (Elf32_Phdr *)get_aux_value(auxv, AT_PHDR); uint32_t auxv_e_phnum = (uint32_t)get_aux_value(auxv, AT_PHNUM); unsigned long j = 0; unsigned int nr_load = 0; for(j = 0; j < auxv_e_phnum; j++) { switch (program_hdr_auxv[j].p_type) { case PT_LOAD: /* Section must be mapped in memory */ if (nr_load >= 2) { sl_exit(1); } load_segments_auxv[nr_load++] = program_hdr_auxv+j; break; } } map_segments_RTLD(fd, load_segments, elf_hdr->e_type, so, load_segments_auxv); } else { map_segments(fd, load_segments, elf_hdr->e_type, so); } so->ref_count = 1; so->deps_count = 0; so->name = name; so->path = path; so->type = elf_hdr->e_type; so->entry = (void*) elf_hdr->e_entry; so->loader = loader; so->dynamic_section = (Elf32_Dyn *) BYTE_STEP(so->dynamic_section, so->base_addr); so->program_header = (Elf32_Phdr *) BYTE_STEP(elf_hdr->e_phoff, so->text_addr); so->program_header_num = elf_hdr->e_phnum; so->l_real = so; /* Adjust address of TLS init image and relro address */ if (so->tls_initimage) { so->tls_initimage = (char *)so->tls_initimage + (long)so->base_addr; } if (so->relro) { so->relro = (Elf32_Addr) BYTE_STEP(so->relro, so->base_addr); } /* Iterate over section headers */ char *strtab = (char *)file_map + shdr[elf_hdr->e_shstrndx].sh_offset; char *sname=0; for (i=0; i<elf_hdr->e_shnum; ++i) { sname = strtab + shdr[i].sh_name; /* Save important sections */ if (sl_strncmp(sname, ".got", 5) == 0) { so->got = (char *) (so->base_addr + shdr[i].sh_addr); so->got_size = shdr[i].sh_size; } if (sl_strncmp(sname, ".plt", 5) == 0) { so->plt = (char *) (so->base_addr + shdr[i].sh_addr); so->plt_size = shdr[i].sh_size; } if (sl_strncmp(sname, ".got.plt", 9) == 0) { so->gotplt = (char *) (so->base_addr + shdr[i].sh_addr); so->gotplt_size = shdr[i].sh_size; } } /* Resolve */ Elf32_Dyn *dyn; long rpath=-1; for (dyn = so->dynamic_section; dyn->d_tag != DT_NULL; ++dyn) { switch (dyn->d_tag) { case DT_INIT: /* Initialization function */ so->init = (void (*)(int, char**, char**)) BYTE_STEP(dyn->d_un.d_ptr, so->base_addr); break; case DT_INIT_ARRAY: /* Array of initialization functions */ so->init_array = (Elf32_Addr *)BYTE_STEP(dyn->d_un.d_ptr, so->base_addr); break; case DT_INIT_ARRAYSZ: /* Size of init array */ so->init_array_sz = (long)dyn->d_un.d_val / sizeof(Elf32_Addr); break; case DT_FINI: /* Finalization function */ so->fini = (void (*)()) BYTE_STEP(dyn->d_un.d_ptr, so->base_addr); break; case DT_FINI_ARRAY: /* Array of finalization functions */ so->fini_array = (Elf32_Addr *)BYTE_STEP(dyn->d_un.d_ptr, so->base_addr); break; case DT_FINI_ARRAYSZ: /* Size of fini array */ so->fini_array_sz = (long)dyn->d_un.d_val / sizeof(Elf32_Addr); break; case DT_RUNPATH: /* String with library search paths */ rpath = dyn->d_un.d_val; break; case DT_RPATH: /* String with library search paths */ if (rpath == -1) rpath = dyn->d_un.d_val; break; case DT_PLTGOT: /* Plt part of the global offset table */ so->gotplt = (char *) BYTE_STEP(dyn->d_un.d_ptr, so->base_addr); break; case DT_REL: /* Relocation table */ so->rel = (Elf32_Rel *) BYTE_STEP(dyn->d_un.d_ptr, so->base_addr); break; case DT_RELSZ: /* Size of the relocation table */ so->relsz = (long)dyn->d_un.d_val / sizeof(Elf32_Rel); break; case DT_JMPREL: /* Plt relocations part of relocation table */ so->pltrel = (Elf32_Rel *) BYTE_STEP(dyn->d_un.d_ptr, so->base_addr); break; case DT_PLTRELSZ: /* Size of plt relocations part of relocation table */ so->pltrelsz = (long)dyn->d_un.d_val / sizeof(Elf32_Rel); break; case DT_HASH: /* ELF hash table */ so->hash_table = (Elf32_Word *) BYTE_STEP(dyn->d_un.d_ptr, so->base_addr); break; case DT_GNU_HASH: /* GNU hash table */ so->gnu_hash_table = (Elf32_Word *) BYTE_STEP(dyn->d_un.d_ptr, so->base_addr); break; case DT_SYMTAB: /* Dynamic symbol table */ so->symbol_table = (Elf32_Sym *) BYTE_STEP(dyn->d_un.d_ptr, so->base_addr); break; case DT_VERDEF: /* Versions defined in this DSO */ so->verdef = (Elf32_Verdef *) BYTE_STEP(dyn->d_un.d_ptr, so->base_addr); break; case DT_VERDEFNUM: /* Number of versions defined in this DSO */ so->verdef_num = (unsigned long) dyn->d_un.d_val; break; case DT_VERNEED: /* Versions needed by this DSO */ so->verneed = (Elf32_Verneed *) BYTE_STEP(dyn->d_un.d_ptr, so->base_addr); break; case DT_VERNEEDNUM: /* Number of versions needed by this DSO */ so->verneed_num = (unsigned long) dyn->d_un.d_val; break; case DT_VERSYM: /* Version symbol table */ so->versym = (Elf32_Half *) BYTE_STEP(dyn->d_un.d_ptr, so->base_addr); break; case DT_STRTAB: /* Dynamic string table */ so->string_table = (char *) so->base_addr + dyn->d_un.d_ptr; break; case DT_NEEDED: /* Dependencies on other DSOs */ /* Count the number of direct dependencies */ so->deps_count++; break; case DT_FLAGS: /* Flags */ so->flags = dyn->d_un.d_val; if ((so->flags & DF_SYMBOLIC) || (so->flags & DF_TEXTREL)) { sl_printf("Error load_elf: not supported flag 0x%x in %s.\n", so->flags, so->name); sl_exit(1); } break; case DT_FLAGS_1: /* Flags */ so->flags_1 = dyn->d_un.d_val; if ((so->flags_1 & DF_1_GROUP) || (so->flags_1 & DF_1_LOADFLTR) || (so->flags_1 & DF_1_DIRECT) || (so->flags_1 & DF_1_INTERPOSE) || (so->flags_1 & DF_1_NODEFLIB) // || (so->flags_1 & DF_1_NODUMP) || (so->flags_1 & DF_1_CONFALT) || (so->flags_1 & DF_1_ENDFILTEE) || (so->flags_1 & DF_1_DISPRELDNE) || (so->flags_1 & DF_1_DISPRELPND)) { sl_printf("Error load_elf: not supported flag_1 0x%x in %s.\n", so->flags_1, so->name); sl_exit(1); } break; } } /* Initialize the versioning data */ init_versions(so); /* Set library search paths */ if (rpath != -1) so->search_path = decompose_path(so->string_table+rpath,so->name, "RPATH"); /* Allocate memory for deps */ if (so->deps_count != 0) so->deps = sl_malloc(so->deps_count * sizeof(dso *)); /* Add shared object to chain */ chain_add(so); /* Now that we have the stringtable, iterate a second time over dynamic section to get the names of the needed libraries. */ char *lib_name = 0; long num = 0; for (dyn = so->dynamic_section; dyn->d_tag != DT_NULL; dyn++) { switch (dyn->d_tag) { case DT_NEEDED: /* Get name of needed lib */ lib_name = (char *)so->string_table + dyn->d_un.d_val; #ifdef D_LOAD sl_printf("Found dependency in %s: %s\n", so->name, lib_name); #endif /* Do not load the linux dynamic loader, because we replace it */ if (sl_strncmp(lib_name, LINUX_LOADER, sl_strnlen(LINUX_LOADER, MAX_LIB_NAME))==0) { so->deps_count--; continue; } /* Check if we already loaded it */ dso *so_search = chain_search(lib_name); if (so_search == 0) { /* Not already loaded, search for it */ char *lib_path; long fd = search_lib(so, lib_name, &lib_path); if (fd == -1) { /* Not found, signal error (longjmp) if we load at runtime */ if(rt_load) signal_error(0, lib_name, 0, "cannot open shared object file"); /* Not at runtime -> fail */ sl_printf("Error load_elf: lib %s not found.\n", lib_name); sl_exit(1); } /* Copy name */ char *lname = sl_malloc(MAX_LIB_NAME); sl_strncpy(lname, lib_name, MAX_LIB_NAME); PROT_DATA(lname, MAX_LIB_NAME); /* Load it */ dso *so_loaded = load_elf(so, lname, lib_path, fd, rt_load, 0, NULL); /* Increment local scope counter and add to direct deps */ so->lscope_num += so_loaded->lscope_num; so->deps[num] = so_loaded; } else { /* Increment reference counter */ UNPROT(so_search); so_search->ref_count++; PROT(so_search); /* Increment local scope counter and add to direct deps */ so->lscope_num += so_search->lscope_num; so->deps[num] = so_search; } num++; so->lscope_num++; break; } } so->lscope_num++; /* Create local scope list. This has to be done in breadth-first order! */ so->lscope = sl_malloc(so->lscope_num * sizeof(dso *)); long j,k,l; i = 0; /* Add object itself */ so->lscope[i++] = so; /* First add direct dependencies */ for (l=0; l<so->deps_count; ++l) { so->lscope[i] = so->deps[l]; ++i; } /* Now add deps recursively */ for (l=0; l<so->deps_count; ++l) { for (k=0; k<so->deps[l]->lscope_num; ++k) { dso *dep = so->deps[l]->lscope[k]; /* Check if already added */ long found = 0; for (j=0; j<i; ++j) { if (so->lscope[j] == dep) found = 1; } if (found || !dep) continue; so->lscope[i] = dep; ++i; } } /* Initialize Global Offset Table */ init_got(so); #if defined(VERIFY_CFTX) /* Add object to dso chain if libdetox wants to check the control flow transfers */ add_dso(so, (char *)file_map); #if defined(CALLBACK_MAIN_DETECTION) || defined(CALLBACK_DATA_SECTION_SEARCH) /* Right after loading the dso we need to detect the libc callbacks to main/__libc_csu_init */ if(so->loader == NULL && dso_chain->next != 0) { /* This is the main executable. Get the immediate values pushed on the stack right before __libc_start_main is called. */ #if defined(CALLBACK_MAIN_DETECTION) /* This is the main function callback detection hack! * - it tries to find the callback pointers passed to libc * - and it adds them to the callback table so CFTX checks will pass */ long count = 0; unsigned char *iptr; unsigned long ptr; if(so->type == ET_EXEC) iptr = (unsigned char *)so->entry; else /* PIE executable */ iptr = (unsigned char *)((unsigned long)so->base_addr + (unsigned long)so->entry); /* TODO: 48? Remove hardcoded value. */ while(count<48) { /* is it a push instruction with a 32bit immediate value? */ if(*iptr == 0x68) { /* add the immediate value pushed to the stack */ ptr = *((unsigned long*)(++iptr)); fbt_add_callback(dso_chain->next, (void*)ptr); iptr+=4; count+=5; } else { iptr++; count++; } /* in case we reached NOPs we can just stop looking for the pushes */ if(*iptr == 0x90) break; } #endif /* CALLBACK_MAIN_DETECTION */ #if defined(CALLBACK_DATA_SECTION_SEARCH) /* Some x* applications have global function pointers in their .data section. * This are probably widget class objects and their members. It seems that there is no other * way to detect these potential callbacks than scanning through the .data section. This has * only to be done for prelinked executables as we will detect the other callbacks during relocation. */ unsigned long *dptr = so->data_addr; if(dptr) { while((unsigned long)dptr < ((unsigned long)so->data_addr+(unsigned long)so->data_size)) { /* check if the obtained address points to executable memory (potential callback target) */ if (PTR_IN_REGION(*dptr, so->text_addr, so->text_size) || PTR_IN_REGION(*dptr, so->dso->init, so->dso->init_size) || PTR_IN_REGION(*dptr, so->dso->fini, so->dso->fini_size)) { fbt_add_callback(so->dso, (void*)*dptr); } dptr++; /* increase by sizeof(unsigned long) = bytes */ } } /* go through GOT */ dptr = (unsigned long*)(so->got); if(dptr) { while((unsigned long)dptr < ((unsigned long)so->got+(unsigned long)so->got_size)) { /* check if the obtained address points to executable memory (potential callback target) */ if (PTR_IN_REGION(*dptr, so->text_addr, so->text_size) || PTR_IN_REGION(*dptr, so->dso->init, so->dso->init_size) || PTR_IN_REGION(*dptr, so->dso->fini, so->dso->fini_size)) { fbt_add_callback(so->dso, (void*)*dptr); } dptr++; /* increase by sizeof(unsigned long) = bytes */ } } /* go through GOT.PLT */ dptr = (unsigned long*)(so->gotplt); if(dptr) { while((unsigned long)dptr < ((unsigned long)so->gotplt+(unsigned long)so->gotplt_size)) { /* check if the obtained address points to executable memory (potential callback target) */ if (PTR_IN_REGION(*dptr, so->text_addr, so->text_size) || PTR_IN_REGION(*dptr, so->dso->init, so->dso->init_size) || PTR_IN_REGION(*dptr, so->dso->fini, so->dso->fini_size)) { fbt_add_callback(so->dso, (void*)*dptr); } dptr++; /* increase by sizeof(unsigned long) = bytes */ } } /* go through rodata */ dptr = (unsigned long*)(so->dso->rodata); if(dptr) { while((unsigned long)dptr < ((unsigned long)so->dso->rodata+(unsigned long)so->dso->rodata_size)) { /* check if the obtained address points to executable memory (potential callback target) */ if (PTR_IN_REGION(*dptr, so->text_addr, so->text_size) || PTR_IN_REGION(*dptr, so->dso->init, so->dso->init_size) || PTR_IN_REGION(*dptr, so->dso->fini, so->dso->fini_size)) { fbt_add_callback(so->dso, (void*)*dptr); } dptr++; /* increase by sizeof(unsigned long) = bytes */ } } /* go through reldyn */ dptr = (unsigned long*)(so->dso->reldyn); if(dptr) { while((unsigned long)dptr < ((unsigned long)so->dso->reldyn+(unsigned long)so->dso->reldyn_size)) { /* check if the obtained address points to executable memory (potential callback target) */ if (PTR_IN_REGION(*dptr, so->text_addr, so->text_size) || PTR_IN_REGION(*dptr, so->dso->init, so->dso->init_size) || PTR_IN_REGION(*dptr, so->dso->fini, so->dso->fini_size)) { fbt_add_callback(so->dso, (void*)*dptr); } dptr++; /* increase by sizeof(unsigned long) = bytes */ } } /* go through relplt */ dptr = (unsigned long*)(so->dso->relplt); if(dptr) { while((unsigned long)dptr < ((unsigned long)so->dso->relplt+(unsigned long)so->dso->relplt_size)) { /* check if the obtained address points to executable memory (potential callback target) */ if (PTR_IN_REGION(*dptr, so->text_addr, so->text_size) || PTR_IN_REGION(*dptr, so->dso->init, so->dso->init_size) || PTR_IN_REGION(*dptr, so->dso->fini, so->dso->fini_size)) { fbt_add_callback(so->dso, (void*)*dptr); } dptr++; /* increase by sizeof(unsigned long) = bytes */ } } #endif /* CALLBACK_DATA_SECTION_SEARCH */ } #endif /* defined(CALLBACK_MAIN_DETECTION) || defined(CALLBACK_DATA_SECTION_SEARCH) */ #if defined(CALLBACK_LIBRARIES_DATA_SECTION_SEARCH) if(so->loader != NULL) { /* it's a library! */ unsigned long *dptr = so->data_addr; if(dptr) { while((unsigned long)dptr < ((unsigned long)so->data_addr+(unsigned long)so->data_size)) { /* check if the obtained address points to executable memory (potential callback target) */ if (PTR_IN_REGION(*dptr, so->text_addr, so->text_size) || PTR_IN_REGION(*dptr, so->dso->init, so->dso->init_size) || PTR_IN_REGION(*dptr, so->dso->fini, so->dso->fini_size)) { fbt_add_callback(so->dso, (void*)*dptr); } dptr++; /* increase by sizeof(unsigned long) = bytes */ } } /* go through GOT */ dptr = (unsigned long*)(so->got); if(dptr) { while((unsigned long)dptr < ((unsigned long)so->got+(unsigned long)so->got_size)) { /* check if the obtained address points to executable memory (potential callback target) */ if (PTR_IN_REGION(*dptr, so->text_addr, so->text_size) || PTR_IN_REGION(*dptr, so->dso->init, so->dso->init_size) || PTR_IN_REGION(*dptr, so->dso->fini, so->dso->fini_size)) { fbt_add_callback(so->dso, (void*)*dptr); } dptr++; /* increase by sizeof(unsigned long) = bytes */ } } /* go through GOT.PLT */ dptr = (unsigned long*)(so->gotplt); if(dptr) { while((unsigned long)dptr < ((unsigned long)so->gotplt+(unsigned long)so->gotplt_size)) { /* check if the obtained address points to executable memory (potential callback target) */ if (PTR_IN_REGION(*dptr, so->text_addr, so->text_size) || PTR_IN_REGION(*dptr, so->dso->init, so->dso->init_size) || PTR_IN_REGION(*dptr, so->dso->fini, so->dso->fini_size)) { fbt_add_callback(so->dso, (void*)*dptr); } dptr++; /* increase by sizeof(unsigned long) = bytes */ } } /* go through rodata */ dptr = (unsigned long*)(so->dso->rodata); if(dptr) { while((unsigned long)dptr < ((unsigned long)so->dso->rodata+(unsigned long)so->dso->rodata_size)) { /* check if the obtained address points to executable memory (potential callback target) */ if (PTR_IN_REGION(*dptr, so->text_addr, so->text_size) || PTR_IN_REGION(*dptr, so->dso->init, so->dso->init_size) || PTR_IN_REGION(*dptr, so->dso->fini, so->dso->fini_size)) { fbt_add_callback(so->dso, (void*)*dptr); } dptr++; /* increase by sizeof(unsigned long) = bytes */ } } /* go through reldyn */ dptr = (unsigned long*)(so->dso->reldyn); if(dptr) { while((unsigned long)dptr < ((unsigned long)so->dso->reldyn+(unsigned long)so->dso->reldyn_size)) { /* check if the obtained address points to executable memory (potential callback target) */ if (PTR_IN_REGION(*dptr, so->text_addr, so->text_size) || PTR_IN_REGION(*dptr, so->dso->init, so->dso->init_size) || PTR_IN_REGION(*dptr, so->dso->fini, so->dso->fini_size)) { fbt_add_callback(so->dso, (void*)*dptr); } dptr++; /* increase by sizeof(unsigned long) = bytes */ } } /* go through relplt */ dptr = (unsigned long*)(so->dso->relplt); if(dptr) { while((unsigned long)dptr < ((unsigned long)so->dso->relplt+(unsigned long)so->dso->relplt_size)) { /* check if the obtained address points to executable memory (potential callback target) */ if (PTR_IN_REGION(*dptr, so->text_addr, so->text_size) || PTR_IN_REGION(*dptr, so->dso->init, so->dso->init_size) || PTR_IN_REGION(*dptr, so->dso->fini, so->dso->fini_size)) { fbt_add_callback(so->dso, (void*)*dptr); } dptr++; /* increase by sizeof(unsigned long) = bytes */ } } } #endif /* CALLBACK_LIBRARIES_DATA_SECTION_SEARCH */ #endif /* VERIFY_CFTX */ /* All necessary information in memory -> unmap file */ sl_munmap(file_map, file_info.st_size); sl_close(fd); /* Protect dependencies and local search scope */ PROT_DATA(so->deps, so->deps_count*sizeof(dso *)); PROT_DATA(so->lscope, so->lscope_num*sizeof(dso *)); return so; }
/* The worker thread function with all the complex * logic in it! Big fat beast! Please watch your * children ... */ static void synch_worker (struct account_synch_msg *m) { ScalixAccountSynch *sxas; ScalixAccountSynchPrivate *priv; CamelException ex; CamelStore *store; CamelFolderInfo *ftree; CamelFolderInfo *sf; CamelSession *cs; const char *uri; gboolean res; char *sversion; char *markup; sxas = SCALIX_ACCOUNT_SYNCH (m->sxas); priv = SCALIX_ACCOUNT_SYNCH_GET_PRIVATE (sxas); uri = e_account_get_string (priv->account, E_ACCOUNT_SOURCE_URL); g_print ("SxAS: starting synch for %s\n", uri); signal_progress (sxas, 1, _("Trying to connect to server")); camel_exception_init (&ex); cs = scalix_camel_session_get_default (); camel_session_set_online (cs, TRUE); store = camel_session_get_store (cs, uri, &ex); if (store == NULL) { signal_error (sxas, _("Authentication failed. Check for correct hostname, username and password.")); return; } /* Must be online! */ camel_offline_store_set_network_state (CAMEL_OFFLINE_STORE (store), CAMEL_OFFLINE_STORE_NETWORK_AVAIL, &ex); camel_service_connect (CAMEL_SERVICE (store), &ex); if (camel_exception_is_set (&ex)) { signal_error (sxas, _("Error while trying to connect to server.")); return; } /* Always check for minimal required server version */ signal_progress (sxas, 10, _("Checking version of Scalix server")); g_print ("SxAS: Checking for minimal server version\n"); sversion = NULL; camel_object_get (store, NULL, CAMEL_SCALIX_STORE_SERVER_VERSION, &sversion, NULL); res = scalix_check_min_server_version (sversion); if (res == FALSE) { signal_error (sxas, _("Wrong version of Scalix server detected")); return; } m->sversion = g_strdup (sversion); g_print ("SxAS: sversion:%s\n", m->sversion); markup = g_markup_printf_escaped (MSG_SVER, sversion); signal_info (sxas, markup); g_free (markup); signal_progress (sxas, 20, _("Getting list of folders")); ftree = camel_store_get_folder_info (store, NULL, CAMEL_STORE_FOLDER_INFO_RECURSIVE | CAMEL_SCALIX_STORE_SHOW_SFOLDER, &ex); if (ftree == NULL) { camel_object_unref (store); signal_error (sxas, _("Could not obtain folder listening")); return; } /* Calendar */ signal_progress (sxas, 30, _("Loading calendar data...")); synch_data (sxas, ftree, CAMEL_SCALIX_FOLDER_CALENDAR, 30); m->esg_cals = create_group (priv->account, "Calendar"); sync_source_group (priv->account, m->esg_cals, CAMEL_SCALIX_FOLDER_CALENDAR, ftree); /* Contacts */ signal_progress (sxas, 60, _("Loading contacts...")); synch_data (sxas, ftree, CAMEL_SCALIX_FOLDER_CONTACT, 60); m->esg_cnts = create_group (priv->account, "Contacts"); sync_source_group (priv->account, m->esg_cnts, CAMEL_SCALIX_FOLDER_CONTACT, ftree); create_ldap_source (priv->account, m->esg_cnts); /* Sent Items and Drafts Folder */ if (priv->synch_dfolder) { char *url_str; CamelURL *url; url = camel_url_new (uri, NULL); signal_progress (sxas, 95, _("Synchronizing additional data")); sf = folder_tree_find_special (ftree, CAMEL_SCALIX_FOLDER_SENT); if (url && sf) { url_str = url_set_path_and_get_string (url, sf->full_name); e_account_set_string (priv->account, E_ACCOUNT_SENT_FOLDER_URI, url_str); g_free (url_str); } sf = folder_tree_find_special (ftree, CAMEL_SCALIX_FOLDER_DRAFTS); if (url && sf) { url_str = url_set_path_and_get_string (url, sf->full_name); e_account_set_string (priv->account, E_ACCOUNT_DRAFTS_FOLDER_URI, url_str); g_free (url_str); } if (url) { gboolean save_pw; camel_url_set_path (url, NULL); if (url->authmech == NULL) { camel_url_set_authmech (url, "PLAIN"); } url_str = camel_url_to_string (url, 0); e_account_set_string (priv->account, E_ACCOUNT_TRANSPORT_URL, url_str); save_pw = e_account_get_bool (priv->account, E_ACCOUNT_SOURCE_SAVE_PASSWD); e_account_set_bool (priv->account, E_ACCOUNT_TRANSPORT_SAVE_PASSWD, save_pw); } if (url) { camel_url_free (url); } } m->success = TRUE; g_print ("SxAS: DONE!\n"); camel_object_unref (store); signal_progress (sxas, 100, _("Done loading")); signal_info (sxas, _("Initial loading complete. Please click Forward.")); g_print ("SxAS: Freeing DONE\n"); return; }
/** * configures the filter * @param n the xml subtree */ virtual void _configure(const pugi::xml_node& n ) { if(pugi::xml_node c = n.child("ip_src")) { if(parse_filter_mode(c,m_ip_src_mode)) { if(pugi::xml_attribute attr = c.attribute("address")) { m_ip_src_address = string_to_ip(attr.value()); } else signal_error ("ip_src"); if(pugi::xml_attribute attr = c.attribute("netmask")) { m_ip_src_mask = string_to_ip(attr.value()); } else signal_error ("ip_src"); } else signal_error("ip_src"); } if(pugi::xml_node c = n.child("ip_dst")) { if(parse_filter_mode(c,m_ip_dst_mode)) { if(pugi::xml_attribute attr = c.attribute("address")) { m_ip_dst_address = string_to_ip(attr.value()); } else signal_error ("ip_dst"); if(pugi::xml_attribute attr = c.attribute("netmask")) { m_ip_dst_mask = string_to_ip(attr.value()); } else signal_error ("ip_dst"); } else signal_error("ip_dst"); } if(pugi::xml_node c = n.child("l4_protocol")) { if(parse_filter_mode(c,m_layer4_mode)) { if(pugi::xml_attribute attr = c.attribute("number")) { m_layer4_proto = attr.as_uint(); } else signal_error("l4_protocol"); } else signal_error("l4_protocol"); } if(pugi::xml_node c = n.child("src_port")) { if(parse_filter_mode(c,m_src_port_mode)) { if(pugi::xml_attribute attr = c.attribute("number")) { m_src_port = attr.as_uint(); } else signal_error("src_port"); } else signal_error("src_port"); } if(pugi::xml_node c = n.child("dst_port")) { if(parse_filter_mode(c,m_dst_port_mode)) { if(pugi::xml_attribute attr = c.attribute("number")) { m_dst_port = attr.as_uint(); } else signal_error("dst_port"); } else signal_error("dst_port"); } }
/************************************************************************* * dict_load - load a compiled dictionary into memory * creates a new dictionary * * fname - fully qualified file name * * Returns: pointer to created dictionary structure * (NULL on failure) *************************************************************************/ DICTIONARY *dict_load(const char *fname) { DICTIONARY *dict = NULL; int code, index; FILE *fi; int ntoc; if ( (fi=fopen((char*)fname,"rb")) == NULL ) { signal_error( "dict_load: could not open file" , (char*)fname , 0 ); goto err_exit; } /* endif */ if ((dict = (DICTIONARY *)malloc(sizeof(DICTIONARY))) == NULL) { /* signal_error( "dict_load: alloc failed" , "" , 0 ); */ goto err_exit; } /* endif */ /* Read the dictionary signature record */ if ((dict->sig = (DICT_SIG *)malloc(sizeof(DICT_SIG))) == NULL) { goto err_exit; } /* endif */ code = block_read( fi , (char*)(dict->sig) , sizeof(DICT_SIG) , 0 ); if ( code == -1 ) { signal_error( "dict_load: could not read signature" , (char*)fname , 0 ); goto err_exit; } /* endif */ if ( dict->sig->check_value != DICT_VALIDATE ) { signal_error( "dict_load: could not validate file" , (char*)fname , 0 ); goto err_exit; } /* endif */ dict->check_value = dict->sig->check_value; /* Read the dictionary Table of Contents */ ntoc = dict->sig->toc_size; dict->toc = (DICT_TOC_ENTRY *) malloc( ntoc * sizeof(DICT_TOC_ENTRY) ); if ( dict->toc == NULL ) { signal_error( "dict_load: alloc of TOC failed" , "" , 0 ); goto err_exit; } /* endif */ code = block_read( fi , (char*)(dict->toc) , ntoc * sizeof(DICT_TOC_ENTRY) , sizeof(DICT_SIG) ); if ( code == -1 ) { signal_error( "dict_load: could not read Table of Contents" , (char*)fname , 0 ); goto err_exit; } /* endif */ /* Read the dictionary parameters */ dict->parm = (DICT_PARM_ENTRY *) dict_load_block( dict , "PARM" , fi , NULL ); if ( dict->parm == NULL ) { signal_error( "dict_load: could not load parameter table" , "" , 0 ); goto err_exit; } /* endif */ index = dict_toc_index( dict , "PARM" ); dict->sig->nparms = dict->toc[index].size / sizeof(DICT_PARM_ENTRY); /* Set the parameter values in the dictionary structure */ if ( dict_set_parm_variables(dict) == FALSE ) goto err_exit; /* Load the string array */ dict->string_array = (char *) dict_load_block( dict , "STAR" , fi , NULL ); if ( dict->string_array == NULL ) { signal_error( "dict_load: could not load string array" , (char*)fname , 0 ); goto err_exit; } /* endif */ /* Load the string table */ dict->string_table = (STRING_ENTRY *) dict_load_block( dict , "STTB" , fi , NULL ); if ( dict->string_table == NULL ) { signal_error( "dict_load: could not load string table" , (char*)fname , 0 ); goto err_exit; } /* endif */ /* Load the hash table */ dict->chains = (long *) dict_load_block( dict , "HASH" , fi , NULL ); if ( dict->chains == NULL ) { signal_error( "dict_load: could not load hash table" , (char*)fname , 0 ); goto err_exit; } /* endif */ /* Initialize the hook for dictionary extensions */ dict->ext = NULL; /* Success */ fclose( fi ); return( dict ); /* Failure */ err_exit: if ( fi != NULL ) fclose( fi ); dict_destroy( dict ); return NULL; }