cpd_config.c

Go to the documentation of this file.
00001 /*
00002  * $Id: cpd_config.c 346460 2009-11-14 05:06:47Z ssiano $
00003  *
00004  * This code is provided as is by Juniper Networks SDK Developer Support.
00005  * It is provided with no warranties or guarantees, and Juniper Networks
00006  * will not provide support or maintenance of this code in any fashion.
00007  * The code is provided only to help a developer better understand how
00008  * the SDK can be used.
00009  *
00010  * Copyright (c) 2007-2008, Juniper Networks, Inc.
00011  * All rights reserved.
00012  */
00013 
00023 #include <string.h>
00024 #include "cpd_config.h"
00025 #include "cpd_logging.h"
00026 
00027 /*** Constants ***/
00028 
00029 
00030 /*** Data structures: ***/
00031 
00032 static in_addr_t pfd_address;  
00033 static in_addr_t cpd_address;  
00034 static patroot root; 
00035 
00036 
00037 /*** STATIC/INTERNAL Functions ***/
00038 
00039 
00044 PATNODE_TO_STRUCT(data_entry, cpd_auth_user_t, node)
00045 
00046 
00047 /*** GLOBAL/EXTERNAL Functions ***/
00048 
00049 
00050 
00054 void
00055 init_config(void)
00056 {
00057     patricia_root_init(&root, FALSE, sizeof(in_addr_t), 0);
00058                    // root, is key ptr, key size, key offset
00059     
00060     cpd_address = 0;
00061     pfd_address = 0;
00062 }
00063 
00067 void
00068 clear_config(void)
00069 {
00070     cpd_auth_user_t * auth_user = NULL;
00071 
00072     while((auth_user = get_next_auth_user(NULL)) != NULL) {
00073 
00074         if (!patricia_delete(&root, &auth_user->node)) {
00075             LOG(LOG_ERR, "%s: patricia delete failed", __func__);
00076         }
00077 
00078         if(auth_user) {
00079             free(auth_user);
00080         }
00081     }
00082 }
00083 
00084 
00091 void
00092 add_auth_user_addr(in_addr_t addr)
00093 {
00094     cpd_auth_user_t * auth_user;
00095     
00096     auth_user = calloc(1, sizeof(cpd_auth_user_t));
00097     auth_user->address = addr; 
00098     
00099     /* add to data_root patricia tree */
00100     patricia_node_init_length(&auth_user->node, sizeof(in_addr_t));
00101 
00102     if (!patricia_add(&root, &auth_user->node)) {
00103         LOG(LOG_ERR, "%s: patricia_add failed", __func__);
00104         free(auth_user);
00105     }
00106 }
00107 
00108 
00115 void
00116 delete_auth_user_addr(in_addr_t addr)
00117 {
00118     patnode * node = NULL;
00119     cpd_auth_user_t * auth_user = NULL;
00120         
00121     node = patricia_get(&root, sizeof(in_addr_t), &addr);
00122 
00123     if (node == NULL) {
00124         LOG(LOG_NOTICE, "%s: called with a user's that is already not "
00125             "authorized", __func__);
00126         return;
00127     }
00128     
00129     auth_user = data_entry(node);
00130         
00131     if (!patricia_delete(&root, node)) {
00132         LOG(LOG_ERR, "%s: patricia delete failed", __func__);
00133     }
00134     
00135     if(auth_user) {
00136         free(auth_user);
00137     }
00138 }
00139 
00140 
00149 boolean
00150 is_auth_user(in_addr_t addr)
00151 {
00152     return (patricia_get(&root, sizeof(in_addr_t), &addr) != NULL);
00153 }
00154 
00165 cpd_auth_user_t * get_next_auth_user(cpd_auth_user_t * user)
00166 {
00167     return data_entry(patricia_find_next(&root, (user ? &(user->node) : NULL)));
00168 }
00169 
00170 
00177 in_addr_t
00178 get_pfd_address(void)
00179 {
00180     return pfd_address;
00181 }
00182 
00183 
00190 void
00191 set_pfd_address(in_addr_t addr)
00192 {
00193     pfd_address = addr;
00194 }
00195 
00196 
00203 in_addr_t
00204 get_cpd_address(void)
00205 {
00206     return cpd_address;
00207 }
00208 
00209 
00216 void
00217 set_cpd_address(in_addr_t addr)
00218 {
00219     cpd_address = addr;
00220 }
00221 

2007-2009 Juniper Networks, Inc. All rights reserved. The information contained herein is confidential information of Juniper Networks, Inc., and may not be used, disclosed, distributed, modified, or copied without the prior written consent of Juniper Networks, Inc. in an express license. This information is subject to change by Juniper Networks, Inc. Juniper Networks, the Juniper Networks logo, and JUNOS are registered trademarks of Juniper Networks, Inc. in the United States and other countries. All other trademarks, service marks, registered trademarks, or registered service marks are the property of their respective owners.
Generated on Sun May 30 20:26:53 2010 for SDK Your Net Corporation Policy Manager Example: Captive Portal Daemon (cpd) 1.0 by Doxygen 1.5.1