For definition, you would want to look into:
Definition in file diameter_api.h.
#include "diameter.h"
#include "utils.h"
Go to the source code of this file.
Defines | |
| #define | DP_TRANS_TIMEOUT 5 |
| Timeout for Diameter transactions (this is quite big, but increase in case that you have a slow peer). | |
| #define | AAACreateAndAddAVPToMessage(_msg_, _code_, _flags_, _vdr_, _data_, _len_) |
| Create and add an AVP to the message, by duplicating the storage space. | |
Functions | |
| AAATransaction * | AAACreateTransaction (AAAApplicationId app_id, AAACommandCode cmd_code) |
| Create a AAATransaction for the given request. | |
| int | AAADropTransaction (AAATransaction *trans) |
| Free the memory allocated for the AAATransaction. | |
| AAASessionId | AAACreateSession () |
| Creates a AAASessionId. | |
| int | AAADropSession (AAASessionId *s) |
| Deallocates the memory taken by a AAASessionId. | |
| int | AAAAddRequestHandler (AAARequestHandler_f *f, void *param) |
| Add a handler function for incoming requests. | |
| int | AAAAddResponseHandler (AAAResponseHandler_f *f, void *param) |
| Add a handler function for incoming responses. | |
| AAAReturnCode | AAASendMessage (AAAMessage *message, AAATransactionCallback_f *callback_f, void *callback_param) |
| Send a AAAMessage asynchronously. | |
| AAAReturnCode | AAASendMessageToPeer (AAAMessage *message, str *peer_id, AAATransactionCallback_f *callback_f, void *callback_param) |
| Send a AAAMessage asynchronously. | |
| AAAMessage * | AAASendRecvMessage (AAAMessage *msg) |
| Send a AAAMessage synchronously. | |
| AAAMessage * | AAASendRecvMessageToPeer (AAAMessage *msg, str *peer_id) |
| Send a AAAMessage synchronously. | |
| AAAMessage * | AAACreateRequest (AAAApplicationId app_id, AAACommandCode command_code, AAAMsgFlag flags, AAASessionId *sessId) |
| Create a Diameter Request. | |
| AAAMessage * | AAACreateResponse (AAAMessage *request) |
| Create a Diameter Response to a given Request. | |
| AAAMessage * | AAANewMessage (AAACommandCode commandCode, AAAApplicationId appId, AAASessionId *sessionId, AAAMessage *request) |
| Allocates a new AAAMessage. | |
| AAAReturnCode | AAAFreeAVPList (AAA_AVP_LIST *avpList) |
| Frees a AVP List and all the members. | |
| AAAReturnCode | AAAFreeMessage (AAAMessage **message) |
| Frees completely a message allocated through AAANewMessage(). | |
| AAAResultCode | AAASetMessageResultCode (AAAMessage *message, AAAResultCode resultCode) |
| Sets the proper result_code into the Result-Code AVP; ths avp must already exists into the reply messge. | |
| void | AAAPrintMessage (AAAMessage *msg) |
| print as debug all info contained by an aaa message + AVPs | |
| AAAReturnCode | AAABuildMsgBuffer (AAAMessage *msg) |
| This function encodes a AAAMessage to its network representation (encoder). | |
| AAAMessage * | AAATranslateMessage (unsigned char *source, unsigned int sourceLen, int attach_buf) |
| This function convert message from the network format to the AAAMessage structure (decoder). | |
| AAA_AVP * | AAACreateAVP (AAA_AVPCode code, AAA_AVPFlag flags, AAAVendorId vendorId, char *data, size_t length, AVPDataStatus data_status) |
| This function creates an AVP and returns a pointer to it. | |
| AAA_AVP * | AAACloneAVP (AAA_AVP *avp, unsigned char duplicate_data) |
| Duplicate a whole AAA_AVP. | |
| AAAReturnCode | AAAAddAVPToMessage (AAAMessage *msg, AAA_AVP *avp, AAA_AVP *position) |
| Insert the AVP avp into the avpList of a message, after a certain position. | |
| AAA_AVP * | AAAFindMatchingAVP (AAAMessage *msg, AAA_AVP *startAvp, AAA_AVPCode avpCode, AAAVendorId vendorId, AAASearchType searchType) |
| This function finds an AVP with matching code and vendor id. | |
| AAAReturnCode | AAARemoveAVPFromMessage (AAAMessage *msg, AAA_AVP *avp) |
| This function removes an AVP from a message. | |
| AAAReturnCode | AAAFreeAVP (AAA_AVP **avp) |
| The function frees the memory allocated to an AVP. | |
| AAA_AVP * | AAAGetFirstAVP (AAA_AVP_LIST *avpList) |
| This function returns the first AVP in the list. | |
| AAA_AVP * | AAAGetLastAVP (AAA_AVP_LIST *avpList) |
| This function returns the last AVP in the list. | |
| AAA_AVP * | AAAGetNextAVP (AAA_AVP *avp) |
| This function returns the next AVP in the list that this AVP was extracted from. | |
| AAA_AVP * | AAAGetPrevAVP (AAA_AVP *avp) |
| This function returns a the previous AVP in the list that this AVP was extracted from. | |
| char * | AAAConvertAVPToString (AAA_AVP *avp, char *dest, unsigned int destLen) |
| This function converts the data in the AVP to a format suitable for print, log or display. | |
| str | AAAGroupAVPS (AAA_AVP_LIST avps) |
| Groups a list of avps into a data buffer. | |
| AAA_AVP_LIST | AAAUngroupAVPS (str buf) |
| Ungroup from a data buffer a list of avps. | |
| AAA_AVP * | AAAFindMatchingAVPList (AAA_AVP_LIST avpList, AAA_AVP *startAvp, AAA_AVPCode avpCode, AAAVendorId vendorId, AAASearchType searchType) |
| Find an avp into a list of avps. | |
| void | AAAAddAVPToAVPList (AAA_AVP_LIST *list, AAA_AVP *avp) |
| Add an AVP to a list of AVPs. | |
| #define DP_TRANS_TIMEOUT 5 |
Timeout for Diameter transactions (this is quite big, but increase in case that you have a slow peer).
Definition at line 71 of file diameter_api.h.
Referenced by AAASendMessage(), AAASendMessageToPeer(), AAASendRecvMessage(), and AAASendRecvMessageToPeer().
| #define AAACreateAndAddAVPToMessage | ( | _msg_, | |||
| _code_, | |||||
| _flags_, | |||||
| _vdr_, | |||||
| _data_, | |||||
| _len_ | ) |
Value:
( AAAAddAVPToMessage(_msg_, \ AAACreateAVP(_code_,_flags_,_vdr_,_data_,_len_, AVP_DUPLICATE_DATA),\ (_msg_)->avpList.tail) )
Definition at line 148 of file diameter_api.h.
Referenced by I_Snd_CER(), Snd_CE_add_applications(), Snd_CEA(), Snd_DPR(), and Snd_DWA().
| AAATransaction* AAACreateTransaction | ( | AAAApplicationId | app_id, | |
| AAACommandCode | cmd_code | |||
| ) |
Create a AAATransaction for the given request.
| app_id | - id of the request's application | |
| cmd_code | - request's code |
Definition at line 73 of file diameter_api.c.
References _AAATransaction::application_id, and _AAATransaction::command_code.
Referenced by load_cdp().
00074 { 00075 AAATransaction *t; 00076 t = shm_malloc(sizeof(AAATransaction)); 00077 if (!t) return 0; 00078 memset(t,0,sizeof(AAATransaction)); 00079 t->application_id=app_id; 00080 t->command_code=cmd_code; 00081 return t; 00082 }
| int AAADropTransaction | ( | AAATransaction * | trans | ) |
Free the memory allocated for the AAATransaction.
| trans | - the AAATransaction to be deallocated |
Definition at line 89 of file diameter_api.c.
Referenced by load_cdp().
00090 { 00091 if (!trans) return 0; 00092 // LOG(L_ERR,"\nCALLED HERE %d %d\n",trans->done,trans->with_callback); 00093 shm_free(trans); 00094 return 1; 00095 }
| AAASessionId AAACreateSession | ( | ) |
Creates a AAASessionId.
Definition at line 166 of file session.c.
References generate_sessionID().
Referenced by load_cdp().
00167 { 00168 AAASessionId sID={0,0}; 00169 00170 /* generates a new session-ID - the extra pad is used to append to 00171 * session-ID the hash-code and label of the session ".XXXXXXXX.XXXXXXXX"*/ 00172 if (generate_sessionID( &(sID), 0 )!=1) 00173 goto error; 00174 00175 return sID; 00176 error: 00177 LOG(L_ERR,"ERROR:AAACreateSession(): Error on new session generation\n"); 00178 return sID; 00179 }
| int AAADropSession | ( | AAASessionId * | s | ) |
Deallocates the memory taken by a AAASessionId.
| s | - the AAASessionId to be deallocated |
Definition at line 185 of file session.c.
References AAA_ERR_SUCCESS.
Referenced by load_cdp().
00186 { 00187 if (s->s) shm_free(s->s); 00188 s->s =0; 00189 s->len=0; 00190 return AAA_ERR_SUCCESS; 00191 }
| int AAAAddRequestHandler | ( | AAARequestHandler_f * | f, | |
| void * | param | |||
| ) |
Add a handler function for incoming requests.
| f | - the callback function | |
| param | - generic parameter to be used when calling the callback functions |
Definition at line 109 of file diameter_api.c.
References handler_t::handler, handlers, handlers_lock, handler_list_t::head, handler_t::next, handler_t::param, handler_t::prev, REQUEST_HANDLER, handler_t::requestHandler, handler_list_t::tail, and handler_t::type.
Referenced by load_cdp().
00110 { 00111 handler *h = shm_malloc(sizeof(handler)); 00112 if (!h) { 00113 LOG(L_ERR,"ERR:AAAAddRequestHandler: error allocating %d bytes in shm\n", 00114 sizeof(handler)); 00115 return 0; 00116 } 00117 h->type = REQUEST_HANDLER; 00118 h->handler.requestHandler = f; 00119 h->param = param; 00120 h->next = 0; 00121 lock_get(handlers_lock); 00122 h->prev = handlers->tail; 00123 if (handlers->tail) handlers->tail->next = h; 00124 handlers->tail = h; 00125 if (!handlers->head) handlers->head = h; 00126 lock_release(handlers_lock); 00127 return 1; 00128 }
| int AAAAddResponseHandler | ( | AAAResponseHandler_f * | f, | |
| void * | param | |||
| ) |
Add a handler function for incoming responses.
| f | - the callback function | |
| param | - generic parameter to be used when calling the callback functions |
Definition at line 136 of file diameter_api.c.
References handler_t::handler, handlers, handlers_lock, handler_list_t::head, handler_t::next, handler_t::param, handler_t::prev, RESPONSE_HANDLER, handler_t::responseHandler, handler_list_t::tail, and handler_t::type.
Referenced by load_cdp().
00137 { 00138 handler *h = shm_malloc(sizeof(handler)); 00139 if (!h) { 00140 LOG(L_ERR,"ERR:AAAAddResponseHandler: error allocating %d bytes in shm\n", 00141 sizeof(handler)); 00142 return 0; 00143 } 00144 h->type = RESPONSE_HANDLER; 00145 h->handler.responseHandler = f; 00146 h->param = param; 00147 h->next = 0; 00148 lock_get(handlers_lock); 00149 h->prev = handlers->tail; 00150 if (handlers->tail) handlers->tail->next = h; 00151 handlers->tail = h; 00152 if (!handlers->head) handlers->head = h; 00153 lock_release(handlers_lock); 00154 return 1; 00155 }
| AAAReturnCode AAASendMessage | ( | AAAMessage * | message, | |
| AAATransactionCallback_f * | callback_f, | |||
| void * | callback_param | |||
| ) |
Send a AAAMessage asynchronously.
When the response is received, the callback_f(callback_param,...) is called.
| message | - the request to be sent | |
| peer_id | - FQDN of the peer to send | |
| callback_f | - callback to be called on transactional response or transaction timeout | |
| callback_param | - generic parameter to call the transactional callback function with |
Definition at line 170 of file diameter_api.c.
References AAAFreeMessage(), add_trans(), DP_TRANS_TIMEOUT, _peer_t::fqdn, get_routing_peer(), I_Open, is_req, peer_send_msg(), R_Open, and _peer_t::state.
Referenced by load_cdp().
00174 { 00175 peer *p; 00176 p = get_routing_peer(message); 00177 if (!p) { 00178 LOG(L_ERR,"ERROR:AAASendMessage(): Can't find a suitable connected peer in the routing table.\n"); 00179 goto error; 00180 } 00181 if (p->state!=I_Open && p->state!=R_Open){ 00182 LOG(L_ERR,"ERROR:AAASendMessage(): Peer not connected to %.*s\n",p->fqdn.len,p->fqdn.s); 00183 goto error; 00184 } 00185 /* only add transaction following when required */ 00186 if (callback_f){ 00187 if (is_req(message)) 00188 add_trans(message,callback_f,callback_param,DP_TRANS_TIMEOUT,1); 00189 else 00190 LOG(L_ERR,"ERROR:AAASendMessage(): can't add transaction callback for answer.\n"); 00191 } 00192 00193 if (!peer_send_msg(p,message)) 00194 goto error; 00195 00196 return 1; 00197 error: 00198 AAAFreeMessage(&message); 00199 return 0; 00200 }
| AAAReturnCode AAASendMessageToPeer | ( | AAAMessage * | message, | |
| str * | peer_id, | |||
| AAATransactionCallback_f * | callback_f, | |||
| void * | callback_param | |||
| ) |
Send a AAAMessage asynchronously.
When the response is received, the callback_f(callback_param,...) is called.
| message | - the request to be sent | |
| peer_id | - FQDN of the peer to send | |
| callback_f | - callback to be called on transactional response or transaction timeout | |
| callback_param | - generic parameter to call the transactional callback function with |
Definition at line 212 of file diameter_api.c.
References AAAFreeMessage(), add_trans(), DP_TRANS_TIMEOUT, get_peer_by_fqdn(), I_Open, is_req, peer_send_msg(), R_Open, and _peer_t::state.
Referenced by load_cdp().
00217 { 00218 peer *p; 00219 p = get_peer_by_fqdn(peer_id); 00220 if (!p) { 00221 LOG(L_ERR,"ERROR:AAASendMessageToPeer(): Peer unknown %.*s\n",peer_id->len,peer_id->s); 00222 goto error; 00223 } 00224 if (p->state!=I_Open && p->state!=R_Open){ 00225 LOG(L_ERR,"ERROR:AAASendMessageToPeer(): Peer not connected to %.*s\n",peer_id->len,peer_id->s); 00226 goto error; 00227 } 00228 /* only add transaction following when required */ 00229 if (callback_f){ 00230 if (is_req(message)) 00231 add_trans(message,callback_f,callback_param,DP_TRANS_TIMEOUT,1); 00232 else 00233 LOG(L_ERR,"ERROR:AAASendMessageToPeer(): can't add transaction callback for answer.\n"); 00234 } 00235 00236 if (!peer_send_msg(p,message)) 00237 goto error; 00238 00239 return 1; 00240 error: 00241 AAAFreeMessage(&message); 00242 return 0; 00243 }
| AAAMessage* AAASendRecvMessage | ( | AAAMessage * | message | ) |
Send a AAAMessage synchronously.
This blocks until a response is received or a transactional time-out happens.
| message | - the request to be sent | |
| peer_id | - FQDN of the peer to send |
Definition at line 271 of file diameter_api.c.
References AAAFreeMessage(), add_trans(), _cdp_trans_t::ans, DP_TRANS_TIMEOUT, _peer_t::fqdn, free_trans(), get_routing_peer(), I_Open, is_req, peer_send_msg(), R_Open, sendrecv_cb(), and _peer_t::state.
Referenced by load_cdp().
00272 { 00273 peer *p; 00274 gen_lock_t *lock; 00275 cdp_trans_t *t; 00276 AAAMessage *ans; 00277 00278 p = get_routing_peer(message); 00279 if (!p) { 00280 LOG(L_ERR,"ERROR:AAASendRecvMessage(): Can't find a suitable connected peer in the routing table.\n"); 00281 goto error; 00282 } 00283 if (p->state!=I_Open && p->state!=R_Open){ 00284 LOG(L_ERR,"ERROR:AAASendRecvMessage(): Peer not connected to %.*s\n",p->fqdn.len,p->fqdn.s); 00285 goto error; 00286 } 00287 00288 00289 if (is_req(message)){ 00290 lock = lock_alloc(); 00291 lock = lock_init(lock); 00292 lock_get(lock); 00293 t = add_trans(message,sendrecv_cb,(void*)lock,DP_TRANS_TIMEOUT,0); 00294 00295 if (!peer_send_msg(p,message)) { 00296 lock_destroy(lock); 00297 lock_dealloc((void*)lock); 00298 goto error; 00299 } 00300 00301 /* block until callback is executed */ 00302 lock_get(lock); 00303 lock_destroy(lock); 00304 lock_dealloc((void*)lock); 00305 ans = t->ans; 00306 free_trans(t); 00307 return ans; 00308 } 00309 else 00310 { 00311 LOG(L_ERR,"ERROR:AAASendRecvMessage(): can't add wait for answer to answer.\n"); 00312 goto error; 00313 } 00314 00315 00316 error: 00317 AAAFreeMessage(&message); 00318 return 0; 00319 }
| AAAMessage* AAASendRecvMessageToPeer | ( | AAAMessage * | message, | |
| str * | peer_id | |||
| ) |
Send a AAAMessage synchronously.
This blocks until a response is received or a transactional time-out happens.
| message | - the request to be sent | |
| peer_id | - FQDN of the peer to send |
Definition at line 330 of file diameter_api.c.
References AAAFreeMessage(), add_trans(), _cdp_trans_t::ans, DP_TRANS_TIMEOUT, free_trans(), get_peer_by_fqdn(), I_Open, is_req, peer_send_msg(), R_Open, sendrecv_cb(), and _peer_t::state.
Referenced by load_cdp().
00331 { 00332 peer *p; 00333 gen_lock_t *lock; 00334 cdp_trans_t *t; 00335 AAAMessage *ans; 00336 00337 p = get_peer_by_fqdn(peer_id); 00338 if (!p) { 00339 LOG(L_ERR,"ERROR:AAASendRecvMessageToPeer(): Peer unknown %.*s\n",peer_id->len,peer_id->s); 00340 goto error; 00341 } 00342 if (p->state!=I_Open && p->state!=R_Open){ 00343 LOG(L_ERR,"ERROR:AAASendRecvMessageToPeer(): Peer not connected to %.*s\n",peer_id->len,peer_id->s); 00344 goto error; 00345 } 00346 00347 00348 if (is_req(message)){ 00349 lock = lock_alloc(); 00350 lock = lock_init(lock); 00351 lock_get(lock); 00352 t = add_trans(message,sendrecv_cb,(void*)lock,DP_TRANS_TIMEOUT,0); 00353 00354 if (!peer_send_msg(p,message)) { 00355 lock_destroy(lock); 00356 lock_dealloc((void*)lock); 00357 goto error; 00358 } 00359 00360 /* block until callback is executed */ 00361 lock_get(lock); 00362 lock_destroy(lock); 00363 lock_dealloc((void*)lock); 00364 ans = t->ans; 00365 free_trans(t); 00366 return ans; 00367 } 00368 else 00369 { 00370 LOG(L_ERR,"ERROR:AAASendRecvMessageToPeer(): can't add wait for answer to answer.\n"); 00371 goto error; 00372 } 00373 00374 00375 error: 00376 AAAFreeMessage(&message); 00377 return 0; 00378 }
| AAAMessage* AAACreateRequest | ( | AAAApplicationId | app_id, | |
| AAACommandCode | command_code, | |||
| AAAMsgFlag | flags, | |||
| AAASessionId * | sessId | |||
| ) |
Create a Diameter Request.
| app_id | - application id to be set | |
| command_code | - the command code for this message | |
| flags | - flags to be set | |
| sessId | - session id to be set |
Definition at line 323 of file diameter_msg.c.
References AAANewMessage(), _message_t::endtoendId, _message_t::flags, _message_t::hopbyhopId, next_endtoend(), and next_hopbyhop().
Referenced by load_cdp().
00327 { 00328 AAAMessage *msg; 00329 msg = AAANewMessage(command_code,app_id,sessId,0); 00330 if (!msg) return 0; 00331 msg->hopbyhopId = next_hopbyhop(); 00332 msg->endtoendId = next_endtoend(); 00333 msg->flags |= flags; 00334 return msg; 00335 }
| AAAMessage* AAACreateResponse | ( | AAAMessage * | request | ) |
Create a Diameter Response to a given Request.
| request | - the request that this response is for |
Definition at line 342 of file diameter_msg.c.
References AAANewMessage(), _message_t::applicationId, _message_t::commandCode, and _message_t::sId.
Referenced by load_cdp().
00343 { 00344 AAAMessage *msg; 00345 msg = AAANewMessage(request->commandCode,request->applicationId,request->sId,request); 00346 00347 return msg; 00348 }
| AAAMessage* AAANewMessage | ( | AAACommandCode | commandCode, | |
| AAAApplicationId | applicationId, | |||
| AAASessionId * | sessionId, | |||
| AAAMessage * | request | |||
| ) |
Allocates a new AAAMessage.
| commandCode | - the command code for this message | |
| applicationId | - application id to be set | |
| sessionId | - session id to be set | |
| request | - if you want to create a response, put the request here. If you want a request, call with NULL |
Definition at line 169 of file diameter_msg.c.
References AAA_AVP_FLAG_MANDATORY, AAA_ERR_SUCCESS, AAA_FORWARD_SEARCH, AAAAddAVPToMessage(), AAACloneAVP(), AAACreateAVP(), AAAFindMatchingAVP(), AAAFreeAVP(), AAAFreeMessage(), _message_t::applicationId, AVP_Destination_Host, AVP_Destination_Realm, AVP_DUPLICATE_DATA, AVP_Origin_Host, AVP_Origin_Realm, _message_t::avpList, _message_t::commandCode, config, avp::data, _message_t::endtoendId, _message_t::flags, dp_config::fqdn, _avp_list_t::head, _message_t::hopbyhopId, _message_t::in_peer, _message_t::orig_host, _message_t::orig_realm, dp_config::realm, _message_t::res_code, _message_t::sessionId, _message_t::sId, and _avp_list_t::tail.
Referenced by AAACreateRequest(), AAACreateResponse(), I_Snd_CER(), Snd_CEA(), Snd_DPA(), Snd_DPR(), Snd_DWA(), and Snd_DWR().
00174 { 00175 AAAMessage *msg; 00176 AAA_AVP *avp; 00177 AAA_AVP *avp_t; 00178 #if 0 00179 unsigned int code; 00180 #endif 00181 str dest_host={"?",1}; 00182 str dest_realm={"?",1}; 00183 00184 msg = 0; 00185 00186 if (!sessionId||!sessionId->s) { 00187 if (request && request->sessionId){ 00188 /* copy old session id */ 00189 avp = request->sessionId; 00190 if (avp) { 00191 sessionId = &(avp->data); 00192 } 00193 }else{ 00194 //because of diameter base messages etc 00195 // LOG(L_ERR,"ERROR:AAANewMessage: param session-ID received null and it's a request!!\n"); 00196 // goto error; 00197 } 00198 } 00199 00200 /* allocated a new AAAMessage structure and set it to 0 */ 00201 msg = (AAAMessage*)shm_malloc(sizeof(AAAMessage)); 00202 if (!msg) { 00203 LOG(L_ERR,"ERROR:AAANewMessage: no more free memory!!\n"); 00204 goto error; 00205 } 00206 memset(msg,0,sizeof(AAAMessage)); 00207 00208 /* command code */ 00209 msg->commandCode = commandCode; 00210 /* application ID */ 00211 msg->applicationId = applicationId; 00212 00213 /* add session ID */ 00214 if (sessionId){ 00215 avp = AAACreateAVP( 263, 0, 0, sessionId->s, sessionId->len, 00216 AVP_DUPLICATE_DATA); 00217 if ( !avp || AAAAddAVPToMessage(msg,avp,0)!=AAA_ERR_SUCCESS) { 00218 LOG(L_ERR,"ERROR:AAANewMessage: cannot create/add Session-Id avp\n"); 00219 if (avp) AAAFreeAVP( &avp ); 00220 goto error; 00221 } 00222 msg->sessionId = avp; 00223 } 00224 00225 00226 /* add origin host AVP */ 00227 /* changed by cristian to comply with rfc3588: 00228 * 6.3. Origin-Host AVP 00229 * 00230 * The Origin-Host AVP (AVP Code 264) is of type 00231 * DiameterIdentity... */ 00232 avp = AAACreateAVP( 264, 0, 0, config->fqdn.s, config->fqdn.len, 00233 AVP_DUPLICATE_DATA); 00234 if (!avp||AAAAddAVPToMessage(msg,avp,msg->avpList.tail)!=AAA_ERR_SUCCESS) { 00235 LOG(L_ERR,"ERROR:AAANewMessage: cannot create/add Origin-Host avp\n"); 00236 if (avp) AAAFreeAVP( &avp ); 00237 goto error; 00238 } 00239 msg->orig_host = avp; 00240 /* add origin realm AVP */ 00241 avp = AAACreateAVP( 296, 0, 0, config->realm.s, config->realm.len, 00242 AVP_DUPLICATE_DATA); 00243 if (!avp||AAAAddAVPToMessage(msg,avp,msg->avpList.tail)!=AAA_ERR_SUCCESS) { 00244 LOG(L_ERR,"ERROR:AAANewMessage: cannot create/add Origin-Realm avp\n"); 00245 if (avp) AAAFreeAVP( &avp ); 00246 goto error; 00247 } 00248 msg->orig_realm = avp; 00249 00250 if (!request) { 00251 /* it's a new request -> set the flag */ 00252 msg->flags = 0x80; 00253 /* keep track of the session -> SendMessage will need it! */ 00254 msg->sId = sessionId; 00255 } else { 00256 /* it'a an answer -> it will have the same session Id */ 00257 msg->sId = request->sId; 00258 /* link the incoming peer to the answer */ 00259 msg->in_peer = request->in_peer; 00260 /* set the P flag as in request */ 00261 msg->flags |= request->flags&0x40; 00262 00263 msg->endtoendId = request->endtoendId; 00264 msg->hopbyhopId = request->hopbyhopId; 00265 00266 /* Mirror the old originhost/realm to destinationhost/realm*/ 00267 avp = AAAFindMatchingAVP(request,0,AVP_Origin_Host,0,0); 00268 if (avp) dest_host = avp->data; 00269 /* add destination host and destination realm */ 00270 avp = AAACreateAVP(AVP_Destination_Host,AAA_AVP_FLAG_MANDATORY,0, 00271 dest_host.s,dest_host.len,AVP_DUPLICATE_DATA); 00272 if (!avp) { 00273 LOG(L_ERR,"ERR:AAANewMessage: Failed creating Destination Host avp\n"); 00274 return 0; 00275 } 00276 if (AAAAddAVPToMessage(msg,avp,msg->avpList.tail)!=AAA_ERR_SUCCESS) { 00277 LOG(L_ERR,"ERR:AAANewMessage: Failed adding Destination Host avp to message\n"); 00278 AAAFreeAVP(&avp); 00279 return 0; 00280 } 00281 avp = AAAFindMatchingAVP(request,0,AVP_Origin_Realm,0,0); 00282 if (avp) dest_realm = avp->data; 00283 00284 avp = AAACreateAVP(AVP_Destination_Realm,AAA_AVP_FLAG_MANDATORY,0, 00285 dest_realm.s,dest_realm.len,AVP_DUPLICATE_DATA); 00286 if (!avp) { 00287 LOG(L_ERR,"ERR:AAANewMessage: Failed creating Destination Realm avp\n"); 00288 return 0; 00289 } 00290 if (AAAAddAVPToMessage(msg,avp,msg->avpList.tail)!=AAA_ERR_SUCCESS) { 00291 LOG(L_ERR,"ERR:AAANewMessage: Failed adding Destination Realm avp to message\n"); 00292 AAAFreeAVP(&avp); 00293 return 0; 00294 } 00295 00296 00297 msg->res_code=0; 00298 /* mirror all the proxy-info avp in the same order */ 00299 avp_t = request->avpList.head; 00300 while ( (avp_t=AAAFindMatchingAVP 00301 (request,avp_t,284,0,AAA_FORWARD_SEARCH))!=0 ) { 00302 if ( (avp=AAACloneAVP(avp_t,1))==0 || AAAAddAVPToMessage( msg, avp, 00303 msg->avpList.tail)!=AAA_ERR_SUCCESS ) 00304 goto error; 00305 } 00306 } 00307 00308 return msg; 00309 error: 00310 LOG(L_ERR,"ERROR:AAANewMessage: failed to create a new AAA message!\n"); 00311 AAAFreeMessage(&msg); 00312 return 0; 00313 }
| AAAReturnCode AAAFreeAVPList | ( | AAA_AVP_LIST * | avpList | ) |
Frees a AVP List and all the members.
| avpList | - list to be freed |
Definition at line 356 of file diameter_msg.c.
References AAA_ERR_SUCCESS, AAAFreeAVP(), _avp_list_t::head, avp::next, and _avp_list_t::tail.
Referenced by AAAFreeMessage(), get_routing_peer(), load_cdp(), Process_CER(), save_peer_applications(), and Snd_CE_add_applications().
00357 { 00358 AAA_AVP *avp_t; 00359 AAA_AVP *avp; 00360 /* free the avp list */ 00361 avp = avpList->head; 00362 while (avp) { 00363 avp_t = avp; 00364 avp = avp->next; 00365 /*free the avp*/ 00366 AAAFreeAVP(&avp_t); 00367 } 00368 avpList->head = 0; 00369 avpList->tail = 0; 00370 return AAA_ERR_SUCCESS; 00371 }
| AAAReturnCode AAAFreeMessage | ( | AAAMessage ** | msg | ) |
Frees completely a message allocated through AAANewMessage().
| msg | - pointer to the pointer containing the message. |
Definition at line 378 of file diameter_msg.c.
References AAA_ERR_SUCCESS, AAAFreeAVPList(), and _message_t::commandCode.
Referenced by AAANewMessage(), AAASendMessage(), AAASendMessageToPeer(), AAASendRecvMessage(), AAASendRecvMessageToPeer(), AAATranslateMessage(), load_cdp(), peer_send(), Process_CEA(), Process_DWA(), Rcv_Process(), receive_message(), select_recv(), Snd_CEA(), Snd_DPA(), Snd_DWA(), worker_destroy(), and worker_process().
00379 { 00380 LOG(L_DBG,"DBG:AAAFreeMessage: Freeing message (%p) %d\n",*msg,(*msg)->commandCode); 00381 /* param check */ 00382 if (!msg || !(*msg)) 00383 goto done; 00384 00385 /* free the avp list */ 00386 AAAFreeAVPList(&((*msg)->avpList)); 00387 00388 /* free the buffer (if any) */ 00389 if ( (*msg)->buf.s ) 00390 shm_free( (*msg)->buf.s ); 00391 00392 /* free the AAA msg */ 00393 shm_free(*msg); 00394 *msg = 0; 00395 00396 done: 00397 return AAA_ERR_SUCCESS; 00398 }
| AAAResultCode AAASetMessageResultCode | ( | AAAMessage * | message, | |
| AAAResultCode | resultCode | |||
| ) |
Sets the proper result_code into the Result-Code AVP; ths avp must already exists into the reply messge.
| message | - the message to set the Result-Code to | |
| resultCode | - code to set as result |
Definition at line 407 of file diameter_msg.c.
References AAA_ERR_FAILURE, AAA_ERR_SUCCESS, avp::data, is_req, and _message_t::res_code.