static int msg_cb (void *dummy_arg, rfc822parse_event_t event, rfc822parse_t msg) { show_event (event); if (event == RFC822PARSE_T2BODY) { rfc822parse_field_t ctx; void *ectx; const char *line; for (ectx=NULL; (line = rfc822parse_enum_header_lines (msg, &ectx)); ) { printf ("*** HDR: %s\n", line); } rfc822parse_enum_header_lines (NULL, &ectx); /* Close enumerator. */ ctx = rfc822parse_parse_field (msg, "Content-Type", -1); if (ctx) { const char *s1, *s2; s1 = rfc822parse_query_media_type (ctx, &s2); if (s1) printf ("*** media: `%s/%s'\n", s1, s2); else printf ("*** media: [not found]\n"); show_param (ctx, "boundary"); show_param (ctx, "protocol"); rfc822parse_release_field (ctx); } else printf ("*** media: text/plain [assumed]\n"); ctx = rfc822parse_parse_field (msg, "Content-Disposition", -1); if (ctx) { const char *s1; TOKEN t; s1 = rfc822parse_query_parameter (ctx, NULL, 1); if (s1) printf ("*** disp: type=`%s'\n", s1); s1 = rfc822parse_query_parameter (ctx, "filename", 0); if (s1) printf ("*** disp: fname=`%s'\n", s1); rfc822parse_release_field (ctx); } } return 0; }
static int sess_param(struct iscsi_target *target, struct iscsi_param_info *info, int set) { struct iscsi_session *session = NULL; struct iscsi_sess_param *param; int err = -ENOENT; if (set) sess_param_check(info); if (info->sid) { if (!(session = session_lookup(target, info->sid))) goto out; param = &session->param; } else { param = &target->sess_param; } if (set) { sess_param_set(param, info); show_param(param); } else sess_param_get(param, info); err = 0; out: return err; }
/* DUMPPARAMS -- Go through the given pfile and list out its parameters on * t_stdout in the form `task.param=value'. */ void dumpparams (struct pfile *pfp) { register struct param *pp; register FILE *fp = currentask->t_stdout; for (pp = pfp->pf_pp; pp != NULL; pp = pp->p_np) if (!(pp->p_mode & M_HIDDEN)) show_param (pfp->pf_ltp, pp, fp); for (pp = pfp->pf_pp; pp != NULL; pp = pp->p_np) if (pp->p_mode & M_HIDDEN) show_param (pfp->pf_ltp, pp, fp); fputs ("# EOF\n", fp); }
int main( int argc, char **argv ) { char line[5000]; char *name, *newname=NULL; size_t length; RFC822 msg; RFC822_PARSE_CTX ctx; const char *s1, *s2; if( argc > 2 ) { newname = argv[2]; name = argv[1]; } else if( argc > 1 ) name = argv[1]; else name = "Content-Type"; msg = rfc822_open( NULL, NULL ); if( !msg ) abort(); while( fgets( line, sizeof(line), stdin ) ) { length = strlen( line ); if( length && line[length-1] == '\n' ) line[--length] = 0; if( length && line[length-1] == '\r' ) line[--length] = 0; if( rfc822_insert( msg, line, length ) ) abort(); } if( newname ) { HDR_LINE h; if( rfc822_rename_header( msg, name, newname, 0 ) ) abort(); for(h = msg->hdr_lines; h; h = h->next ) puts( h->line ); } else if( 1 ) { HDR_LINE h; if( rfc822_remove_header( msg, name,0 ) ) abort(); for(h = msg->hdr_lines; h; h = h->next ) puts( h->line ); } else { ctx = rfc822_parse_header( msg, name, -1 ); dump_token_list( ctx); s1 = ctx? rfc822_query_media_type( ctx, &s2 ) : NULL; if( s1 ) printf("media: `%s' `%s'\n", s1, s2 ); else printf("media: [not found]\n"); show_param( ctx, "boundary" ); show_param( ctx, "protocol" ); show_param( ctx, "micalg" ); rfc822_release_parse_ctx( ctx ); } rfc822_close( msg ); return 0; }