int parse_cig_header(execute_cgi_info_manager_t * cgi_info_manager, buffer * header) { if(header->ptr == NULL || header->used == 0) { return 0; } char *start = header->ptr; char *end = start+header->used; unsigned int ts ; string file ; while(start < end && *start != '\n') { start ++;} file.ptr = header->ptr; file.len = start - header->ptr; if(*start == '\n') { //string * file = string_init_from_str(cgi_info_manager->p, header->ptr, start- header->ptr); hash_item_t * hitem = get_hash_item(cgi_info_manager->h, file.ptr, file.len); ts = atoi(start+1); if( hitem) { epoll_cgi_t *cgi_info = (epoll_cgi_t *) hitem->value.ptr; if(ts > cgi_info->last_add_ts) { cgi_info->last_add_ts = ts; } } else { init_cgi_data_struct(&file, cgi_info_manager, ts); } } return 0; }
void parse_mimetypes_file( unsigned char *filename ) { int edx; FILE *file = fopen64( &filename[0], "rb" ); unsigned char line[1024]; if ( file ) { do { if ( fgets( line, 1023, file ) ) { unsigned char *ctype; unsigned char *token; if ( strchr( line, 35 ) ) *(char*)(strchr( line, 35 )) = 0; ctype[0] = line[0]; if ( ( ctype[0] & 255 ) && token[0] ) { token[0] = 0; if ( strchr( &ctype[0], 47 ) ) { token[0] = token[1]; while ( token[0] == 0 || token[0] == 0 ) { token[0] = 0; if ( !get_hash_item( mimetypes_map, &token[0], strlen( &token[0] ) ) && get_hash_item( mimetypes_map, &token[0], strlen( &token[0] ) ) ) { *ebp_1084 = memacpy( &ctype[0], strlen( &ctype[0] ) ); if ( ebp_1084 ) { memcpy( &token[0], &edi, edx + 4 ); if ( eax == 0 ) goto B34; else { token[0] = token[0] + 1; } } B34: done_mimetypes_entry( &edx ); } } } } } else fclose( file ); } while ( token[0] ); } if ( 0 ^ 0 ) { __stack_chk_fail( ); } return; }
int hash_get_ptr(hash_t *h, const char *key, int keyLen, void * ret, size_t size) { hash_item_t * item = get_hash_item(h, key, keyLen); if(item == NULL || item->type != HASH_ITEM_VALUE_TYPE_PTR) { return -1; } memcpy(ret, item->value.ptr, size); return 0; }
int hash_get_string(hash_t *h, const char *key, int keyLen, string * ret) { hash_item_t * item = get_hash_item(h, key, keyLen); if(item == NULL || item->type != HASH_ITEM_VALUE_TYPE_STRING) { return -1; } memcpy(ret, item->value.str, sizeof(string)); return 0; }
int hash_get_double(hash_t *h, const char *key, int keyLen, double * ret) { hash_item_t * item = get_hash_item(h, key, keyLen); if(item == NULL || item->type != HASH_ITEM_VALUE_TYPE_DOUBLE) { return -1; } *ret = item->value.d; return 0; }
int hash_get_long(hash_t *h, const char *key, int keyLen, long * ret) { hash_item_t * item = get_hash_item(h, key, keyLen); if(item == NULL || item->type != HASH_ITEM_VALUE_TYPE_LONG) { return -1; } *ret = item->value.l; return 0; }
int hash_get_int(hash_t *h, const char *key, int keyLen,int * ret) { hash_item_t * item = get_hash_item(h, key, keyLen); if(item == NULL || item->type != HASH_ITEM_VALUE_TYPE_INT) { return -1; } *ret = item->value.i; return 0; }
AfterShowXWindow* aftershow_XWindowID2XWindow (AfterShowContext *ctx, Window w) { ASHashData hdata = {0} ; int i; for (i = 0 ; i < ctx->gui.x.screens_num; ++i) { if (get_hash_item (ctx->gui.x.screens[i].windows, AS_HASHABLE(w), &hdata.vptr) == ASH_Success) return hdata.vptr; } return NULL; }
mem * count_find (const char *fname, int line, void *ptr, int type) { ASHashData hdata = {0}; if( allocs_hash != NULL ) if( get_hash_item( allocs_hash, (ASHashableValue)ptr, &hdata.vptr) == ASH_Success ) { mem *m = hdata.vptr ; if( (m->type & 0xff) == (type & 0xff) ) return m ; } return NULL ; }
void count_alloc (const char *fname, int line, void *ptr, size_t length, int type) { mem *m = NULL; ASHashResult res ; ASHashData hdata = {0}; if( service_mode > 0 ) return ; if( allocs_hash == NULL ) { service_mode++ ; allocs_hash = create_ashash( 256, pointer_hash_value, NULL, mem_destroy ); fprintf( stderr, "MEMORY AUDIT: count_alloc() called from %s:%d: allocs hash table created with pointer %p\n", fname, line, allocs_hash ); service_mode-- ; }else if( ptr == allocs_hash ) return; if( get_hash_item( allocs_hash, (ASHashableValue)ptr, &hdata.vptr ) == ASH_Success ) { m = (mem*)hdata.vptr ; if( type != (C_MEM|C_ADD_HASH_OPTIONAL_ITEM) ) { show_error( "Same pointer value 0x%lX is being counted twice!\n Called from %s:%d - previously allocated in %s:%d", (unsigned long)ptr, fname, line, m->fname, m->line ); print_simple_backtrace(); #ifdef DEBUG_ALLOC_STRICT { char *segv = NULL ; *segv = 0 ; } #endif }else return ; }else if( deallocated_used > 0 ) { m = deallocated_mem[--deallocated_used]; /* show_warning( "<mem> reusing deallocation cache - element %d, pointer %p auditing service memory used (%lu )\n Called from %s:%d", deallocated_used, m, total_service, fname, line ); */ }else { m = safecalloc (1, sizeof (mem)); if( total_service+sizeof(mem) > AUDIT_SERVICE_MEM_LIMIT ) { show_error( "<mem> too much auditing service memory used (%lu - was %lu)- aborting, please investigate.\n Called from %s:%d", total_service+sizeof(mem), total_service, fname, line ); print_simple_backtrace(); output_unfreed_mem (stderr); #ifdef DEBUG_ALLOC_STRICT { char *segv = NULL ; *segv = 0 ; } #endif exit(0); } total_service += sizeof(mem); if( total_service > max_service ) max_service = total_service ; } m->fname = fname; m->line = line; m->length = length; m->type = type; m->ptr = ptr; m->freed = 0; allocations++; if ((type & 0xff) == C_MEM) { total_alloc += length; if (total_alloc > max_alloc) max_alloc = total_alloc; } else { total_x_alloc += length; if (total_x_alloc > max_x_alloc) max_x_alloc = total_x_alloc; } if (allocations - deallocations > max_allocations) max_allocations = allocations - deallocations; if( (res = add_hash_item( allocs_hash, (ASHashableValue)ptr, m )) != ASH_Success ) show_error( "failed to log allocation for pointer 0x%lX - result = %d", ptr, res); else { if( total_service+sizeof(ASHashItem) > AUDIT_SERVICE_MEM_LIMIT ) { show_error( "<add_hash_item> too much auditing service memory used (%lu - was %lu)- aborting, please investigate.\n Called from %s:%d", total_service+sizeof(ASHashItem), total_service, fname, line ); print_simple_backtrace(); #ifdef DEBUG_ALLOC_STRICT { char *segv = NULL ; *segv = 0 ; } #endif exit(0); } total_service += sizeof(ASHashItem); if( total_service > max_service ) max_service = total_service ; } }
void gen_syntax_doc( const char *source_dir, const char *dest_dir, SyntaxDef *syntax, ASDocType doc_type ) { ASXMLInterpreterState state; const char *doc_path = AfterStepName ; char *syntax_dir = NULL ; int i ; ASFlagType doc_class_mask = 0 ; if( syntax ) { if( get_hash_item( ProcessedSyntaxes, AS_HASHABLE(syntax), NULL ) == ASH_Success ) return ; doc_path = syntax->doc_path ; } if( syntax != NULL && syntax->doc_path != NULL && syntax->doc_path[0] != '\0' ) syntax_dir = make_file_name (source_dir, syntax->doc_path); if( syntax_dir == NULL ) syntax_dir = mystrdup( source_dir ); if( doc_type == DocType_PHP ) { int overview_size = 0 ; int tmp ; /* we generate upto 4 files in PHP mode : overview, Base config, MyStyles and Config Options * Overview and Config Options are always present. Others may be ommited if source is missing * If Overview is too small - say < 1024 bytes - it could be bundled with Config Options */ set_flags( doc_class_mask, DOC_CLASS_Overview ); LOCAL_DEBUG_OUT( "Checking what parts to generate ...%s", ""); if( (tmp = check_xml_contents( syntax_dir, MyStylesOptionsEntry )) > 0) set_flags( doc_class_mask, DOC_CLASS_MyStyles ); LOCAL_DEBUG_OUT( "MyStyle size = %d", tmp ); if((tmp = check_xml_contents( syntax_dir, BaseOptionsEntry )) > 0) set_flags( doc_class_mask, DOC_CLASS_BaseConfig ); LOCAL_DEBUG_OUT( "Base size = %d", tmp ); for( i = 0 ; StandardSourceEntries[i] ; ++i ) overview_size += check_xml_contents( syntax_dir, StandardSourceEntries[i] ); if( syntax == NULL ) overview_size += 0 ; LOCAL_DEBUG_OUT( "overview size = %d", overview_size ); if( overview_size > OVERVIEW_SIZE_THRESHOLD ) set_flags( doc_class_mask, DOC_CLASS_Options ); }else doc_class_mask = DOC_CLASS_None ; if( !start_doc_file( dest_dir, doc_path, NULL, doc_type, syntax?syntax->doc_path:NULL, syntax?syntax->display_name:NULL, syntax?syntax->display_purpose:NULL, &state, doc_class_mask, DocClass_Overview ) ) return ; if( doc_type != DocType_PHP ) { /* BODY *************************************************************************/ i = 0 ; if( syntax == NULL ) { convert_xml_file( syntax_dir, StandardSourceEntries[0], &state ); ++i ; convert_xml_file( syntax_dir, StandardOptionsEntry, &state ); } for( ; i < OPENING_PARTS_END ; ++i ) convert_xml_file( syntax_dir, StandardSourceEntries[i], &state ); if( syntax ) { convert_xml_file( syntax_dir, BaseOptionsEntry, &state ); convert_xml_file( syntax_dir, MyStylesOptionsEntry, &state ); } }else { i = 0 ; if( syntax == NULL ) { convert_xml_file( syntax_dir, StandardSourceEntries[0], &state ); ++i ; convert_xml_file( syntax_dir, StandardOptionsEntry, &state ); } for( ; StandardSourceEntries[i] ; ++i ) { if (( convert_xml_file( syntax_dir, StandardSourceEntries[i], &state ) == True) && ( i == 0 ) ) fprintf( state.dest_fp, "<hr>\n" ); } if( get_flags( doc_class_mask, DOC_CLASS_Options ) ) { end_doc_file( &state ); start_doc_file( dest_dir, doc_path, "_options", doc_type, syntax?syntax->doc_path:NULL, syntax?syntax->display_name:NULL, syntax?syntax->display_purpose:NULL, &state, doc_class_mask, DocClass_Options ); fprintf( state.dest_fp, "<UL>\n" ); } } LOCAL_DEBUG_OUT( "starting config_options%s", "" ); if( syntax && state.dest_fp ) { write_options_header( &state ); write_options_keywords(source_dir, syntax_dir, syntax, &state ); write_options_footer( &state ); } LOCAL_DEBUG_OUT( "done with config_options%s", "" ); if( doc_type != DocType_PHP ) { for( i = OPENING_PARTS_END ; StandardSourceEntries[i] ; ++i ) convert_xml_file( syntax_dir, StandardSourceEntries[i], &state ); }else if( state.dest_fp ) { if( state.doc_class == DocClass_Options ) fprintf( state.dest_fp, "</UL>\n" ); if( get_flags( doc_class_mask, DOC_CLASS_BaseConfig ) ) { end_doc_file( &state ); start_doc_file( dest_dir, doc_path, BaseOptionsEntry, doc_type, syntax?syntax->doc_path:NULL, syntax?syntax->display_name:NULL, syntax?syntax->display_purpose:NULL, &state, doc_class_mask, DocClass_BaseConfig ); convert_xml_file( syntax_dir, BaseOptionsEntry, &state ); } if( get_flags( doc_class_mask, DOC_CLASS_MyStyles ) ) { end_doc_file( &state ); start_doc_file( dest_dir, doc_path, MyStylesOptionsEntry, doc_type, syntax?syntax->doc_path:NULL, syntax?syntax->display_name:NULL, syntax?syntax->display_purpose:NULL, &state, doc_class_mask, DocClass_MyStyles ); convert_xml_file( syntax_dir, MyStylesOptionsEntry, &state ); } } /* FOOTER ***********************************************************************/ end_doc_file( &state ); if( syntax ) add_hash_item( ProcessedSyntaxes, AS_HASHABLE(syntax), NULL ); free( syntax_dir ); }
void check_syntax_source( const char *source_dir, SyntaxDef *syntax, Bool module ) { int i ; char *syntax_dir = NULL ; char *obsolete_dir ; struct direntry **list = NULL; int list_len ; if( syntax ) { if( get_hash_item( ProcessedSyntaxes, AS_HASHABLE(syntax), NULL ) == ASH_Success ) return ; if( syntax->doc_path != NULL && syntax->doc_path[0] != '\0' ) syntax_dir = make_file_name (source_dir, syntax->doc_path); } if( syntax_dir == NULL ) syntax_dir = mystrdup( source_dir ); obsolete_dir = make_file_name (syntax_dir, "obsolete" ); if( CheckDir(syntax_dir) != 0 ) if( !make_doc_dir( syntax_dir ) ) { free( syntax_dir ); return; } if( syntax ) { add_hash_item( ProcessedSyntaxes, AS_HASHABLE(syntax), NULL ); /* pass one: lets see which of the existing files have no related options : */ list_len = my_scandir ((char*)syntax_dir, &list, ignore_dots, NULL); for (i = 0; i < list_len; i++) { int k ; if (!S_ISDIR (list[i]->d_mode)) { char *name = list[i]->d_name ; show_progress( "checking \"%s\" ... ", name ); if( name[0] != '_' ) { for (k = 0; syntax->terms[k].keyword; k++) if( mystrcasecmp(name, syntax->terms[k].keyword ) == 0 ) break; if( syntax->terms[k].keyword == NULL || get_flags( syntax->terms[k].flags, TF_OBSOLETE) ) { /* obsolete option - move it away */ char *obsolete_fname = make_file_name (obsolete_dir, name ); char *fname = make_file_name (syntax_dir, name ); Bool no_dir = False ; if( CheckDir(obsolete_dir) != 0 ) no_dir = !make_doc_dir( obsolete_dir ) ; if( !no_dir ) { copy_file (fname, obsolete_fname); show_progress( "Option \"%s\" is obsolete - moving away!", name ); unlink(fname); } free( fname ); free( obsolete_fname ); } } } free( list[i] ); } if( list ) free (list); /* pass two: lets see which options are missing : */ for (i = 0; syntax->terms[i].keyword; i++) { if( !get_flags( syntax->terms[i].flags, TF_OBSOLETE) ) { SyntaxDef *sub_syntax = syntax->terms[i].sub_syntax ; if( sub_syntax == pPopupFuncSyntax ) sub_syntax = pFuncSyntax ; if (sub_syntax) check_syntax_source( source_dir, sub_syntax, False ); if( isalnum( syntax->terms[i].keyword[0] ) ) check_option_source( syntax_dir, syntax->terms[i].keyword, sub_syntax, module?syntax->doc_path:NULL ) ; } } for (i = module?0:1; StandardSourceEntries[i] != NULL ; ++i) check_option_source( syntax_dir, StandardSourceEntries[i], NULL, module?syntax->doc_path:NULL ) ; if( module ) { check_option_source( syntax_dir, BaseOptionsEntry, NULL, syntax->doc_path ) ; check_option_source( syntax_dir, MyStylesOptionsEntry, NULL, syntax->doc_path ) ; } }else generate_main_source( syntax_dir ); free( obsolete_dir ); free( syntax_dir ); }
void write_doc_cdata( const char *cdata, int len, ASXMLInterpreterState *state ) { int i ; if( state->doc_type == DocType_XML || state->doc_type == DocType_HTML || state->doc_type == DocType_PHP ) { int token_start = 0; Bool special = False ; for( i = 0 ; i < len ; ++i ) { if( (!isalnum(cdata[i]) && cdata[i] != '_' && cdata[i] != '(' && cdata[i] != ')') || special ) { if( token_start < i ) { if( get_flags( state->flags, ASXMLI_InsideLink) ) { fwrite( &(cdata[token_start]), 1, i-token_start, state->dest_fp ); }else { /* need to try and insert an URL here if token is a keyword */ char *token = mystrndup( &(cdata[token_start]), i - token_start ); ASHashData hdata ; if( !special && get_hash_item(Links, AS_HASHABLE(token), &(hdata.vptr)) == ASH_Success ) { if( state->doc_type == DocType_HTML ) fprintf( state->dest_fp, "<A href=\"%s\">%s</A>", hdata.cptr, token ); else if( state->doc_type == DocType_PHP ) fprintf( state->dest_fp, PHPXrefFormat, "visualdoc",token, hdata.cptr, "" ); }else fwrite( token, 1, i-token_start, state->dest_fp ); free( token ); } } token_start = i+1 ; if( cdata[i] == '&' ) special = ( translate_special_sequence( &(cdata[i]), len-i, NULL ) != '\0' ); else if( cdata[i] == ';' && special ) special = False ; switch( cdata[i] ) { case '<' : fwrite( "<", 1, 4, state->dest_fp ); break ; case '>' : fwrite( ">", 1, 4, state->dest_fp ); break ; case '"' : fwrite( """, 1, 6, state->dest_fp ); break ; case '&' : if( !special ) { fwrite( "&", 1, 5, state->dest_fp ); break ; } /* otherwise falling through ! */ default: fputc( cdata[i], state->dest_fp ); } } } if( i > token_start ) fwrite( &(cdata[token_start]), 1, i-token_start, state->dest_fp ); }else { for( i = 0 ; i < len ; ++i ) { int c_len = 0 ; int c = '\0' ; if( cdata[i] == '&' ) c = translate_special_sequence( &(cdata[i]), len-i, &c_len ) ; if( c != '\0' ) i += c_len-1 ; else c = cdata[i]; if( c == '\"' && get_flags( state->flags, ASXMLI_EscapeDQuotes) ) fputc( '\"', state->dest_fp ); else if ( c == '-' && state->doc_type == DocType_NROFF ) fputc( '\\', state->dest_fp ); else if ( c == '.' && state->doc_type == DocType_NROFF ) fputs( "\\&", state->dest_fp ); else if ( c == '\\' && state->doc_type == DocType_NROFF ) fputc( '\\', state->dest_fp ); else if ( c == '' && state->doc_type == DocType_NROFF ) c = '~'; fputc( c, state->dest_fp ); } } }