Mercurial > hg > freeDiameter
comparison libfdproto/messages.c @ 1103:d8591b1c56cd
Implemented a few hooks
author | Sebastien Decugis <sdecugis@freediameter.net> |
---|---|
date | Fri, 10 May 2013 18:48:57 +0800 |
parents | 40b48a3997a2 |
children | eb4ce68b6e5c |
comparison
equal
deleted
inserted
replaced
1102:1d7b3ebda27f | 1103:d8591b1c56cd |
---|---|
199 TRACE_ENTRY("%p", msg); | 199 TRACE_ENTRY("%p", msg); |
200 | 200 |
201 memset(msg, 0, sizeof(struct msg)); | 201 memset(msg, 0, sizeof(struct msg)); |
202 init_chain( &msg->msg_chain, MSG_MSG); | 202 init_chain( &msg->msg_chain, MSG_MSG); |
203 msg->msg_eyec = MSG_MSG_EYEC; | 203 msg->msg_eyec = MSG_MSG_EYEC; |
204 | |
205 fd_list_init(&msg->msg_pmdl.sentinel, NULL); | |
206 CHECK_POSIX_DO( pthread_mutex_init(&msg->msg_pmdl.lock, NULL), ); | |
204 } | 207 } |
205 | 208 |
206 | 209 |
207 /* Create a new AVP instance */ | 210 /* Create a new AVP instance */ |
208 int fd_msg_avp_new ( struct dict_object * model, int flags, struct avp ** avp ) | 211 int fd_msg_avp_new ( struct dict_object * model, int flags, struct avp ** avp ) |
1949 | 1952 |
1950 TRACE_ENTRY("%p %zd %p", buffer, buflen, msg); | 1953 TRACE_ENTRY("%p %zd %p", buffer, buflen, msg); |
1951 | 1954 |
1952 CHECK_PARAMS( buffer && *buffer && msg && (buflen >= GETMSGHDRSZ()) ); | 1955 CHECK_PARAMS( buffer && *buffer && msg && (buflen >= GETMSGHDRSZ()) ); |
1953 buf = *buffer; | 1956 buf = *buffer; |
1954 *buffer = NULL; | |
1955 | 1957 |
1956 if ( buf[0] != DIAMETER_VERSION) { | 1958 if ( buf[0] != DIAMETER_VERSION) { |
1957 TRACE_DEBUG(INFO, "Invalid version in message: %d (supported: %d)", buf[0], DIAMETER_VERSION); | 1959 TRACE_DEBUG(INFO, "Invalid version in message: %d (supported: %d)", buf[0], DIAMETER_VERSION); |
1958 free(buf); | |
1959 return EBADMSG; | 1960 return EBADMSG; |
1960 } | 1961 } |
1961 | 1962 |
1962 msglen = ntohl(*(uint32_t *)buf) & 0x00ffffff; | 1963 msglen = ntohl(*(uint32_t *)buf) & 0x00ffffff; |
1963 if ( buflen < msglen ) { | 1964 if ( buflen < msglen ) { |
1964 TRACE_DEBUG(INFO, "Truncated message (%zd / %d)", buflen, msglen ); | 1965 TRACE_DEBUG(INFO, "Truncated message (%zd / %d)", buflen, msglen ); |
1965 free(buf); | |
1966 return EBADMSG; | 1966 return EBADMSG; |
1967 } | 1967 } |
1968 | 1968 |
1969 /* Create a new object */ | 1969 /* Create a new object */ |
1970 CHECK_MALLOC_DO( new = malloc (sizeof(struct msg)), { free(buf); return ENOMEM; } ); | 1970 CHECK_MALLOC( new = malloc (sizeof(struct msg)) ); |
1971 | 1971 |
1972 /* Initialize the fields */ | 1972 /* Initialize the fields */ |
1973 init_msg(new); | 1973 init_msg(new); |
1974 | 1974 |
1975 /* Now read from the buffer */ | 1975 /* Now read from the buffer */ |
1981 | 1981 |
1982 new->msg_public.msg_appl = ntohl(*(uint32_t *)(buf+8)); | 1982 new->msg_public.msg_appl = ntohl(*(uint32_t *)(buf+8)); |
1983 new->msg_public.msg_hbhid = ntohl(*(uint32_t *)(buf+12)); | 1983 new->msg_public.msg_hbhid = ntohl(*(uint32_t *)(buf+12)); |
1984 new->msg_public.msg_eteid = ntohl(*(uint32_t *)(buf+16)); | 1984 new->msg_public.msg_eteid = ntohl(*(uint32_t *)(buf+16)); |
1985 | 1985 |
1986 new->msg_rawbuffer = buf; | |
1987 | |
1988 /* Parse the AVP list */ | 1986 /* Parse the AVP list */ |
1989 CHECK_FCT_DO( ret = parsebuf_list(buf + GETMSGHDRSZ(), buflen - GETMSGHDRSZ(), &new->msg_chain.children), { destroy_tree(_C(new)); return ret; } ); | 1987 CHECK_FCT_DO( ret = parsebuf_list(buf + GETMSGHDRSZ(), buflen - GETMSGHDRSZ(), &new->msg_chain.children), { destroy_tree(_C(new)); return ret; } ); |
1990 | 1988 |
1989 /* Parsing successful */ | |
1990 new->msg_rawbuffer = buf; | |
1991 *buffer = NULL; | |
1991 *msg = new; | 1992 *msg = new; |
1992 return 0; | 1993 return 0; |
1993 } | 1994 } |
1994 | 1995 |
1995 | 1996 |