LVal parse_attr(char* str) { int i,j; char *name,*val; struct Cons tmp,*ret=&tmp,*cur=ret; struct opts* p; tmp.next=(LVal)NULL; for(i=0;str[i]!='\0';++i) { name=NULL,val=NULL; /*skip space*/ int pos=position_char_not(" \t\r\n",&str[i]); if(pos!=-1) { i+=pos; }else continue; /*attr name */ pos=position_char("\"'>/= \t\r\n",&str[i]); if(pos!=-1) name=subseq(&str[i],0,pos),i+=pos; /*skip space*/ pos=position_char_not(" \t\r\n",&str[i]); if(pos!=-1) i+=pos; if(!(name && str[i]=='=')) continue; cur->next=(LVal)attralloc();; p=(struct opts*)firstp((LVal)cur->next); p->name=name; /*skip space*/ pos=position_char_not(" \t\r\n",&str[++i]); if(pos!=-1) { i+=pos; switch(str[i]) { case '\'': j=position_char("'",&str[i+1]); if(j!=-1) { val=subseq(&str[i+1],0,j); i+=j+1; } break; case '"': for(j=1;str[i+j]!='"';++j) if(str[i+j]=='\\') ++j; val=subseq(&str[i],1,j); i+=j; break; default: pos=position_char(" \t\r\n",&str[i]); val=subseq(&str[i],0,pos); break; } p->value=val; } cur=(struct Cons *)cur->next; } return (LVal)ret->next; }
static size_t header_callback(char *buffer, size_t size,size_t nitems, int *opt) { int pos=-1,pos2,code=0; if(strncmp("HTTP",buffer,nitems<4?nitems:4)==0) { pos=position_char(" ",buffer); if(pos!=-1 && (pos2=position_char_not("0123456789",&buffer[pos+1]))!=-1) { char *num=subseq(&buffer[pos+1],0,pos2); code=atoi(num),s(num); if(verbose) fprintf(c_out, "http response:%d\n",code); } if(400<=code) return 0; /*invoke error for curl*/ }else if(strncmp("content-length:",downcase(buffer),nitems<15?nitems:15)==0) { pos=position_char(" ",buffer); if(pos!=-1 && (pos2=position_char_not("0123456789",&buffer[pos+1]))!=-1) { char *num=subseq(&buffer[pos+1],0,pos2); code=atoi(num),s(num); content_length=code; } } return nitems * size; }