Changeset 1141
- Timestamp:
- 01/09/10 14:40:43 (14 years ago)
- Location:
- branches/monitor-improvement
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/monitor-improvement/oscam-config.c
r1139 r1141 1002 1002 fprintf_conf(f, CONFVARWIDTH, "serverip", "%s\n", inet_ntoa(*(struct in_addr *)&cfg->c33_srvip)); 1003 1003 fprintf_conf(f, CONFVARWIDTH, "passive", "%d\n", cfg->c33_passive); 1004 fprintf_conf(f, CONFVARWIDTH, "key", ""); for (i = 0; i < sizeof(cfg->c33_key); ++i) fprintf(f,"%02X", cfg->c33_key[i]); fputc((int)'\n', f); 1004 unsigned int ui; 1005 fprintf_conf(f, CONFVARWIDTH, "key", ""); for (ui = 0; ui < sizeof(cfg->c33_key); ++ui) fprintf(f,"%02X", cfg->c33_key[ui]); fputc((int)'\n', f); 1005 1006 fprintf_conf(f, CONFVARWIDTH, "nocrypt", ""); 1006 1007 dot=""; -
branches/monitor-improvement/oscam-http-helpers.c
r1028 r1141 1 1 #include "oscam-http.h" 2 2 3 /* Adds a name->value-mapping or appends to it. You will get a reference back which you may freely 3 /* Adds a name->value-mapping or appends to it. You will get a reference back which you may freely 4 4 use (but you should not call free/realloc on this!)*/ 5 5 char *tpl_addVar(struct templatevars *vars, int append, char *name, char *value){ … … 37 37 } 38 38 free((*vars).values[i]); 39 (*vars).values[i] = tmp; 40 } 39 (*vars).values[i] = tmp; 40 } 41 41 return tmp; 42 42 } 43 43 44 /* Allows to add a char array which has been allocated by malloc. It will automatically get 45 freed when calling tpl_create(). Please do NOT free the memory yourself or realloc 44 /* Allows to add a char array which has been allocated by malloc. It will automatically get 45 freed when calling tpl_create(). Please do NOT free the memory yourself or realloc 46 46 it after having added the array here! */ 47 47 char *tpl_addTmp(struct templatevars *vars, char *value){ … … 59 59 back which you may freely use (but you should not call free/realloc on this!)*/ 60 60 char *tpl_printf(struct templatevars *vars, int append, char *varname, char *fmtstring, ...){ 61 int allocated = strlen(fmtstring) - (strlen(fmtstring)%16) + 16;62 char *result, *tmp = (char *) malloc(allocated * sizeof(char)); 61 unsigned int allocated = strlen(fmtstring) - (strlen(fmtstring)%16) + 16; 62 char *result, *tmp = (char *) malloc(allocated * sizeof(char)); 63 63 va_list argptr; 64 64 65 65 va_start(argptr,fmtstring); 66 66 vsnprintf(tmp ,allocated, fmtstring, argptr); … … 72 72 vsnprintf(tmp, allocated, fmtstring, argptr); 73 73 va_end(argptr); 74 } 74 } 75 75 result = (char *) malloc(strlen(tmp) + 1 * sizeof(char)); 76 76 strcpy(result, tmp); … … 81 81 free(result); 82 82 result = tmp; 83 } 83 } 84 84 return result; 85 85 } … … 99 99 } 100 100 101 /* Initializes all variables vor a templatevar-structure and returns a pointer to it. Make 101 /* Initializes all variables vor a templatevar-structure and returns a pointer to it. Make 102 102 sure to call tpl_clear() when you are finished or you'll run into a memory leak! */ 103 103 struct templatevars *tpl_create(){ … … 118 118 for(i = (*vars).varscnt-1; i >= 0; --i){ 119 119 free((*vars).names[i]); 120 free((*vars).values[i]); 120 free((*vars).values[i]); 121 121 } 122 122 free((*vars).names); 123 123 free((*vars).values); 124 124 for(i = (*vars).tmpcnt-1; i >= 0; --i){ 125 free((*vars).tmp[i]); 125 free((*vars).tmp[i]); 126 126 } 127 127 free((*vars).tmp); … … 130 130 131 131 /* Creates a path to a template file. You need to set the resultsize to the correct size of result. */ 132 char *tpl_getTplPath(const char *name, const char *path, char *result, int resultsize){132 char *tpl_getTplPath(const char *name, const char *path, char *result, unsigned int resultsize){ 133 133 char *pch; 134 134 if((strlen(path) + strlen(name) + 5) <= resultsize){ … … 144 144 } 145 145 146 /* Returns an unparsed template either from disk or from internal templates. 146 /* Returns an unparsed template either from disk or from internal templates. 147 147 Note: You must free() the result after using it!*/ 148 148 char *tpl_getUnparsedTpl(const char* name){ … … 151 151 int tplmapcnt = sizeof(tplmap)/sizeof(char *); 152 152 char *result; 153 153 154 154 for(i = 0; i < tplcnt; ++i){ 155 155 if(strcmp(name, tpl[i]) == 0) break; 156 156 } 157 157 158 158 if(strlen(cfg->http_tpl) > 0){ 159 159 char path[200]; … … 162 162 char buffer[1024]; 163 163 int read, allocated = 1025, size = 1; 164 result = (char *) malloc(allocated * sizeof(char)); 164 result = (char *) malloc(allocated * sizeof(char)); 165 165 if((fp = fopen(path,"r"))!=NULL){ 166 166 while((read = fread(&buffer,sizeof(char),1024,fp)) > 0){ … … 180 180 if(i >= 0 && i < tplmapcnt){ 181 181 int len = (strlen(tplmap[i])) + 1; 182 result = (char *) malloc(len * sizeof(char)); 182 result = (char *) malloc(len * sizeof(char)); 183 183 memcpy(result, tplmap[i], len); 184 184 } else { 185 result = (char *) malloc(1 * sizeof(char)); 185 result = (char *) malloc(1 * sizeof(char)); 186 186 result[0] = '\0'; 187 } 187 } 188 188 return result; 189 189 } 190 190 191 /* Returns the specified template with all variables/other templates replaced or an 191 /* Returns the specified template with all variables/other templates replaced or an 192 192 empty string if the template doesn't exist*/ 193 193 char *tpl_getTpl(struct templatevars *vars, const char* name){ … … 196 196 char *pch, *pch2, *tpl=tplorg; 197 197 char varname[33]; 198 198 199 199 int tmp,respos = 0; 200 200 int allocated = 2 * strlen(tpl) + 1; 201 char *result = (char *) malloc(allocated * sizeof(char)); 202 201 char *result = (char *) malloc(allocated * sizeof(char)); 202 203 203 while(tpl < tplend){ 204 if(tpl[0] == '#' && tpl[1] == '#' && tpl[2] != '#'){ 204 if(tpl[0] == '#' && tpl[1] == '#' && tpl[2] != '#'){ 205 205 pch2 = tpl; 206 206 pch = tpl + 2; … … 213 213 } else { 214 214 pch2 = tpl_getVar(vars, varname); 215 } 215 } 216 216 tmp = strlen(pch2); 217 217 if(tmp + respos + 2 >= allocated){ … … 222 222 respos += tmp; 223 223 tpl = pch + 2; 224 } 224 } 225 225 } else { 226 226 if(respos + 2 >= allocated){ … … 231 231 ++respos; 232 232 ++tpl; 233 } 233 } 234 234 } 235 235 free(tplorg); … … 325 325 pch2 = uri; 326 326 for(pch = uri; pch[0] != '\0'; ++pch) { 327 if(pch[0] == '/') pch2 = pch; 327 if(pch[0] == '/') pch2 = pch; 328 328 } 329 329 if(strncmp(pch2, path, strlen(path)) == 0) uriok = 1; … … 420 420 for(i=(*params).paramcount-1; i>=0; --i){ 421 421 if(strcmp((*params).params[i], name) == 0) return (*params).values[i]; 422 } 422 } 423 423 return ""; 424 424 } -
branches/monitor-improvement/oscam-http.c
r1139 r1141 114 114 tpl_printf(vars, 0, "PASSIVE", "%d", cfg->c33_passive); 115 115 116 for (i = 0; i < sizeof(cfg->c33_key); ++i) tpl_printf(vars, 1, "KEY", "%02X",cfg->c33_key[i]); 116 unsigned int ui; 117 for (ui = 0; ui < sizeof(cfg->c33_key); ++ui) tpl_printf(vars, 1, "KEY", "%02X",cfg->c33_key[ui]); 117 118 struct s_ip *cip; 118 119 char *dot="";
Note:
See TracChangeset
for help on using the changeset viewer.