/** * Got data from lower layer. */ static bool rx_chunk_recv(rxdrv_t *rx, pmsg_t *mb) { struct attr *attr = rx->opaque; bool error = FALSE; pmsg_t *imb; /* Dechunked message */ rx_check(rx); g_assert(mb); /* * Dechunk the stream, forwarding dechunked data to the upper layer. * At any time, a packet we forward can cause the reception to be * disabled, in which case we must stop. */ while ((attr->flags & IF_ENABLED) && (imb = dechunk_data(rx, mb))) { error = !(*rx->data.ind)(rx, imb); if (error) break; } pmsg_free(mb); /* * When we encountered the end of the stream, let them know. */ if ((attr->flags & IF_ENABLED) && attr->state == CHUNK_STATE_END) attr->cb->chunk_end(rx->owner); return !error; }
/** * Initialize the driver. */ static void * rx_chunk_init(rxdrv_t *rx, const void *args) { const struct rx_chunk_args *rargs = args; struct attr *attr; rx_check(rx); g_assert(rargs->cb != NULL); WALLOC(attr); attr->cb = rargs->cb; attr->flags = 0; attr->data_remain = 0; attr->hex_pos = 0; attr->state = CHUNK_STATE_SIZE; rx->opaque = attr; return rx; /* OK */ }
static int arx(char *fn) { if((arxfd=open(arxfn=fn,O_RDONLY))==-1) { (*er_printf)("error (%s): %s\n",arxfn,strerror(errno)); return 0; } else { errors=0; len_b=read(arxfd,buf,BUFSIZE); i_b=u_bom(buf,len_b); prevline=-1; line=1; col=0; rnc=0; cc=' '; getsym(); chk_get(SYM_GRMS); chk_get(SYM_LCUR); do { if(i_2==len_2) t2s=(int(*)[2])m_stretch(t2s,len_2=i_2*2,i_2,sizeof(int[2])); if(chksym(SYM_IDNT)) t2s[i_2][0]=add_s(value); getsym(); chk_get(SYM_ASGN); if(chksym(SYM_LTRL)) { if(path2abs) { int len=strlen(arxfn)+strlen(value)+1; if(len>len_v) {value=(char*)m_stretch(value,len,len_v,sizeof(char)); len_v=len;} s_abspath(value,arxfn); } t2s[i_2][1]=add_s(value); } getsym(); ++i_2; } while(sym==SYM_IDNT); chk_get(SYM_RCUR); for(;;) { if(i_r==len_r) rules=(int(*)[3])m_stretch(rules,len_r=i_r*2,i_r,sizeof(int[3])); switch(sym) { case SYM_MTCH: rules[i_r][0]=MATCH; goto REGEXP; case SYM_NMTC: rules[i_r][0]=NOMAT; goto REGEXP; REGEXP: getsym(); if(chksym(SYM_RGXP)) { if(!rx_check(value)) error(ARX_ER_REX); rules[i_r][1]=add_s(value); } getsym(); if(chksym(SYM_IDNT)) rules[i_r][2]=typ2str(); goto NEXT; case SYM_VALD: rules[i_r][0]=VALID; goto RNG; case SYM_NVAL: rules[i_r][0]=INVAL; goto RNG; RNG: getsym(); if(chksym(SYM_RENG)) { char *rncfn=(char*)m_alloc(strlen(arxfn)+strlen("#rnc[]")+12,sizeof(char)); sprintf(rncfn,"%s#rnc[%i]",arxfn,rnc++); if(!(rules[i_r][1]=rnl_s(rncfn,value,strlen(value)))) error(ARX_ER_RNG); m_free(rncfn); } getsym(); if(chksym(SYM_IDNT)) rules[i_r][2]=typ2str(); goto NEXT; default: goto LAST; } NEXT: ++i_r; getsym(); } LAST: chk_get(SYM_EOF); close(arxfd); return !errors; } }