/* XXX - still dangerous ... */ static inline int swap_entries(linked_list_t *list, size_t pos1, size_t pos2) { list_entry_t *e1; list_entry_t *e2; if(pos2 > pos1) { e2 = fetch_entry(list, pos2); insert_entry(list, e2, pos1); e1 = fetch_entry(list, pos1+1); insert_entry(list, e1, pos2); } else if(pos1 > pos2) { e1 = fetch_entry(list, pos1); insert_entry(list, e1, pos2); e2 = fetch_entry(list, pos2+1); insert_entry(list, e2, pos1); } else return -1; /* TODO - Unimplemented */ return 0; }
void alias0(const char *s, const char *old) { entree *ep, *e; GEN x; ep = fetch_entry(old); e = fetch_entry(s); if (EpVALENCE(e) != EpALIAS && EpVALENCE(e) != EpNEW) pari_err(e_MISC,"can't replace an existing symbol by an alias"); freeep(e); x = newblock(2); x[0] = evaltyp(t_STR)|_evallg(2); /* for getheap */ gel(x,1) = (GEN)ep; e->value=x; e->valence=EpALIAS; }
static bool read_metadata( struct metadata_accessor *accessor, void *dest, size_t num_bytes) { const struct hash_table_entry *entry = accessor->entry; unsigned int offset = accessor->offset; while (num_bytes != 0) { // Copy bytes from current block. size_t step_bytes = offset + num_bytes <= entry->usize ? num_bytes : entry->usize - offset; memcpy(dest, entry->udata + offset, step_bytes); dest += step_bytes; offset += step_bytes; num_bytes -= step_bytes; if (num_bytes != 0) { // Next block. long long start_block = entry->cnext; entry = fetch_entry(accessor->table, start_block); accessor->entry = entry; if (!entry) { ERROR("Table block %lld not found\n", start_block); return false; } offset = 0; } } accessor->offset = offset; return true; }
void addhelp(const char *e, char *s) { entree *ep = fetch_entry(e); if (ep->help && !EpSTATIC(ep)) pari_free((void*)ep->help); ep->help = pari_strdup(s); }
void binary_operate_on_value( entry_type e1 , entry_type e2 , value_type v , BinaryOperation& op ) { std::pair<row_iterator,column_iterator> results = fetch_entry( e1 , e2 , v ); row_iterator ri = results.first; column_iterator ci = results.second; value_type new_value = op( ci->second , v ); ci->second = new_value; ri->second.insert( ci , *ci ); }
void * list_fetch_value(linked_list_t *list, size_t pos) { void *val = NULL; list_entry_t *entry = fetch_entry(list, pos); if(entry) { val = entry->value; destroy_entry(entry); } return val; }
static bool init_metadata_accessor( struct metadata_accessor *accessor, struct metadata_table *table, squashfs_block start_block, unsigned short offset) { const struct hash_table_entry *entry = fetch_entry(table, start_block); if (!entry) { ERROR("Table block %lld not found\n", start_block); return false; } accessor->table = table; accessor->entry = entry; accessor->offset = offset; return true; }
long fetch_user_var(const char *s) { entree *ep = fetch_entry(s); long v; switch (EpVALENCE(ep)) { case EpVAR: return varn((GEN)initial_value(ep)); case EpNEW: break; default: pari_err(e_MISC, "%s already exists with incompatible valence", s); } v = pari_var_create(ep); ep->valence = EpVAR; ep->value = initial_value(ep); return v; }
/* return old entry at pos */ static inline list_entry_t *subst_entry(linked_list_t *list, uint32_t pos, list_entry_t *entry) { list_entry_t *old; MUTEX_LOCK(&list->lock); old = fetch_entry(list, pos); if(!old) return NULL; insert_entry(list, entry, pos); MUTEX_UNLOCK(&list->lock); /* XXX - NO CHECK ON INSERTION */ return old; }
/* We're making a new annotation to a url. Pass in the title, author, and text of the annotation. */ mo_status mo_new_pan (char *url, char *title, char *author, char *text) { entry *l = fetch_entry (url); int id = ++max_pan_id; if (!title || !*title) title = strdup ("Annotation with no title"); if (!author || !*author) author = strdup ("No author name"); /* Create a new entry if we have to. */ if (!l) l = new_entry (hash_url (url), url); /* Register the new annotation id with the entry. */ add_an_to_entry (l, id); mo_write_pan (id, title, author, text); return mo_succeed; }
static inline int move_entry(linked_list_t *list, size_t srcPos, size_t dstPos) { list_entry_t *e; e = fetch_entry(list, srcPos); if(e) { if(insert_entry(list, e, dstPos) == 0) return 0; else { if(insert_entry(list, e, srcPos) != 0) { //fprintf(stderr, "Can't restore entry at index %lu while moving to %lu\n", srcPos, dstPos); } } } /* TODO - Unimplemented */ return -1; }
entree * install(void *f, const char *name, const char *code) { long arity = check_proto(code); entree *ep; check_name(name); ep = fetch_entry(name); if (ep->valence != EpNEW) { if (ep->valence != EpINSTALL) pari_err(e_MISC,"[install] identifier '%s' already in use", name); pari_warn(warner, "[install] updating '%s' prototype; module not reloaded", name); if (ep->code) pari_free((void*)ep->code); } else { ep->value = f; ep->valence = EpINSTALL; } ep->code = pari_strdup(code); ep->arity = arity; return ep; }
/* For the given url, fetch an HTML-format hyperlink table to be appended to the document text. */ char *mo_fetch_pan_links (char *url, int on_top) { entry *l = fetch_entry (url); char *msg = NULL; char line[MO_LINE_LENGTH]; char *status; char *default_directory = Rdata.private_annotation_directory; int i, count = 0; if (!l) { return NULL; } if (!l->num_pans) { return NULL; } /* OK, now we've got the entry. Basically, we step through the available annotations and manufacture links: <h2>Personal Annotations</h2> <ul> <li> Title, Date <li> Title, Date </ul> */ msg = smart_append (msg, "<h2>Personal Annotations</h2>\n<ul>\n"); for (i = 0; i < l->num_pans; i++) { /* What's the annotation called? */ char filename[500]; extern char *shortmachine; FILE *fp; /* Do we have to assume we're opening a file with suffix .html??? */ sprintf (filename, "%s/%s/%s%d.html\0", home, default_directory, PAN_ANNOTATION_PREFIX, l->an[i]); fp = fopen (filename, "r"); if (fp) { status = fgets (line, MO_LINE_LENGTH, fp); if (status && *line) { /* See if it's our format. */ if (!strncmp (line, NCSA_ANNOTATION_FORMAT_ONE, strlen (NCSA_ANNOTATION_FORMAT_ONE))) { char chunk[500]; count++; /* Second line is the title. */ status = fgets (line, MO_LINE_LENGTH, fp); sprintf (chunk, "<li> <a href=\"file://%s%s\">%s</a> ", shortmachine, filename, extract_meat (line, 7)); msg = smart_append (msg, chunk); /* Third line is skipped. */ status = fgets (line, MO_LINE_LENGTH, fp); /* Fourth line is the author; skipped. */ status = fgets (line, MO_LINE_LENGTH, fp); /* Fifth line is the date. */ status = fgets (line, MO_LINE_LENGTH, fp); sprintf (chunk, "(%s)\n", extract_meat (line, 9)); msg = smart_append (msg, chunk); /* That's it. */ } } fclose (fp); } } /* If we made it all this way and it turns out we don't actually have anything yet, then punt. */ if (!count) { free (msg); return NULL; } msg = smart_append (msg, "</ul>\n"); return msg; }
void insert( entry_type e1 , entry_type e2 , value_type v ) { fetch_entry( e1 , e2 , v ); }
static int myworker (struct handle_struct *handle, void *packet, int len, struct timeval *tv){ struct iphdr *i; struct in_addr x; struct in_addr y; struct tcphdr *tcph; struct udphdr *udph; struct value_struct connection; //guint64 val=(guint64)tv->tv_sec; Have not been able to gain a timestamp from any paket so far! time_t now = time (NULL); guint64 val=(guint64)now; // using system time when paket arrives instead i = (struct iphdr *) (packet); connection.protocol = i->protocol; if( connection.protocol == 6 ){ tcph = (struct tcphdr *)(packet + sizeof(struct iphdr)); connection.dst_port = ntohs(tcph->dest); } if( connection.protocol == 17 ){ udph = (struct udphdr *)(packet + sizeof(struct iphdr)); connection.dst_port = ntohs(udph->dest); } if (len < sizeof (struct iphdr)) return -1; if (len != ntohs(i->tot_len)) return -1; x.s_addr = i->saddr; y.s_addr = i->daddr; connection.src_ip = i->saddr; connection.dst_ip = i->daddr; inet_ntop(AF_INET, &x, connection.s_src_ip, sizeof(connection.s_src_ip)); inet_ntop(AF_INET, &y, connection.s_dst_ip, sizeof(connection.s_dst_ip)); g_debug("Source: %s \n",connection.s_src_ip); g_debug("Destination: %s \n",connection.s_dst_ip); g_debug("Source: %i \n",connection.src_ip); g_debug("Destination: %i \n",connection.dst_ip); g_debug("Protocol: %i \n",connection.protocol); /* 1= ICMP, 6= TCP, 17=UDP */ g_debug("Destination Port: %i\n",connection.dst_port); /* in whitelist? */ if (TRUE == listman_check_key(handle->whitelist,&connection,val,handle->timeout)){ g_debug("in whitelist"); return 0; } /* already in blacklist? */ if (FALSE == listman_check_key(handle->blacklist,&connection,val,handle->timeout)){ if ( TRUE == fetch_entry(handle->url->str,&connection)){ g_debug("recieved user: %s",connection.username); g_debug("Calling Check Policy Function"); if (TRUE == checkpolicy(&connection)){ listman_add2list(handle->whitelist,&connection,&val); return 0; } } else { listman_add2list(handle->blacklist,&connection,&val); } } g_debug("in blacklist"); return -1; }
void my_fileset_reload(struct my_fileset *fs) { assert(fs != NULL); struct fileset_entry *ent, **entptr; entry_vec *new_entries; FILE *fp; char *fname, *line = NULL; size_t len = 0; ubuf *u; if (!setfile_updated(fs)) return; fp = fopen(fs->setfile, "r"); if (fp == NULL) return; u = ubuf_init(64); new_entries = entry_vec_init(1); while (getline(&line, &len, fp) != -1) { ubuf_clip(u, 0); if (line[0] != '/') { /* if not absolute path, prepend fileset file's path */ ubuf_add_cstr(u, fs->setdir); ubuf_add(u, '/'); } ubuf_add_cstr(u, line); ubuf_rstrip(u, '\n'); fname = ubuf_cstr(u); if (path_exists(fname)) { entptr = fetch_entry(fs->entries, fname); if (entptr == NULL) { ent = my_calloc(1, sizeof(*ent)); ent->fname = my_strdup(fname); if (fs->load) ent->ptr = fs->load(fs, fname); entry_vec_add(new_entries, ent); } else { ent = my_calloc(1, sizeof(*ent)); ent->fname = my_strdup(fname); ent->ptr = (*entptr)->ptr; (*entptr)->keep = true; entry_vec_add(new_entries, ent); } } } free(line); fclose(fp); qsort(entry_vec_data(new_entries), entry_vec_size(new_entries), sizeof(void *), cmp_fileset_entry); for (size_t i = 0; i < entry_vec_size(fs->entries); i++) { ent = entry_vec_value(fs->entries, i); assert(ent != NULL); if (ent->keep == false && fs->unload) fs->unload(fs, ent->fname, ent->ptr); free(ent->fname); free(ent); } entry_vec_destroy(&fs->entries); fs->entries = new_entries; ubuf_destroy(&u); }