Beispiel #1
0
/*
 * Parse digest credentials
 * Return value -1 means that the function was unable to allocate
 * memory and therefore the server should return Internal Server Error,
 * not Bad Request in this case !
 * Bad Request should be send when return value != -1
 */
int parse_credentials(struct hdr_field* _h)
{
	int res;
	void** ph_parsed;

	if (_h->parsed) {
		return 0;  /* Already parsed */
	}

	if (new_credentials(_h) < 0) {
		LM_ERR("can't create new credentials\n");
		return -1;
	}

	/* parse_digest_cred must return < -1 on error otherwise we will be
	 * unable to distinguish if the error was caused by the server or if the
	 * credentials are broken
	 */
	res = parse_digest_cred(&(_h->body), &(((auth_body_t*)(_h->parsed))->digest));

	if (res != 0) {
		ph_parsed=&_h->parsed;
		free_credentials((auth_body_t**)ph_parsed);
	}

	return res;
}
Beispiel #2
0
void protocol_start_session(DbXmlSessionData *session) {

  int r;
  DbXmlCredentials cred;
  DbXmlSessionOptions options;
  DbXmlSessionOptions *options_set;
  memset(&cred, 0, sizeof(DbXmlCredentials));
  memset(&options, 0, sizeof(DbXmlSessionOptions));

  if (initial_handshake(session) != 0)
    return;

  r = receive_credentials(session, &cred);

  if (r == 0)
    r = check_authentication(session, &cred);
  
  free_credentials(session, &cred);

  r = receive_session_options(session, &options);

  int init = -1;
  options_set = NULL;
  if (r == 0)
    init = r = initialize_session(session, &options, &options_set);

  session_response(session, r);

  if (r != 0)
    return;
  
  if (r == 0)
    r = send_session_options(session, options_set);

  free_session_options(session, &options);

  if (r == 0)
    protocol_request_response(session);
  
  if (init == 0)
    free_session(session);
  
}
Beispiel #3
0
/*
 * Frees a hdr_field structure,
 * WARNING: it frees only parsed (and not name.s, body.s)
 */
void clean_hdr_field(struct hdr_field* hf)
{
	if (hf->parsed){
		switch(hf->type){
		case HDR_VIA_T:
			free_via_list(hf->parsed);
			hf->parsed = NULL;
			break;

		case HDR_TO_T:
			free_to(hf->parsed);
			hf->parsed = NULL;
			break;

		case HDR_FROM_T:
			free_to(hf->parsed);
			hf->parsed = NULL;
			break;

		case HDR_CSEQ_T:
			free_cseq(hf->parsed);
			hf->parsed = NULL;
			break;

		case HDR_CALLID_T:
			break;

		case HDR_CONTACT_T:
			free_contact((contact_body_t**)(void*)(&(hf->parsed)));
			break;

		case HDR_MAXFORWARDS_T:
			break;

		case HDR_ROUTE_T:
			free_rr((rr_t**)(void*)(&hf->parsed));
			break;

		case HDR_RECORDROUTE_T:
			free_rr((rr_t**)(void*)(&hf->parsed));
			break;

		case HDR_PATH_T:
			free_rr((rr_t**)(void*)(&hf->parsed));
			break;

		case HDR_CONTENTTYPE_T:
			free_contenttype((content_t**)(void*)(&hf->parsed));
			break;

		case HDR_CONTENTLENGTH_T:
			break;

		case HDR_AUTHORIZATION_T:
			free_credentials((auth_body_t**)(void*)(&(hf->parsed)));
			break;

		case HDR_EXPIRES_T:
			free_expires((exp_body_t**)(void*)(&(hf->parsed)));
			break;

		case HDR_PROXYAUTH_T:
			free_credentials((auth_body_t**)(void*)(&(hf->parsed)));
			break;

		case HDR_SUPPORTED_T:
			free_supported((struct supported_body**)(void*)(&(hf->parsed)));
			break;

		case HDR_PROXYREQUIRE_T:
			break;

		case HDR_UNSUPPORTED_T:
			break;

		case HDR_ALLOW_T:
			free_allow((struct allow_body**)(void*)(&(hf->parsed)));
			break;

		case HDR_EVENT_T:
			free_event((event_t**)(void*)(&(hf->parsed)));
			break;

		case HDR_ACCEPT_T:
			pkg_free(hf->parsed);
			hf->parsed = NULL;
			break;

		case HDR_ACCEPTLANGUAGE_T:
			break;
			
		case HDR_ORGANIZATION_T:
			break;
			
		case HDR_PRIORITY_T:
			break;

		case HDR_SUBJECT_T:
			break;

		case HDR_USERAGENT_T:
			break;

		case HDR_ACCEPTDISPOSITION_T:
			break;

		case HDR_CONTENTDISPOSITION_T:
			free_disposition( ((struct disposition**)(void*)(&hf->parsed)) );
			break;

		case HDR_DIVERSION_T:
			free_to(hf->parsed);
			hf->parsed = NULL;
			break;

		case HDR_RPID_T:
			free_to(hf->parsed);
			hf->parsed = NULL;
			break;

		case HDR_REFER_TO_T:
			free_to(hf->parsed);
			hf->parsed = NULL;
			break;

		case HDR_SESSION_EXPIRES_T:
			free_session_expires((struct session_expires*)hf->parsed );
			hf->parsed = NULL;
			break;

		case HDR_MIN_SE_T:
			break;

		case HDR_MIN_EXPIRES_T:
			break;

		case HDR_PPI_T:
			free_to(hf->parsed);
			hf->parsed = NULL;
			break;

		case HDR_PAI_T:
			free_to(hf->parsed);
			hf->parsed = NULL;
			break;

		case HDR_PRIVACY_T:
			break;

		case HDR_RETRY_AFTER_T:
			break;

		case HDR_CALL_INFO_T:
			free_call_info(hf->parsed);
			hf->parsed = NULL;
			break;

		case HDR_WWW_AUTHENTICATE_T:
		case HDR_PROXY_AUTHENTICATE_T:
			free_authenticate((struct authenticate_body *)hf->parsed);
			hf->parsed = NULL;
			break;

		default:
			LM_CRIT("unknown header type %d\n", hf->type);
			break;
		}
	}
}
Beispiel #4
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;
		}
	}
}
Beispiel #5
0
/* 
 * Frees a hdr_field structure,
 * WARNING: it frees only parsed (and not name.s, body.s)
 */
