comparison libfdproto/messages.c @ 992:80584f0e851a

Copy by default the Proxy-Info AVP included in requests into the answers. Use MSGFL_ANSW_NOPROXYINFO to ignore. This code has not been tested yet.
author Sebastien Decugis <sdecugis@freediameter.net>
date Sun, 17 Mar 2013 16:22:32 +0100
parents b90cb4c07160
children 2016a0c46bda
comparison
equal deleted inserted replaced
991:9c7d6b3cb90e 992:80584f0e851a
298 /* The new object is ready, return */ 298 /* The new object is ready, return */
299 *msg = new; 299 *msg = new;
300 return 0; 300 return 0;
301 } 301 }
302 302
303 static int bufferize_avp(unsigned char * buffer, size_t buflen, size_t * offset, struct avp * avp);
304 static int parsebuf_list(unsigned char * buf, size_t buflen, struct fd_list * head);
305
303 /* Create answer from a request */ 306 /* Create answer from a request */
304 int fd_msg_new_answer_from_req ( struct dictionary * dict, struct msg ** msg, int flags ) 307 int fd_msg_new_answer_from_req ( struct dictionary * dict, struct msg ** msg, int flags )
305 { 308 {
306 struct dict_object * model = NULL; 309 struct dict_object * model = NULL;
307 struct msg *qry, *ans; 310 struct msg *qry, *ans;
357 CHECK_FCT( fd_msg_avp_add( ans, MSG_BRW_FIRST_CHILD, avp ) ); 360 CHECK_FCT( fd_msg_avp_add( ans, MSG_BRW_FIRST_CHILD, avp ) );
358 ans->msg_sess = sess; 361 ans->msg_sess = sess;
359 CHECK_FCT( fd_sess_ref_msg(sess) ); 362 CHECK_FCT( fd_sess_ref_msg(sess) );
360 } 363 }
361 364
365 /* Add all Proxy-Info AVPs from the query if any */
366 if (! (flags & MSGFL_ANSW_NOPROXYINFO)) {
367 struct avp * avp;
368 CHECK_FCT( fd_msg_browse(qry, MSG_BRW_FIRST_CHILD, &avp, NULL) );
369 while (avp) {
370 if ( (avp->avp_public.avp_code == AC_PROXY_INFO)
371 && (avp->avp_public.avp_vendor == 0) ) {
372 /* We found a Proxy-Info, need to duplicate it in the answer */
373
374 /* In order to avoid dealing with all different possibilities of states, we just create a buffer then parse it */
375 unsigned char * buf = NULL;
376 size_t offset = 0;
377
378 CHECK_FCT( fd_msg_update_length(avp) );
379 CHECK_MALLOC( buf = malloc(avp->avp_public.avp_len) );
380 CHECK_FCT( bufferize_avp(buf, avp->avp_public.avp_len, &offset, avp) );
381
382 /* Now we directly parse this buffer into the new message list */
383 CHECK_FCT( parsebuf_list(buf, avp->avp_public.avp_len, &ans->msg_chain.children) );
384
385 /* Done for this AVP */
386 free(buf);
387 }
388 /* move to next AVP in the message, we can have several Proxy-Info instances */
389 CHECK_FCT( fd_msg_browse(avp, MSG_BRW_NEXT, &avp, NULL) );
390 }
391 }
392
362 /* associate with query */ 393 /* associate with query */
363 ans->msg_query = qry; 394 ans->msg_query = qry;
364 qry->msg_associated = 1; 395 qry->msg_associated = 1;
365 396
366 /* Done */ 397 /* Done */
"Welcome to our mercurial repository"