int decode_vrrp(u_char *buf, int len, u_char *obuf, int olen) { struct buf *b, inbuf, outbuf; struct vrrp_header *vrrp; buf_init(&inbuf, buf, len); buf_init(&outbuf, obuf, olen); vrrp = (struct vrrp_header *)buf_ptr(&inbuf); if (buf_len(&inbuf) < sizeof(*vrrp)) return (0); /* We only care about VRRP_AUTH_SIMPLE */ if (ntohs(vrrp->vr_auth) != VRRP_AUTH_SIMPLE) return (0); /* XXX - probably want to verify checksum */ /* Forward to Authentication Data */ buf_skip(&inbuf, sizeof(*vrrp) + 8 + (vrrp->vr_naddr * 4)); if ((b = buf_tok(&inbuf, NULL, VRRP_AUTH_DATA_LEN)) == NULL) return (0); buf_put(&outbuf, buf_ptr(b), buf_len(b)); buf_put(&outbuf, "\n", 1); buf_end(&outbuf); return (buf_len(&outbuf)); }
/*---------------------------------------------------------------------------*/ void output_init(unsigned outputbuf_size, struct thread_ctx_s *ctx) { LOG_DEBUG("[%p] init output media renderer", ctx); ctx->outputbuf = &ctx->__o_buf; buf_init(ctx->outputbuf, outputbuf_size); if (!ctx->outputbuf->buf) { LOG_ERROR("[%p]: unable to malloc output buffer", ctx); exit(0); } if (strcasecmp(ctx->config.encode, "thru")) { ctx->encodebuf = &ctx->__e_buf; buf_init(ctx->encodebuf, outputbuf_size); if (!ctx->encodebuf->buf) { LOG_ERROR("[%p]: unable to malloc output buffer", ctx); exit(0); } } ctx->output.track_started = false; ctx->output.track_start = NULL; ctx->output_running = THREAD_KILLED; ctx->output.http = -1; ctx->output.icy.artist = ctx->output.icy.title = ctx->output.icy.artwork = NULL; ctx->render.index = -1; }
int decode_imap(u_char *buf, int len, u_char *obuf, int olen) { struct buf *line, inbuf, outbuf; int i; buf_init(&inbuf, buf, len); buf_init(&outbuf, obuf, olen); while ((i = buf_index(&inbuf, "\r\n", 2)) != -1) { line = buf_tok(&inbuf, NULL, i); buf_skip(&inbuf, 2); if ((i = buf_index(line, " ", 1)) != -1) { buf_skip(line, i + 1); if (buf_cmp(line, "LOGIN ", 6) == 0) { buf_putf(&outbuf, "%.*s\n", buf_len(line), buf_ptr(line)); } } } buf_end(&outbuf); return (buf_len(&outbuf)); }
void test_crypto (const struct crypto_options *co, struct frame* frame) { int i, j; struct gc_arena gc = gc_new (); struct buffer src = alloc_buf_gc (TUN_MTU_SIZE (frame), &gc); struct buffer work = alloc_buf_gc (BUF_SIZE (frame), &gc); struct buffer encrypt_workspace = alloc_buf_gc (BUF_SIZE (frame), &gc); struct buffer decrypt_workspace = alloc_buf_gc (BUF_SIZE (frame), &gc); struct buffer buf = clear_buf(); /* init work */ ASSERT (buf_init (&work, FRAME_HEADROOM (frame))); msg (M_INFO, "Entering " PACKAGE_NAME " crypto self-test mode."); for (i = 1; i <= TUN_MTU_SIZE (frame); ++i) { update_time (); msg (M_INFO, "TESTING ENCRYPT/DECRYPT of packet length=%d", i); /* * Load src with random data. */ ASSERT (buf_init (&src, 0)); ASSERT (i <= src.capacity); src.len = i; ASSERT (rand_bytes (BPTR (&src), BLEN (&src))); /* copy source to input buf */ buf = work; memcpy (buf_write_alloc (&buf, BLEN (&src)), BPTR (&src), BLEN (&src)); /* encrypt */ openvpn_encrypt (&buf, encrypt_workspace, co, frame); /* decrypt */ openvpn_decrypt (&buf, decrypt_workspace, co, frame); /* compare */ if (buf.len != src.len) msg (M_FATAL, "SELF TEST FAILED, src.len=%d buf.len=%d", src.len, buf.len); for (j = 0; j < i; ++j) { const uint8_t in = *(BPTR (&src) + j); const uint8_t out = *(BPTR (&buf) + j); if (in != out) msg (M_FATAL, "SELF TEST FAILED, pos=%d in=%d out=%d", j, in, out); } } msg (M_INFO, PACKAGE_NAME " crypto self-test mode SUCCEEDED."); gc_free (&gc); }
void network_init(struct network *net) { memset(net, 0, sizeof(struct network)); net->portno = DEFAULT_PORT; net->conf = prog_config.net_global_conf; buf_init(&net->sock); buf_init(&net->cmdfd); net->joinedfd = -1; net->motdfd = -1; net->rawfd = -1; net->realnamefd = -1; net->nicknamefd = -1; }
void status_flush(struct status_output *so) { if (so && so->fd >= 0 && (so->flags & STATUS_OUTPUT_WRITE)) { #if defined(HAVE_FTRUNCATE) { const off_t off = lseek(so->fd, (off_t)0, SEEK_CUR); if (ftruncate(so->fd, off) != 0) { msg(M_WARN, "Failed to truncate status file: %s", strerror(errno)); } } #elif defined(HAVE_CHSIZE) { const long off = (long) lseek(so->fd, (off_t)0, SEEK_CUR); chsize(so->fd, off); } #else /* if defined(HAVE_FTRUNCATE) */ #warning both ftruncate and chsize functions appear to be missing from this OS #endif /* clear read buffer */ if (buf_defined(&so->read_buf)) { ASSERT(buf_init(&so->read_buf, 0)); } } }
void kmain(u32 init_stack) { init_esp_start = init_stack; init_video(); puts_color_str("Booting Panda OS ...\n", 0x0B); cli(); time_init(); gdt_init(); idt_init(); kb_init(); mm_init(); buf_init(); file_init(); inode_init(); ide_init(); task_init(); timer_init(); sysc_init(); spawn(init_user); sti(); init = 0; while(1) { if(!init) { printk("kernel running ...\n"); init = 1; } sti(); sched(); } }
static PyObject *quote_literal_body(unsigned char *src, Py_ssize_t src_len) { struct Buf buf; unsigned char *esc, *dst, *src_end = src + src_len; unsigned int start_ofs = 1; if (src == NULL) return PyString_FromString("null"); esc = dst = buf_init(&buf, src_len * 2 + 2 + 1); if (!dst) return NULL; *dst++ = ' '; *dst++ = '\''; while (src < src_end) { if (*src == '\\') { *dst++ = '\\'; start_ofs = 0; } else if (*src == '\'') { *dst++ = '\''; } *dst++ = *src++; } *dst++ = '\''; if (start_ofs == 0) *esc = 'E'; return buf_pystr(&buf, start_ofs, dst); }
static void mass_init(int argc, char **argv) { option_init(argc, argv); if (!option_output_file) option_output_file = "a.out"; if (!option_input_file) { errmsg("mass: error: no input file specified\n"); exit(0); } FILE *tmp_in = fopen(option_input_file, "r"); if (!tmp_in) { errmsg("mass: error: %s: %s\n", option_input_file, strerror(errno)); exit(0); } yyset_in(tmp_in); symbol_table_init(); buf_init(); return; }
int main() { buf_pool_t *sp ; sp = buf_init(PROD_NUM,sizeof(test_ar_t)); int res ; pthread_t tid[THREAD_NUM] ; //store to child pthread pthread_t master_tid ; fprintPt(pthread_self()); res = pthread_create(&master_tid,NULL,master_thread_function,sp); if (res != 0) { fprintf(stderr,"pthread was create error \n"); exit(EXIT_FAILURE); } for(int i = 0 ;i < THREAD_NUM ;i++) //the child thread { res = pthread_create(&tid[i],NULL,thread_function,sp); if (res != 0) { fprintf(stderr,"pthread was create error \n"); exit(EXIT_FAILURE); } } printf("master thread : %lu \n ", pthread_self()); sleep(20); release(sp); return 0; }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(telnetd_process, ev, data) { PROCESS_BEGIN(); tcp_listen(HTONS(23)); buf_init(&buf); shell_init(); #if TELNETD_CONF_GUI telnetd_gui_init(); #endif /* TELNETD_CONF_GUI */ while(1) { PROCESS_WAIT_EVENT(); if(ev == tcpip_event) { telnetd_appcall(data); } else if(ev == PROCESS_EVENT_EXIT) { telnetd_quit(); } else { #if TELNETD_CONF_GUI telnetd_gui_eventhandler(ev, data); #endif /* TELNETD_CONF_GUI */ } } PROCESS_END(); }
/* FsMountVol : mount the file system volume */ INT32 FsMountVol(struct super_block *sb) { INT32 err, drv; sm_P(&z_sem); for (drv = 0; drv < MAX_DRIVE; drv++) { if (!fs_struct[drv].mounted) break; } if (drv >= MAX_DRIVE) { err = FFS_ERROR; goto ret_unlock; } sm_P(&(fs_struct[drv].v_sem)); err = buf_init(sb); if (!err) { err = ffsMountVol(sb, drv); } sm_V(&(fs_struct[drv].v_sem)); if (!err) { fs_struct[drv].mounted = TRUE; fs_struct[drv].sb = sb; } else { buf_shutdown(sb); } ret_unlock: sm_V(&z_sem); return(err); } /* end of FsMountVol */
bool buf_assign (struct buffer *dest, const struct buffer *src) { if (!buf_init (dest, src->offset)) return false; return buf_write (dest, BPTR (src), BLEN (src)); }
static struct cbuf * ld_ataraid_make_cbuf(struct ld_ataraid_softc *sc, struct buf *bp, u_int comp, daddr_t bn, void *addr, long bcount) { struct cbuf *cbp; cbp = CBUF_GET(); if (cbp == NULL) return (NULL); buf_init(&cbp->cb_buf); cbp->cb_buf.b_flags = bp->b_flags; cbp->cb_buf.b_oflags = bp->b_oflags; cbp->cb_buf.b_cflags = bp->b_cflags; cbp->cb_buf.b_iodone = sc->sc_iodone; cbp->cb_buf.b_proc = bp->b_proc; cbp->cb_buf.b_vp = sc->sc_vnodes[comp]; cbp->cb_buf.b_objlock = &sc->sc_vnodes[comp]->v_interlock; cbp->cb_buf.b_blkno = bn + sc->sc_aai->aai_offset; cbp->cb_buf.b_data = addr; cbp->cb_buf.b_bcount = bcount; /* Context for iodone */ cbp->cb_obp = bp; cbp->cb_sc = sc; cbp->cb_comp = comp; cbp->cb_other = NULL; cbp->cb_flags = 0; return (cbp); }
/* Reset to search beginning of buffer, looking for tag */ static void buf_reset(int source, int tag) { assert( source != MPI_ANY_SOURCE ); if ( recv_buf == NULL ) buf_init(); recv_buf[source].curs = 0; recv_buf[source].tag = tag; }
/* sanitize given string and replace all invalid UTF-8 sequences with "?" */ char * utf8(const char *s, unsigned int l) { struct template_buffer *buf = buf_init(l); unsigned char *ptr = (unsigned char *)s; unsigned int v, o; if (!buf) return NULL; for (o = 0; o < l; o++) { /* ascii char */ if ((*ptr >= 0x01) && (*ptr <= 0x7F)) { if (!buf_putchar(buf, (char)*ptr++)) break; } /* invalid byte or multi byte sequence */ else { if (!(v = _validate_utf8(&ptr, l - o, buf))) break; o += (v - 1); } } return buf_destroy(buf); }
static int CreateCellAddressTable(FILE *h, const struct vobgroup *va) /* outputs a VMGM_C_ADT, VTSM_C_ADT or VTS_C_ADT structure containing pointers to all cells. */ { int i, p, k; buf_init(); p = 8; for (k = 0; k < va->numvobs; k++) { const struct vob * const thisvob = va->vobs[k]; for (i = 0; i < thisvob->numvobus; i++) { if (!i || thisvob->vobu[i].vobcellid != thisvob->vobu[i - 1].vobcellid) { /* starting a new cell */ if (i) { buf_write4(p + 8, thisvob->vobu[i - 1].lastsector); /* ending sector within VOB in previous entry */ p += 12; } /*if*/ buf_write2(p, thisvob->vobu[i].vobcellid >> 8); /* VOBidn */ buf_write1(p + 2, thisvob->vobu[i].vobcellid); /* CELLidn */ buf_write4(p + 4, thisvob->vobu[i].sector); /* starting sector within VOB */ } /*if*/ } /*for*/ buf_write4(p + 8, thisvob->vobu[i - 1].lastsector); /* ending sector within VOB in last entry */ p += 12; } /*for*/ buf_write4(4, p - 1); /* end address (last byte of last entry) */ // first 2 bytes of C_ADT contains number of vobs buf_write2(0, va->numvobs); p = (p + 2047) & (-2048); /* round up to whole sectors */ nfwrite(bigbuf, p, h); return p / 2048; /* nr sectors written */ } /*CreateCellAddressTable*/
void Err(void) { printf(ERR); // bioscom(_COM_SEND,255,port); com_send(0xff); buf_init(); }
/** * Set process title, for the ps(1) command to report an updated title. * * The title is set from the executable's name, followed by the result of a * printf(3) style expansion of the arguments as specified by the fmt argument. * * If the fmt argument begins with a ``-'' character, the executable's name * is skipped. * * If fmt is NULL, the original process title is restored. */ void setproctitle(const char *fmt, ...) { va_list args; char *start; size_t len; buf_t *b, bs; start = progname_args_start(); len = progname_args_size(); if (0 == len) return; b = buf_init(&bs, start, len); memset(start, 0, len); va_start(args, fmt); if (NULL == fmt) { buf_printf(b, "%s", progstart_arg(0)); } else if ('-' == *fmt) { buf_vprintf(b, fmt + 1, args); } else { buf_printf(b, "%s ", getprogname()); buf_vcatf(b, fmt, args); } va_end(args); }
/*---------------------------------------------------------------------------*/ void telnetd_appcall(void *ts) { if(uip_connected()) { tcp_markconn(uip_conn, &s); buf_init(&buf); s.bufptr = 0; s.state = STATE_NORMAL; shell_start(); } if(s.state == STATE_CLOSE) { s.state = STATE_NORMAL; uip_close(); return; } if(uip_closed() || uip_aborted() || uip_timedout()) { closed(); } if(uip_acked()) { acked(); } if(uip_newdata()) { newdata(); } if(uip_rexmit() || uip_newdata() || uip_acked() || uip_connected() || uip_poll()) { senddata(); } }
char * striptags(const char *s, unsigned int l) { struct template_buffer *buf = buf_init(l); unsigned char *ptr = (unsigned char *)s; unsigned char *end = ptr + l; unsigned char *tag; unsigned char prev; char esq[8]; int esl; for (prev = ' '; ptr < end; ptr++) { if ((*ptr == '<') && ((ptr + 2) < end) && ((*(ptr + 1) == '/') || isalpha(*(ptr + 1)))) { for (tag = ptr; tag < end; tag++) { if (*tag == '>') { if (!isspace(prev)) buf_putchar(buf, ' '); ptr = tag; prev = ' '; break; } } } else if (isspace(*ptr)) { if (!isspace(prev)) buf_putchar(buf, *ptr); prev = *ptr; } else { switch(*ptr) { case '"': case '\'': case '<': case '>': case '&': esl = snprintf(esq, sizeof(esq), "&#%i;", *ptr); buf_append(buf, esq, esl); break; default: buf_putchar(buf, *ptr); break; } prev = *ptr; } } return buf_destroy(buf); }
/* * parse snapshot from cstring */ static TxidSnapshot * parse_snapshot(const char *str) { txid xmin; txid xmax; txid last_val = 0, val; const char *str_start = str; const char *endp; StringInfo buf; xmin = str2txid(str, &endp); if (*endp != ':') goto bad_format; str = endp + 1; xmax = str2txid(str, &endp); if (*endp != ':') goto bad_format; str = endp + 1; /* it should look sane */ if (xmin == 0 || xmax == 0 || xmin > xmax) goto bad_format; /* allocate buffer */ buf = buf_init(xmin, xmax); /* loop over values */ while (*str != '\0') { /* read next value */ val = str2txid(str, &endp); str = endp; /* require the input to be in order */ if (val < xmin || val >= xmax || val < last_val) goto bad_format; /* skip duplicates */ if (val != last_val) buf_add_txid(buf, val); last_val = val; if (*str == ',') str++; else if (*str != '\0') goto bad_format; } return buf_finalize(buf); bad_format: ereport(ERROR, (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), errmsg("invalid input syntax for type txid_snapshot: \"%s\"", str_start))); return NULL; /* keep compiler quiet */ }
int __cdecl main( int argc, char *argv[] ) { lex ilex; plexitem pil; buf in; str fn; arr out; uint i; uint fout; gentee_init(); printf("Start\n"); str_init( &fn ); str_copyzero( &fn, "gttbl.dat"); fout = os_fileopen( &fn, FOP_CREATE ); printf("Fout=%i %s\n", fout, str_ptr( &fn )); os_filewrite( fout, ( pubyte )&tbl_gt, 97 * sizeof( uint )); os_fileclose( ( pvoid )fout ); str_copyzero( &fn, "gtdotbl.dat"); fout = os_fileopen( &fn, FOP_CREATE ); printf("Fout=%i %s\n", fout, str_ptr( &fn )); str_delete( &fn ); os_filewrite( fout, ( pubyte )&tbl_gtdo, 81 * sizeof( uint )); os_fileclose( ( pvoid )fout ); arr_init( &out, sizeof( lexitem )); buf_init( &in ); buf_copyzero( &in, "</r/&xfa; &xfa; #ap/dfield( 'qwer ()ty' , \"my , name\" , qqq)#asdf.fgwsw/# se# &xaa;" "<2 qqq> </2><1 a2345=&xf0;> 223&</1><-qwe-rty->" "<mygt /asd = \"qwerty sese'\" qq21 = 'dedxd' 'esese;' aqaq=325623/>" "<a asdff /a> <mygtdd><a /><-ooops-><ad />< qq</>" "xxx </r/nm <_aa aqaqa /_aaaa /_a/_aa><a22222/ >" "<*abc ></abc><|*aaa = qqqq></aaa>ooops aaa</eee>\"\r\n</>"); // buf_copyzero( &in, "<mygt > <aaa asdff>qqqq</> </mygtdd>qq </> xxx </r/nm <_aa aqaqa /_aaaa /_aa> <a22222/ /> </ > "); printf("lex_init\n"); lex_init( &ilex, (puint)&tbl_gtdo ); printf("gentee_lex\n"); gentee_lex( &in, &ilex, &out ); if (arr_count(&ilex.state)) printf("================= State=%x/%i \n", arr_getuint( &ilex.state, arr_count(&ilex.state) - 1 ), arr_count(&ilex.state)); for ( i = 0; i < arr_count( &out ); i++ ) { pil = ( plexitem )arr_ptr( &out, i ); printf("ID=%x pos=%i len=%i \n", pil->type, pil->pos, pil->len, buf_ptr( &in ) + pil->pos ); } // gentee_compile(); lex_delete( &ilex ); buf_delete( &in ); arr_delete( &out ); gentee_deinit(); printf("OK\n"); getch(); return 0; }
static int process_smtp_client(struct smtp_info *smtp, char *data, int len) { struct buf *line, *body, buf; char *p; int i; buf_init(&buf, data, len); if (smtp->state != SMTP_DATA) { while ((i = buf_index(&buf, "\r\n", 2)) >= 0) { line = buf_tok(&buf, NULL, i + 2); line->base[line->end-1] = '\0'; p = buf_ptr(line); if (strncasecmp(p, "RSET", 4) == 0) { smtp->state = SMTP_HELO; } else if (smtp->state == SMTP_NONE && (strncasecmp(p, "HELO", 4) == 0 || strncasecmp(p, "EHLO", 4) == 0)) { smtp->state = SMTP_HELO; } else if (smtp->state == SMTP_HELO && (strncasecmp(p, "MAIL ", 5) == 0 || strncasecmp(p, "SEND ", 5) == 0 || strncasecmp(p, "SAML ", 5) == 0)) { smtp->from = grep_mail_address(p); smtp->state = SMTP_MAIL; } else if (smtp->state == SMTP_MAIL && strncasecmp(p, "RCPT ", 5) == 0) { smtp->state = SMTP_RCPT; } else if (smtp->state == SMTP_RCPT && strncasecmp(p, "DATA", 4) == 0) { smtp->state = SMTP_DATA; break; } } } if (smtp->state == SMTP_DATA) { if ((i = buf_index(&buf, "\r\n.\r\n", 5)) >= 0) { body = buf_tok(&buf, NULL, i); buf_skip(&buf, 5); body->base[body->end] = '\0'; if (regex_match(buf_ptr(body))) print_mbox_msg(smtp->from, buf_ptr(body)); if (smtp->from) { free(smtp->from); smtp->from = NULL; } smtp->state = SMTP_HELO; } } return (len - buf_len(&buf)); }
int nfcconf_lex_parse_string(nfcconf_parser * parser, const char *string) { BUFHAN bhan; int ret; buf_init(&bhan, (FILE *) NULL, string); ret = nfcconf_lex_engine(parser, &bhan); return ret; }
int page_test(PPartition *ppt,unsigned int block, unsigned int *buf, unsigned int ppb, unsigned char data) { int ret = 0; unsigned char *writebuf = (unsigned char *)buf; unsigned int writesize = ppt->byteperpage; unsigned char *readbuf = (unsigned char *)(buf + writesize * 3); BlockList blocklist; int i; int j = 0; ret =vnand_interface->iIsBadBlock(ppt,block); if(ret) dprintf("block %d is badblock\n",block); else dprintf("block %d is goodblock\n",block); blocklist.startBlock = block; blocklist.BlockCount =1; blocklist.head.next =0; /* // g_vnand.operator->MultiBlockErase(&blocklist); ret = nand_test_erase(ppt,&blocklist); if(ret != 0){ printk("erase %d block err!\n",block); return ret; } */ memset(writebuf, data, writesize); buf_init(writebuf, 1024); //while (j--) { //for (j=0;j<ppt->pageperblock;j++) { // printk("test pageid = %d\n",j); // ret = nand_test_write_page(ppt, j + block * ppt->pageperblock,0,writesize,(unsigned int *)writebuf); // if(ret < 0) // dprintf("\n****** page_test nand_test_write_page wrong ; ret =%d *****\n",ret); //clear buf for read memset(readbuf, 0xff, writesize*2); ret = nand_test_read_page(ppt, 11 + block * ppt->pageperblock,0,writesize,(unsigned int *)readbuf); if(ret) { dprintf("\n****** page_test nand_test_read_page wrong ; ret =%d *****\n",ret); for(i = 0; i < ppt->byteperpage; i++) { if(i % 8 == 0) printk("\n"); printk("%02x ",readbuf[i]); } printk("\n"); while(1); } // buf_check(writebuf, readbuf, writesize); dprintf("\n****** readbuf_phy_addr = 0x%08x writebuf_phy_addr = 0x%08x*****\n", CPHYSADDR(readbuf),CPHYSADDR(writebuf)); // dump_buf(writebuf,2048); // dump_buf(readbuf,2048); dprintf("\n****** page_test ok ok ok *****\n"); /* If you want know the data,please open these.*/ //} return ret; }
int decode_citrix(u_char *buf, int len, u_char *obuf, int olen) { struct buf inbuf, outbuf; u_char key, c, t[2]; int i; buf_init(&inbuf, buf, len); buf_init(&outbuf, obuf, olen); while ((i = buf_index(&inbuf, ica_magic, sizeof(ica_magic))) >= 0) { buf_skip(&inbuf, i); if (buf_len(&inbuf) < 60) break; buf_skip(&inbuf, 17); if (buf_get(&inbuf, &key, 1) != 1) break; buf_skip(&inbuf, 42); if (buf_get(&inbuf, &c, 1) != 1) break; c ^= ('C' | key); buf_put(&outbuf, &c, 1); i = 0; while (buf_get(&inbuf, t, 2) == 2) { c = t[0] ^ t[1] ^ key; if (c == '\0') { buf_put(&outbuf, "\n", 1); if (++i > 2) break; } buf_put(&outbuf, &c, 1); } } buf_end(&outbuf); return (buf_len(&outbuf)); }
/*---------------------------------------------------------------------------*/ void telnetd_appcall(void *ts) { if(uip_connected()) { if(!connected) { buf_init(&buf); s.bufptr = 0; s.state = STATE_NORMAL; connected = 1; shell_start(); timer_set(&s.silence_timer, MAX_SILENCE_TIME); ts = (char *)0; } else { uip_send(telnetd_reject_text, strlen(telnetd_reject_text)); ts = (char *)1; } tcp_markconn(uip_conn, ts); } if(!ts) { if(s.state == STATE_CLOSE) { s.state = STATE_NORMAL; uip_close(); return; } if(uip_closed() || uip_aborted() || uip_timedout()) { shell_stop(); connected = 0; } if(uip_acked()) { timer_set(&s.silence_timer, MAX_SILENCE_TIME); acked(); } if(uip_newdata()) { timer_set(&s.silence_timer, MAX_SILENCE_TIME); newdata(); } if(uip_rexmit() || uip_newdata() || uip_acked() || uip_connected() || uip_poll()) { senddata(); if(s.numsent > 0) { timer_set(&s.silence_timer, MAX_SILENCE_TIME); } } if(uip_poll()) { if(timer_expired(&s.silence_timer)) { uip_close(); tcp_markconn(uip_conn, NULL); } } } }
/* Create (malloc) a new buffer of size */ buffer* buf_new(unsigned int size) { buffer* ret; ret = (buffer*)m_malloc(sizeof(buffer)); buf_init(ret, size); return ret; }
/* * parse snapshot from cstring */ static TxidSnapshot * parse_snapshot(const char *str) { txid xmin; txid xmax; txid last_val = 0, val; const char *str_start = str; const char *endp; StringInfo buf; xmin = str2txid(str, &endp); if (*endp != ':') goto bad_format; str = endp + 1; xmax = str2txid(str, &endp); if (*endp != ':') goto bad_format; str = endp + 1; /* it should look sane */ if (xmin == 0 || xmax == 0 || xmin > xmax) goto bad_format; /* allocate buffer */ buf = buf_init(xmin, xmax); /* loop over values */ while (*str != '\0') { /* read next value */ val = str2txid(str, &endp); str = endp; /* require the input to be in order */ if (val < xmin || val >= xmax || val < last_val) goto bad_format; /* skip duplicates */ if (val != last_val) buf_add_txid(buf, val); last_val = val; if (*str == ',') str++; else if (*str != '\0') goto bad_format; } return buf_finalize(buf); bad_format: elog(ERROR, "invalid input for txid_snapshot: \"%s\"", str_start); return NULL; }