void clean_hdr_field(struct hdr_field* hf)
{
	if (hf->parsed){
		switch(hf->type){
		case HDR_VIA:
			free_via_list(hf->parsed);
			break;

		case HDR_TO:
			free_to(hf->parsed);
			break;

		case HDR_FROM:
			free_to(hf->parsed);
			break;

		case HDR_CSEQ:
			free_cseq(hf->parsed);
			break;

		case HDR_CALLID:
			break;

		case HDR_CONTACT:
			free_contact((contact_body_t**)(&(hf->parsed)));
			break;

		case HDR_MAXFORWARDS:
			break;

		case HDR_ROUTE:
			free_rr((rr_t**)(&hf->parsed));
			break;

		case HDR_RECORDROUTE:
			free_rr((rr_t**)(&hf->parsed));
			break;

		case HDR_CONTENTTYPE:
			break;

		case HDR_CONTENTLENGTH:
			break;

		case HDR_AUTHORIZATION:
			free_credentials((auth_body_t**)(&(hf->parsed)));
			break;

		case HDR_EXPIRES:
			free_expires((exp_body_t**)(&(hf->parsed)));
			break;

		case HDR_PROXYAUTH:
			free_credentials((auth_body_t**)(&(hf->parsed)));
			break;

		case HDR_SUPPORTED:
			break;

		case HDR_PROXYREQUIRE:
			break;

		case HDR_UNSUPPORTED:
			break;

		case HDR_ALLOW:
			break;

		case HDR_EVENT:
			free_event((event_t**)(&(hf->parsed)));
			break;

		case HDR_ACCEPT:
			pkg_free(hf->parsed);
			break;

		case HDR_ACCEPTLANGUAGE:
			break;
			
		case HDR_ORGANIZATION:
			break;
			
		case HDR_PRIORITY:
			break;

		case HDR_SUBJECT:
			break;

		case HDR_USERAGENT:
			break;

		case HDR_ACCEPTDISPOSITION:
			break;

		case HDR_CONTENTDISPOSITION:
			free_disposition( ((struct disposition**)(&hf->parsed)) );
			break;

		default:
			LOG(L_CRIT, "BUG: clean_hdr_field: unknown header type %d\n",
			    hf->type);
			break;
		}
	}
}