Changeset 1683
- Timestamp:
- 02/25/10 11:15:52 (14 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/globals.h
r1682 r1683 749 749 extern void cs_setpriority(int); 750 750 extern struct s_auth *find_user(char *); 751 extern void long2bitchar(long value, char *result);752 751 extern void clear_sip(struct s_ip **sip); 753 752 extern void clear_ptab(struct s_ptab *ptab); -
trunk/oscam-config.c
r1682 r1683 2037 2037 } 2038 2038 #endif 2039 2040 /*2041 * makes a char ready to write a token into config or webIf2042 */2043 char *mk_t_caidtab(CAIDTAB *ctab){2044 int i = 0, needed = 1, pos = 0;2045 while(ctab->caid[i]){2046 if(ctab->mask[i]) needed += 10;2047 else needed += 5;2048 if(ctab->cmap[i]) needed += 5;2049 ++i;2050 }2051 char *value = (char *) malloc(needed * sizeof(char));2052 i = 0;2053 while(ctab->caid[i]) {2054 if(i == 0) {2055 sprintf(value + pos, "%04X", ctab->caid[i]);2056 pos += 4;2057 } else {2058 sprintf(value + pos, ",%04X", ctab->caid[i]);2059 pos += 5;2060 }2061 if(ctab->mask[i]){2062 sprintf(value + pos, "&%04X", ctab->mask[i]);2063 pos += 5;2064 }2065 if(ctab->cmap[i]){2066 sprintf(value + pos, ":%04X", ctab->cmap[i]);2067 pos += 5;2068 }2069 ++i;2070 }2071 value[pos] = '\0';2072 return value;2073 }2074 2075 /*2076 * makes a char ready to write a token into config or webIf2077 */2078 char *mk_t_tuntab(TUNTAB *ttab){2079 int i = 0, needed = 1, pos = 0;2080 while(ttab->bt_caidfrom[i]){2081 if(ttab->bt_srvid[i]) needed += 10;2082 else needed += 5;2083 if(ttab->bt_caidto[i]) needed += 5;2084 ++i;2085 }2086 char *value = (char *) malloc(needed * sizeof(char));2087 i = 0;2088 while(ttab->bt_caidfrom[i]) {2089 if(i == 0) {2090 sprintf(value + pos, "%04X", ttab->bt_caidfrom[i]);2091 pos += 4;2092 } else {2093 sprintf(value + pos, ",%04X", ttab->bt_caidfrom[i]);2094 pos += 5;2095 }2096 if(ttab->bt_srvid[i]){2097 sprintf(value + pos, ".%04X", ttab->bt_srvid[i]);2098 pos += 5;2099 }2100 if(ttab->bt_caidto[i]){2101 sprintf(value + pos, ":%04X", ttab->bt_caidto[i]);2102 pos += 5;2103 }2104 ++i;2105 }2106 value[pos] = '\0';2107 return value;2108 }2109 2110 /*2111 * makes a char ready to write a token into config or webIf2112 */2113 char *mk_t_group(ulong *grp){2114 int i = 0, needed = 1, pos = 0, dot = 0;2115 char grpbit[33];2116 long2bitchar((long) grp, grpbit);2117 2118 for(i = 0; i < 32; i++){2119 if (grpbit[i] == '1'){2120 needed += 2;2121 if(i > 9) needed += 1;2122 }2123 }2124 char *value = (char *) malloc(needed * sizeof(char));2125 2126 for(i = 0; i < 32; i++){2127 if (grpbit[i] == '1'){2128 if (dot == 0){2129 sprintf(value + pos, "%d", i+1);2130 if (i > 9)pos += 2;2131 else pos += 1;2132 dot = 1;2133 } else {2134 sprintf(value + pos, ",%d", i+1);2135 if (i > 9)pos += 3;2136 else pos += 2;2137 }2138 }2139 }2140 value[pos] = '\0';2141 return value;2142 }2143 2144 /*2145 * makes a char ready to write a token into config or webIf2146 */2147 char *mk_t_ftab(FTAB *ftab){2148 int i = 0, j = 0, needed = 1, pos = 0;2149 2150 needed = ftab->nfilts * 5;2151 for (i = 0; i < ftab->nfilts; ++i)2152 needed += ftab->filts[i].nprids * 7;2153 2154 char *value = (char *) malloc(needed * sizeof(char));2155 2156 char *dot="";2157 for (i = 0; i < ftab->nfilts; ++i){2158 sprintf(value + pos, "%s%04X", dot, ftab->filts[i].caid);2159 pos += 4;2160 if (i > 0) pos += 1;2161 dot=":";2162 for (j = 0; j < ftab->filts[i].nprids; ++j) {2163 sprintf(value + pos, "%s%06lX", dot, ftab->filts[i].prids[j]);2164 pos += 7;2165 dot=",";2166 }2167 dot=";";2168 }2169 2170 value[pos] = '\0';2171 return value;2172 } -
trunk/oscam-simples.c
r1682 r1683 399 399 } 400 400 401 /* Converts a long value to a char array in bitwise representation.402 Note that the result array MUST be at least 33 bit large and that403 this function assumes long values to hold only values up to 32bits and to be positive!404 the result of e.g. long 7 is 11100000000000000000000000000000 this means the array405 is reversed */406 void long2bitchar(long value, char *result){407 int pos;408 for (pos=0;pos<32;pos++) result[pos]='0';409 result[pos] = '\0';410 411 pos=0;412 while (value > 0 && pos < 32){413 if(value % 2 == 1) result[pos]='1';414 else result[pos]='0';415 value=value / 2;416 pos++;417 }418 }419 420 401 /* 421 402 * Ordinary strncpy does not terminate the string if the source
Note:
See TracChangeset
for help on using the changeset viewer.