static void rehash_records(void) { SourceRecord *temp_records; unsigned int i, old_size, new_size; int slot, found; old_size = ARR_GetSize(records); temp_records = MallocArray(SourceRecord, old_size); memcpy(temp_records, ARR_GetElements(records), old_size * sizeof (SourceRecord)); /* The size of the hash table is always a power of two */ for (new_size = 1; !check_hashtable_size(n_sources, new_size); new_size *= 2) ; ARR_SetSize(records, new_size); for (i = 0; i < new_size; i++) get_record(i)->remote_addr = NULL; for (i = 0; i < old_size; i++) { if (!temp_records[i].remote_addr) continue; find_slot(temp_records[i].remote_addr, &slot, &found); assert(!found); *get_record(slot) = temp_records[i]; } Free(temp_records); }
void NSR_StartSources(void) { unsigned int i; for (i = 0; i < ARR_GetSize(records); i++) { if (!get_record(i)->remote_addr) continue; NCR_StartInstance(get_record(i)->data); } }
void NSR_HandleBadSource(IPAddr *address) { static struct timeval last_replacement; struct timeval now; NTP_Remote_Address remote_addr; SourceRecord *record; int slot, found; double diff; remote_addr.ip_addr = *address; remote_addr.port = 0; find_slot(&remote_addr, &slot, &found); if (!found) return; record = get_record(slot); /* Only sources with a name can be replaced */ if (!record->name) return; /* Don't resolve names too frequently */ SCH_GetLastEventTime(NULL, NULL, &now); UTI_DiffTimevalsToDouble(&diff, &now, &last_replacement); if (fabs(diff) < RESOLVE_INTERVAL_UNIT * (1 << MIN_REPLACEMENT_INTERVAL)) { DEBUG_LOG(LOGF_NtpSources, "replacement postponed"); return; } last_replacement = now; resolve_source_replacement(record); }
int NSR_TakeSourcesOnline(IPAddr *mask, IPAddr *address) { SourceRecord *record; unsigned int i; int any; NSR_ResolveSources(); any = 0; for (i = 0; i < ARR_GetSize(records); i++) { record = get_record(i); if (record->remote_addr) { if (address->family == IPADDR_UNSPEC || !UTI_CompareIPs(&record->remote_addr->ip_addr, address, mask)) { any = 1; NCR_TakeSourceOnline(record->data); } } } if (address->family == IPADDR_UNSPEC) { struct UnresolvedSource *us; for (us = unresolved_sources; us; us = us->next) { if (us->replacement) continue; any = 1; us->new_source.params.online = 1; } } return any; }
DB_RECORD_NUMBER Database::duplicate_record(DB_RECORD_NUMBER record_number, DatabasePtr new_database, LPERRORCODE lperror) { DB_RECORD_NUMBER new_record_number = 0; /* // Get the record for duplication purposes. */ if (record_number != 0) { DatabaseRecordPtr record; if ((record = get_record(record_number, lperror)) != NULL) { DatabaseRecordPtr new_record; /* Invoke the record to duplicate itself. */ if ((new_record = duplicate_record(record, new_database, lperror)) != NULL) { /* Success! Release the record after getting its number. */ new_record_number = new_record->Id(); new_record->release(); } record->release(); } } return new_record_number; }
int NAV_get_record ( ) { int result; for (;;) if (get_record ()) return 1; }
int substitute_ref_record(const char *direct, fileheader_t * fhdr, int ent) { fileheader_t hdr; char fname[PATHLEN]; int num = 0; /* rocker.011018: 串接模式用reference增進效率 */ if (!(fhdr->filemode & FILE_BOTTOM) && (fhdr->multi.refer.flag) && (num = fhdr->multi.refer.ref)){ setdirpath(fname, direct, FN_DIR); get_record(fname, &hdr, sizeof(hdr), num); if (strcmp(hdr.filename, fhdr->filename)) { if((num = getindex_m(fname, fhdr, num, 1))>0) { substitute_record(fname, fhdr, sizeof(*fhdr), num); } } else if(num>0) { fhdr->multi.money = hdr.multi.money; substitute_record(fname, fhdr, sizeof(*fhdr), num); } fhdr->multi.refer.flag = 1; fhdr->multi.refer.ref = num; // Ptt: update now! } substitute_record(direct, fhdr, sizeof(*fhdr), ent); return num; }
static gboolean k12_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { k12_t *k12 = (k12_t *)wth->priv; guint8* buffer; gint len; gboolean status; K12_DBG(5,("k12_seek_read: ENTER")); if ( file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) { K12_DBG(5,("k12_seek_read: SEEK ERROR")); return FALSE; } len = get_record(k12, wth->random_fh, seek_off, TRUE, err, err_info); if (len < 0) { K12_DBG(5,("k12_seek_read: READ ERROR")); return FALSE; } else if (len < K12_RECORD_SRC_ID + 4) { /* Record not large enough to contain a src ID */ K12_DBG(5,("k12_seek_read: SHORT READ")); *err = WTAP_ERR_SHORT_READ; return FALSE; } buffer = k12->rand_read_buff; status = process_packet_data(rec, buf, buffer, (guint)len, k12, err, err_info); K12_DBG(5,("k12_seek_read: DONE OK")); return status; }
static int u2dump(char *file) { u2record record; u2iterator *it = new_iterator(file); memset(&record, 0, sizeof(record)); if(!it) { printf("u2dump: Failed to create new iterator with file: %s\n", file); return -1; } while( get_record(it, &record) == SUCCESS ) { if(record.type == UNIFIED2_IDS_EVENT) event_dump(&record); else if(record.type == UNIFIED2_IDS_EVENT_VLAN) event2_dump(&record); else if(record.type == UNIFIED2_PACKET) packet_dump(&record); else if(record.type == UNIFIED2_IDS_EVENT_IPV6) event6_dump(&record); else if(record.type == UNIFIED2_IDS_EVENT_IPV6_VLAN) event2_6_dump(&record); else if(record.type == UNIFIED2_EXTRA_DATA) extradata_dump(&record); #if defined(FEAT_OPEN_APPID) else if(record.type == UNIFIED2_IDS_EVENT_APPID) event3_dump(&record); else if(record.type == UNIFIED2_IDS_EVENT_APPID_IPV6) event3_6_dump(&record); else if(record.type == UNIFIED2_IDS_EVENT_APPSTAT) appid_dump(&record); #endif /* defined(FEAT_OPEN_APPID) */ } free_iterator(it); if(record.data) free(record.data); return 0; }
const ValueType &remove(const KeyType &key) { auto record = get_record(key); if (record == nullptr) { throw HashTableException(); } if (record->head == nullptr) { hashTable_[get_hash_index(key)] = record->tail; } else if (record->tail == nullptr) { record->head->tail = nullptr; } else { record->head->tail = record->tail; record->tail->head = record->head; } size_--; const ValueType &value = record->value; delete record; return value; }
void NSR_Finalise(void) { SourceRecord *record; struct UnresolvedSource *us; unsigned int i; ARR_DestroyInstance(pools); for (i = 0; i < ARR_GetSize(records); i++) { record = get_record(i); if (record->remote_addr) clean_source_record(record); } ARR_DestroyInstance(records); while (unresolved_sources) { us = unresolved_sources; unresolved_sources = us->next; Free(us->name); Free(us); } initialised = 0; }
/* * Open the slurpd replication log, seek to our last known position, and * process any pending replication entries. */ static void populate_queue( char *f ) { FILE *fp, *lfp; char *p; if ( acquire_lock( f, &fp, &lfp ) < 0 ) { #ifdef NEW_LOGGING LDAP_LOG ( SLURPD, ERR, "populate_queue: error: can't lock file \"%s\": %s\n", f, sys_errlist[ errno ], 0 ); #else Debug( LDAP_DEBUG_ANY, "error: can't lock file \"%s\": %s\n", f, sys_errlist[ errno ], 0 ); #endif return; } /* * Read replication records from fp and append them the * the queue. */ if ( fseek( fp, sglob->srpos, 0 ) < 0 ) { #ifdef NEW_LOGGING LDAP_LOG ( SLURPD, ERR, "populate_queue: error: can't seek to offset %ld in file \"%s\"\n", sglob->srpos, f, 0 ); #else Debug( LDAP_DEBUG_ANY, "error: can't seek to offset %ld in file \"%s\"\n", sglob->srpos, f, 0 ); #endif } else { while (( p = get_record( fp )) != NULL ) { if ( sglob->rq->rq_add( sglob->rq, p ) < 0 ) { char *t; /* Print an error message. Only print first line. */ if (( t = strchr( p, '\n' )) != NULL ) { *t = '\0'; } #ifdef NEW_LOGGING LDAP_LOG ( SLURPD, ERR, "populate_queue: error: malformed replog entry " "(begins with \"%s\")\n", p, 0, 0 ); #else Debug( LDAP_DEBUG_ANY, "error: malformed replog entry (begins with \"%s\")\n", p, 0, 0 ); #endif } free( p ); ldap_pvt_thread_yield(); } sglob->srpos = ftell( fp ); } (void) relinquish_lock( f, fp, lfp ); }
static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) { struct GNUNET_NAMESTORE_PluginFunctions *nsp; struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded zone_key; struct GNUNET_CRYPTO_ShortHashCode zone; ok = 0; nsp = load_plugin (cfg); if (NULL == nsp) { FPRINTF (stderr, "%s", "Failed to initialize namestore. Database likely not setup, skipping test.\n"); return; } put_record (nsp, 1); get_record (nsp, 1); memset (&zone_key, 1, sizeof (zone_key)); GNUNET_CRYPTO_short_hash (&zone_key, sizeof (zone_key), &zone); nsp->delete_zone (nsp->cls, &zone); unload_plugin (nsp); }
/** internal sip naptr resolver function: resolves a host name trying: * - NAPTR lookup if the address is not an ip and *proto==0 and *port==0. * The result of the NAPTR query will be used for a SRV lookup * - SRV lookup if the address is not an ip *port==0. The result of the SRV * query will be used for an A/AAAA lookup. * - normal A/AAAA lookup (either fallback from the above or if *port!=0 * and *proto!=0 or port==0 && proto==0) * when performing SRV lookup (*port==0) it will use proto to look for * tcp or udp hosts, otherwise proto is unused; if proto==0 => no SRV lookup * returns: hostent struct & *port filled with the port from the SRV record; * 0 on error */ struct hostent* naptr_sip_resolvehost(str* name, unsigned short* port, char* proto) { struct hostent* he; struct ip_addr* ip; static char tmp[MAX_DNS_NAME]; /* tmp. buff. for SRV lookups and null. term strings */ struct rdata* l; struct rdata* naptr_head; char n_proto; str srv_name; naptr_bmp_t tried_bmp; /* tried bitmap */ char origproto; if(proto) origproto = *proto; naptr_head=0; he=0; if (name->len >= MAX_DNS_NAME) { LM_ERR("domain name too long\n"); goto end; } /* try NAPTR if no port or protocol is specified and NAPTR lookup is * enabled */ if (port && proto && (*proto==0) && (*port==0)){ *proto=PROTO_UDP; /* just in case we don't find another */ if ( ((ip=str2ip(name))!=0) || ((ip=str2ip6(name))!=0) ){ /* we are lucky, this is an ip address */ he=ip_addr2he(name,ip); *port=SIP_PORT; goto end; } memcpy(tmp, name->s, name->len); tmp[name->len] = '\0'; naptr_head=get_record(tmp, T_NAPTR, RES_AR); naptr_iterate_init(&tried_bmp); while((l=naptr_sip_iterate(naptr_head, &tried_bmp, &srv_name, &n_proto))!=0){ if ((he=srv_sip_resolvehost(&srv_name, 1, port, proto, 1, l))!=0){ *proto=n_proto; return he; } } /*clean up on exit*/ LM_DBG("no NAPTR record found for %.*s, trying SRV lookup...\n", name->len, name->s); } /* fallback to srv lookup */ if(proto) *proto = origproto; he=no_naptr_srv_sip_resolvehost(name,port,proto); /* fallback all the way down to A/AAAA */ if (he==0) { he=dns_get_he(name,dns_flags); } end: if (naptr_head) free_rdata_list(naptr_head); return he; }
static gboolean k12_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) { k12_t *k12 = (k12_t *)wth->priv; k12_src_desc_t* src_desc; guint8* buffer; gint64 offset; gint len; guint32 type; guint32 src_id; offset = file_tell(wth->fh); /* ignore the record if it isn't a packet */ do { K12_DBG(5,("k12_read: offset=%i",offset)); *data_offset = offset; len = get_record(k12, wth->fh, offset, FALSE, err, err_info); if (len < 0) { /* read error */ return FALSE; } else if (len == 0) { /* EOF */ *err = 0; return FALSE; } else if (len < K12_RECORD_SRC_ID + 4) { /* Record not large enough to contain a src ID */ *err = WTAP_ERR_BAD_FILE; *err_info = g_strdup_printf("data record length %d too short", len); return FALSE; } buffer = k12->seq_read_buff; type = pntoh32(buffer + K12_RECORD_TYPE); src_id = pntoh32(buffer + K12_RECORD_SRC_ID); if ( ! (src_desc = (k12_src_desc_t*)g_hash_table_lookup(k12->src_by_id,GUINT_TO_POINTER(src_id))) ) { /* * Some records from K15 files have a port ID of an undeclared * interface which happens to be the only one with the first byte changed. * It is still unknown how to recognize when this happens. * If the lookup of the interface record fails we'll mask it * and retry. */ src_desc = (k12_src_desc_t*)g_hash_table_lookup(k12->src_by_id,GUINT_TO_POINTER(src_id&K12_RECORD_SRC_ID_MASK)); } K12_DBG(5,("k12_read: record type=%x src_id=%x",type,src_id)); offset += len; } while ( ((type & K12_MASK_PACKET) != K12_REC_PACKET && (type & K12_MASK_PACKET) != K12_REC_D0020) || !src_id || !src_desc ); process_packet_data(&wth->phdr, wth->frame_buffer, buffer, len, k12); return TRUE; }
void NSR_GetActivityReport(RPT_ActivityReport *report) { SourceRecord *record; unsigned int i; struct UnresolvedSource *us; report->online = 0; report->offline = 0; report->burst_online = 0; report->burst_offline = 0; for (i = 0; i < ARR_GetSize(records); i++) { record = get_record(i); if (record->remote_addr) { NCR_IncrementActivityCounters(record->data, &report->online, &report->offline, &report->burst_online, &report->burst_offline); } } report->unresolved = 0; for (us = unresolved_sources; us; us = us->next) { report->unresolved++; } }
const std::string section::get_record_item (const std::string& rec_name) const { const record& rec = get_record (rec_name); if (rec.items_.size () != 1) throw rld::error ("duplicate", "record item: " + name + '/' + rec_name); return rec.items_[0].text; }
/* int apply_users(func) void (*func)() ; { register int i ; resolve_ucache() ; for(i=0; i < uidshm->number; i++) (*func)(uidshm->userid[i],i+1) ; return 0 ; } */ int getuser(char* userid) { int uid = searchuser(userid); if (uid == 0) return 0; get_record(PASSFILE, &lookupuser, sizeof(lookupuser), uid); return uid; }
/* * sync_threadfiles * if a .DIR entry has been updated, this function will make all changes * in respective thread files, updating fields that are common to both * .DIR & .THREADxxxx files * fhr - file header of the entry just modified * ent - which entry in .DIR is this file header * * return: 0 - success, * -1 - fail */ int sync_threadfiles(FILEHEADER *fhr, char *direct) { FILEHEADER filehdr; THRHEADHEADER thrhead, *p_thrhead=(THRHEADHEADER *)&filehdr; THRPOSTHEADER thrpost, *p_thrpost=(THRPOSTHEADER *)&filehdr; char path[STRLEN]; int index; /* make working copy of header structure */ memcpy( &filehdr, fhr, FH_SIZE ); /* update .THREADHEAD */ strcpy( path, direct ); *( strrchr(path,'/')+1 ) = '\0'; strcat( path, THREAD_HEAD_REC ); index = fhr->thrheadpos + 1; if( get_record( path, &thrhead, THRHEADHDR_SIZE, index ) == -1 ) return (-1); p_thrhead->numfollow = thrhead.numfollow; p_thrhead->thrpostpos = thrhead.thrpostpos; p_thrhead->thrheadpos = thrhead.thrheadpos; p_thrhead->thrpostidx = thrhead.thrpostidx; if( substitute_record( path, p_thrhead, THRHEADHDR_SIZE, index ) == -1 ) return (-1); /* update .THREADPOST */ *( strrchr(path,'/')+1 ) = '\0'; strcpy( path, THREAD_REC ); index = thrhead.thrpostpos + fhr->thrpostidx + 1; if( get_record( path, &thrpost, THRPOSTHDR_SIZE, index ) == -1 ) return (-1); p_thrpost->lastfollowidx = thrpost.lastfollowidx; p_thrpost->nextfollowidx = thrpost.nextfollowidx; p_thrpost->nextpostidx = thrpost.nextpostidx; p_thrpost->thrheadpos = thrpost.thrheadpos; p_thrpost->thrpostidx = thrpost.thrpostidx; if( substitute_record( path, p_thrpost, THRPOSTHDR_SIZE, index ) == -1 ) return (-1); return 0; }
extern void symtab_set(t_symtab *symtab, const char *s, void *data) { t_symrec *symrec; symrec = get_record(symtab, s); if (symrec) { symrec->data = data; } }
static unsigned char* apply_difference(unsigned char *before, int before_len, unsigned char *patch, int patch_len, int *result_len) { unsigned char *patch_ptr = patch; *result_len = *(int32_t*)patch_ptr; patch_ptr += 4; unsigned char *patch_end = patch + patch_len; unsigned char *before_end = before + before_len; unsigned char *result = new unsigned char[*result_len]; unsigned char *result_ptr = result; unsigned char *result_end = result + *result_len; unsigned char *before_ptr = before; int done = 0; while(!done) { unsigned char *after_data; int after_offset; int after_size; int before_size; get_record(&patch_ptr, patch_end, &after_data, &after_offset, &after_size, &before_size); if(after_data) { int result_offset = result_ptr - result; if(after_offset > result_offset) { int skip_size = after_offset - result_offset; memcpy(result_ptr, before_ptr, skip_size); result_ptr += skip_size; before_ptr += skip_size; } memcpy(result_ptr, after_data, after_size); result_ptr += after_size; before_ptr += before_size; } else { // All data from before_ptr to end of result buffer is identical if(result_end - result_ptr > 0) memcpy(result_ptr, before_ptr, result_end - result_ptr); done = 1; } } return result; }
void SharedAllocationRecord< Kokkos::CudaHostPinnedSpace , void >:: deallocate_tracked( void * const arg_alloc_ptr ) { if ( arg_alloc_ptr != 0 ) { SharedAllocationRecord * const r = get_record( arg_alloc_ptr ); RecordBase::decrement( r ); } }
const ValueType &get(const KeyType &key) const { auto record = get_record(key); if (record == nullptr) { throw HashTableException(); } return record->value; }
static int process_log_fd(const char *filename) { llist *entries; // entries in a record int ret; int first = 0; event first_event, last_event; last_event.sec = 0; last_event.milli = 0; /* For each record in file */ do { ret = get_record(&entries); if ((ret != 0)||(entries->cnt == 0)) break; // If report is RPT_TIME or RPT_SUMMARY, get if (report_type <= RPT_SUMMARY) { if (first == 0) { list_get_event(entries, &first_event); first = 1; if (very_first_event.sec == 0) list_get_event(entries, &very_first_event); } list_get_event(entries, &last_event); } if (scan(entries)) { // This is the per entry action item if (per_event_processing(entries)) found = 1; } list_clear(entries); free(entries); } while (ret == 0); fclose(log_fd); // This is the per file action items very_last_event.sec = last_event.sec; very_last_event.milli = last_event.milli; if (report_type == RPT_TIME) { if (first == 0) { printf("%s: no records\n", filename); } else { struct tm *btm; char tmp[32]; printf("%s: ", filename); btm = localtime(&first_event.sec); strftime(tmp, sizeof(tmp), "%x %T", btm); printf("%s.%03d - ", tmp, first_event.milli); btm = localtime(&last_event.sec); strftime(tmp, sizeof(tmp), "%x %T", btm); printf("%s.%03d\n", tmp, last_event.milli); } } return 0; }
void SharedAllocationRecord< Kokkos::Experimental::HBWSpace , void >:: deallocate_tracked( void * const arg_alloc_ptr ) { if ( arg_alloc_ptr != 0 ) { SharedAllocationRecord * const r = get_record( arg_alloc_ptr ); RecordBase::decrement( r ); } }
feather_callback void do_sched_trace_task_release(unsigned long id, unsigned long _task) { struct task_struct *t = (struct task_struct*) _task; struct st_event_record* rec = get_record(ST_RELEASE, t); if (rec) { rec->data.release.release = get_release(t); rec->data.release.deadline = get_deadline(t); put_record(rec); } }
record_stream::record_stream(FILE* file, unsigned int drop_wraps) : time_offset(0), rec_idx(0), file(file) { assert(file != NULL); unsigned int i=0; while (i < drop_wraps) { record rec = get_record(); if (rec.get_wrap_flag()) i++; } time_offset = 0; }
feather_callback void do_sched_trace_task_block(unsigned long id, unsigned long _task) { struct task_struct *t = (struct task_struct*) _task; struct st_event_record* rec = get_record(ST_BLOCK, t); if (rec) { rec->data.block.when = now(); put_record(rec); } }
feather_callback void do_sched_trace_task_resume(unsigned long id, unsigned long _task) { struct task_struct *t = (struct task_struct*) _task; struct st_event_record* rec = get_record(ST_RESUME, t); if (rec) { rec->data.resume.when = now(); put_record(rec); } }
feather_callback void do_sched_trace_sys_release(unsigned long id, unsigned long _start) { lt_t *start = (lt_t*) _start; struct st_event_record* rec = get_record(ST_SYS_RELEASE, NULL); if (rec) { rec->data.sys_release.when = now(); rec->data.sys_release.release = *start; put_record(rec); } }