Navigation


Changeset 10:c5c99c73c2bf in freeDiameter for extensions/_sample/sample.c


Ignore:
Timestamp:
Sep 25, 2009, 4:12:08 PM (15 years ago)
Author:
Sebastien Decugis <sdecugis@nict.go.jp>
Branch:
default
Phase:
public
Message:

Added some extensions and functions in the daemon

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/_sample/sample.c

    r9 r10  
    4545static int sample_main(char * conffile)
    4646{
     47        /* The debug macro from main tree can be used the same way */
    4748        TRACE_ENTRY("%p", conffile);
    4849       
    49         fprintf(stdout, "I am extension " __FILE__ " running on host %s\n", fd_g_config->diam_id);
     50        /* This is how we access daemon's global vars */
     51        fprintf(stdout, "I am extension " __FILE__ " running on host %s.", fd_g_config->cnf_diamid);
    5052       
     53        /* The configuration file name is received in the conffile var. It's up to extension to parse it */
    5154        if (conffile) {
    5255                fprintf(stdout, "I should parse my configuration file there: %s\n", conffile);
     
    5558        }
    5659       
    57         /* Use the dictionary for test */
    58         fd_log_debug("Let's create that 'Example-AVP'...\n");
     60        /* Functions from the libfreediameter can also be used as demonstrated here: */
     61        TRACE_DEBUG(INFO, "Let's create that 'Example-AVP'...");
    5962        {
    6063                struct dict_object * origin_host_avp = NULL;
     
    6467                struct dict_avp_data example_avp_data = { 999999, 0, "Example-AVP", AVP_FLAG_VENDOR , 0, AVP_TYPE_GROUPED };
    6568
    66                 CHECK_FCT( fd_dict_search ( fd_g_config->g_dict, DICT_AVP, AVP_BY_NAME, "Origin-Host", &origin_host_avp, ENOENT));
    67                 CHECK_FCT( fd_dict_search ( fd_g_config->g_dict, DICT_AVP, AVP_BY_NAME, "Session-Id", &session_id_avp, ENOENT));
     69                CHECK_FCT( fd_dict_search ( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Origin-Host", &origin_host_avp, ENOENT));
     70                CHECK_FCT( fd_dict_search ( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Session-Id", &session_id_avp, ENOENT));
    6871               
    69                 CHECK_FCT( fd_dict_new ( fd_g_config->g_dict, DICT_AVP, &example_avp_data , NULL, &example_avp_avp ));
     72                CHECK_FCT( fd_dict_new ( fd_g_config->cnf_dict, DICT_AVP, &example_avp_data , NULL, &example_avp_avp ));
    7073               
    7174                rule_data.rule_avp = origin_host_avp;
    7275                rule_data.rule_min = 1;
    7376                rule_data.rule_max = 1;
    74                 CHECK_FCT( fd_dict_new ( fd_g_config->g_dict, DICT_RULE, &rule_data, example_avp_avp, NULL ));
     77                CHECK_FCT( fd_dict_new ( fd_g_config->cnf_dict, DICT_RULE, &rule_data, example_avp_avp, NULL ));
    7578               
    7679                rule_data.rule_avp = session_id_avp;
    7780                rule_data.rule_min = 1;
    7881                rule_data.rule_max = -1;
    79                 CHECK_FCT( fd_dict_new ( fd_g_config->g_dict, DICT_RULE, &rule_data, example_avp_avp, NULL ));
     82                CHECK_FCT( fd_dict_new ( fd_g_config->cnf_dict, DICT_RULE, &rule_data, example_avp_avp, NULL ));
     83               
     84                fd_dict_dump_object(example_avp_avp);
    8085        }
    81         fd_log_debug("'Example-AVP' created without error\n");
     86        TRACE_DEBUG(INFO, "'Example-AVP' created without error\n");
    8287       
     88        /* The initialization function returns an error code with the standard POSIX meaning (ENOMEM, and so on) */
    8389        return 0;
    8490}
     91
     92/* See file fini.c for an example of destructor */
Note: See TracChangeset for help on using the changeset viewer.