int parse_date_header(struct sip_msg *msg) { struct date_body* date_b; if ( !msg->date && (parse_headers(msg,HDR_DATE_F,0)==-1 || !msg->date) ) { LOG(L_ERR,"ERROR:parse_date_header: bad msg or missing DATE header\n"); goto error; } /* maybe the header is already parsed! */ if (msg->date->parsed) return 0; date_b=pkg_malloc(sizeof(*date_b)); if (date_b==0) { LOG(L_ERR, "ERROR:parse_date_header: out of memory\n"); goto error; } memset(date_b, 0, sizeof(*date_b)); parse_date(msg->date->body.s, msg->date->body.s + msg->date->body.len+1, date_b); if (date_b->error==PARSE_ERROR) { free_date(date_b); goto error; } msg->date->parsed=(void*)date_b; return 0; error: return -1; }
void init_date(T_DATE **pdate) { T_DATE **pd=pdate; if(NULL!=(*pd)){ free_date(*pd); (*pd)=NULL; } (*pd)=(T_DATE *)malloc(sizeof(T_DATE)); }
int main(void) { T_DATE *pdate=NULL; //pdate=(T_DATE *)malloc(sizeof(T_DATE)); // error: invalid application of ‘sizeof’ to incomplete type ‘T_DATE’ init_date(&pdate); set_date(pdate,10,7,2013); printf("%d-%d-%d\n",get_month(pdate),get_day(pdate),get_year(pdate)); //printf("%d-%d-%d\n",pdate->month,pdate->day,pdate->year);// error: dereferencing pointer to incomplete type free_date(pdate); return 0; }
/** Frees a hdr_field structure. * WARNING: it frees only parsed (and not name.s, body.s) */ void clean_hdr_field(struct hdr_field* const hf) { void** h_parsed; if (hf->parsed){ h_parsed=&hf->parsed; /* strict aliasing warnings workarround */ switch(hf->type){ /* headers with pkg alloc for parsed structure (alphabetic order) */ case HDR_ACCEPT_T: pkg_free(hf->parsed); break; case HDR_ALLOW_T: free_allow_header(hf); break; case HDR_AUTHORIZATION_T: free_credentials((auth_body_t**)h_parsed); break; case HDR_CONTACT_T: free_contact((contact_body_t**)h_parsed); break; case HDR_CONTENTDISPOSITION_T: free_disposition( ((struct disposition**)h_parsed)); break; case HDR_CSEQ_T: free_cseq(hf->parsed); break; case HDR_DATE_T: free_date(hf->parsed); break; case HDR_DIVERSION_T: free_to(hf->parsed); break; case HDR_EVENT_T: free_event((event_t**)h_parsed); break; case HDR_EXPIRES_T: free_expires((exp_body_t**)h_parsed); break; case HDR_FROM_T: free_to(hf->parsed); break; case HDR_IDENTITY_INFO_T: free_identityinfo(hf->parsed); break; case HDR_IDENTITY_T: free_identity(hf->parsed); break; case HDR_PAI_T: free_pai_ppi_body(hf->parsed); break; case HDR_PPI_T: free_pai_ppi_body(hf->parsed); break; case HDR_PROXYAUTH_T: free_credentials((auth_body_t**)h_parsed); break; case HDR_RECORDROUTE_T: free_rr((rr_t**)h_parsed); break; case HDR_REFER_TO_T: free_to(hf->parsed); break; case HDR_ROUTE_T: free_rr((rr_t**)h_parsed); break; case HDR_RPID_T: free_to(hf->parsed); break; case HDR_SESSIONEXPIRES_T: hdr_free_parsed(h_parsed); break; case HDR_SIPIFMATCH_T: free_sipifmatch((str **)h_parsed); break; case HDR_SUBSCRIPTION_STATE_T: free_subscription_state((subscription_state_t**)h_parsed); break; case HDR_SUPPORTED_T: hdr_free_parsed(h_parsed); break; case HDR_TO_T: free_to(hf->parsed); break; case HDR_VIA_T: free_via_list(hf->parsed); break; /* headers with no alloc for parsed structure */ case HDR_CALLID_T: case HDR_MAXFORWARDS_T: case HDR_CONTENTTYPE_T: case HDR_CONTENTLENGTH_T: case HDR_RETRY_AFTER_T: case HDR_REQUIRE_T: case HDR_PROXYREQUIRE_T: case HDR_UNSUPPORTED_T: case HDR_ACCEPTLANGUAGE_T: case HDR_ORGANIZATION_T: case HDR_PRIORITY_T: case HDR_SUBJECT_T: case HDR_USERAGENT_T: case HDR_SERVER_T: case HDR_MIN_SE_T: case HDR_ACCEPTCONTACT_T: case HDR_ALLOWEVENTS_T: case HDR_CONTENTENCODING_T: case HDR_REFERREDBY_T: case HDR_REJECTCONTACT_T: case HDR_REQUESTDISPOSITION_T: case HDR_WWW_AUTHENTICATE_T: case HDR_PROXY_AUTHENTICATE_T: case HDR_PATH_T: case HDR_PRIVACY_T: case HDR_REASON_T: break; default: LOG(L_CRIT, "BUG: clean_hdr_field: unknown header type %d\n", hf->type); break; } } }