00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 static int getudef(struct udef_chans *ul, char *name)
00031 {
00032 int val = 0;
00033
00034 for (; ul; ul = ul->next)
00035 if (!strcasecmp(ul->chan, name)) {
00036 val = ul->value;
00037 break;
00038 }
00039 return val;
00040 }
00041
00042 static int ngetudef(char *name, char *chan)
00043 {
00044 struct udef_struct *l;
00045 struct udef_chans *ll;
00046
00047 for (l = udef; l; l = l->next)
00048 if (!strcasecmp(l->name, name)) {
00049 for (ll = l->values; ll; ll = ll->next)
00050 if (!strcasecmp(ll->chan, chan))
00051 return ll->value;
00052 break;
00053 }
00054 return 0;
00055 }
00056
00057 static void setudef(struct udef_struct *us, char *name, int value)
00058 {
00059 struct udef_chans *ul, *ul_last = NULL;
00060
00061 for (ul = us->values; ul; ul_last = ul, ul = ul->next)
00062 if (!strcasecmp(ul->chan, name)) {
00063 ul->value = value;
00064 return;
00065 }
00066
00067 ul = malloc(sizeof(struct udef_chans));
00068 ul->chan = strdup(name);
00069 ul->value = value;
00070 ul->next = NULL;
00071 if (ul_last)
00072 ul_last->next = ul;
00073 else
00074 us->values = ul;
00075 }
00076
00077 static void initudef(int type, char *name, int defined)
00078 {
00079 struct udef_struct *ul, *ul_last = NULL;
00080
00081 if (strlen(name) < 1)
00082 return;
00083
00084 for (ul = udef; ul; ul_last = ul, ul = ul->next)
00085 if (ul->name && !strcasecmp(ul->name, name)) {
00086 if (defined) {
00087 putlog(LOG_DEBUG, "*", "UDEF: %s defined", ul->name);
00088 ul->defined = 1;
00089 }
00090 return;
00091 }
00092
00093 putlog(LOG_DEBUG, "*", "Creating %s (type %d)", name, type);
00094 ul = malloc(sizeof(struct udef_struct));
00095 ul->name = strdup(name);
00096 if (defined)
00097 ul->defined = 1;
00098 else
00099 ul->defined = 0;
00100 ul->type = type;
00101 ul->values = NULL;
00102 ul->next = NULL;
00103 if (ul_last)
00104 ul_last->next = ul;
00105 else
00106 udef = ul;
00107 }
00108
00109 static void free_udef(struct udef_struct *ul)
00110 {
00111 struct udef_struct *ull;
00112
00113 for (; ul; ul = ull) {
00114 ull = ul->next;
00115 free_udef_chans(ul->values, ul->type);
00116 free(ul->name);
00117 free(ul);
00118 }
00119 }
00120
00121 static void free_udef_chans(struct udef_chans *ul, int type)
00122 {
00123 struct udef_chans *ull;
00124
00125 for (; ul; ul = ull) {
00126 ull = ul->next;
00127 if (type == UDEF_STR && ul->value) {
00128 free((void *)ul->value);
00129 }
00130 free(ul->chan);
00131 free(ul);
00132 }
00133 }