00001 /* 00002 * $Id: cr_carrier.h 5189 2008-11-12 15:53:01Z henningw $ 00003 * 00004 * Copyright (C) 2007-2008 1&1 Internet AG 00005 * 00006 * This file is part of Kamailio, a free SIP server. 00007 * 00008 * Kamailio is free software; you can redistribute it and/or modify 00009 * it under the terms of the GNU General Public License as published by 00010 * the Free Software Foundation; either version 2 of the License, or 00011 * (at your option) any later version 00012 * 00013 * Kamailio is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU General Public License 00019 * along with this program; if not, write to the Free Software 00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00021 */ 00022 00023 /** 00024 * \file cr_carrier.h 00025 * \brief Contains the functions to manage carrier data. 00026 * \ingroup carrierroute 00027 * - Module; \ref carrierroute 00028 */ 00029 00030 #ifndef CR_CARRIER_H 00031 #define CR_CARRIER_H 00032 00033 #include <sys/types.h> 00034 #include "../../str.h" 00035 00036 00037 /** 00038 * The struct for a carrier. 00039 */ 00040 struct carrier_data_t { 00041 int id; /*!< id of the carrier */ 00042 str * name; /*!< name of the carrier. This points to the name in carrier_map to avoid duplication. */ 00043 struct domain_data_t ** domains; /*!< array of routing domains */ 00044 size_t domain_num; /*!< number of routing domains */ 00045 size_t first_empty_domain; /*!< the index of the first empty entry in domains */ 00046 }; 00047 00048 00049 /** 00050 * Create a new carrier_data struct in shared memory and set it up. 00051 * 00052 * @param carrier_id id of carrier 00053 * @param carrier_name pointer to the name of the carrier 00054 * @param domains number of domains for that carrier 00055 * 00056 * @return a pointer to the newly allocated carrier data or NULL on 00057 * error, in which case it LOGs an error message. 00058 */ 00059 struct carrier_data_t * create_carrier_data(int carrier_id, str *carrier_name, int domains); 00060 00061 00062 /** 00063 * Destroys the given carrier and frees the used memory. 00064 * 00065 * @param carrier_data the structure to be destroyed. 00066 */ 00067 void destroy_carrier_data(struct carrier_data_t *carrier_data); 00068 00069 00070 /** 00071 * Adds a domain_data struct to the given carrier data structure at the given index. 00072 * Other etries are moved one position up to make space for the new one. 00073 * 00074 * @param carrier_data the carrier data struct where domain_data should be inserted 00075 * @param domain_data the domain data struct to be inserted 00076 * @param index the index where to insert the domain_data structure in the domain array 00077 * 00078 * @return 0 on success, -1 on failure 00079 */ 00080 int add_domain_data(struct carrier_data_t * carrier_data, struct domain_data_t * domain_data, int index); 00081 00082 00083 /** 00084 * Returns the domain data for the given id by doing a binary search. 00085 * @note The domain array must be sorted! 00086 * 00087 * @param carrier_data carrier data to be searched 00088 * @param domain_id the id of desired domain 00089 * 00090 * @return a pointer to the desired domain data, NULL if not found. 00091 */ 00092 struct domain_data_t *get_domain_data(struct carrier_data_t * carrier_data, int domain_id); 00093 00094 00095 /** 00096 * Compares the IDs of two carrier data structures. 00097 * A NULL pointer is always greater than any ID. 00098 * 00099 * @return -1 if v1 < v2, 0 if v1 == v2, 1 if v1 > v2 00100 */ 00101 int compare_carrier_data(const void *v1, const void *v2); 00102 00103 00104 #endif
1.5.6