/**
 * Copyright (C) 2007 iptego GmbH
 *
 * This file is part of ser, a free SIP server.
 *
 * ser is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version
 *
 * ser is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#ifndef __ASI_DIGEST_H__
#define __ASI_DIGEST_H__

#include <binrpc.h>

#include "parser/msg_parser.h"
#include "select.h"
#include "usr_avp.h"
#include "modules/xlog/xl_lib.h"

enum DIG_TOK_TYPE {
	DIG_TOKT_IMM,
	DIG_TOKT_SEL,
	DIG_TOKT_AVP,
	DIG_TOKT_XLL, /* TODO: still needed? */
};

typedef struct {
	enum DIG_TOK_TYPE type;
	/* Cloned received BINRPC value:
	 * 	- returned for DIG_TOKT_IMM type 
	 * 	- keeps avp_ident_t's strings
	 */
	brpc_val_t *spec;
	union {
		select_t *sel;
		avp_ident_t avp; //TODO: avp_spec_t == avp_ident_t !:?
		xl_elog_t *xll;
	};
} tok_dig_t;

struct digest_format {
	tok_dig_t *toks;
	size_t cnt;
};

typedef struct {
	str name;
	struct digest_format req;
	struct digest_format fin;
	struct digest_format prov;
} meth_dig_t;


enum ASI_DSGT_IDS {
	ASI_DGST_ID_REQ	= 1,
	ASI_DGST_ID_FIN	= 2,
	ASI_DGST_ID_PRV	= 3,
};



meth_dig_t *meth_array_new(brpc_str_t **names, size_t cnt);
void meth_array_free(meth_dig_t *array, size_t cnt);
int meth_add_digest(meth_dig_t *meth, brpc_str_t *ident, brpc_val_t *array);
int digest(struct sip_msg *sipmsg, brpc_t *rpcreq, 
		tok_dig_t *toks, size_t tokcnt);

#define STR_EQ_BSTR(_str_, _bstr_) \
	(((_str_)->len == (_bstr_)->len) && \
	(strncmp((_str_)->s, (_bstr_)->val, (_bstr_)->len) == 0))

#endif /* __ASI_DIGEST_H__ */
