Changeset 4994 for trunk/oscam-http-helpers.c
- Timestamp:
- 04/13/11 23:19:59 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/oscam-http-helpers.c
r4896 r4994 6 6 /* Adds a name->value-mapping or appends to it. You will get a reference back which you may freely 7 7 use (but you should not call free/realloc on this!)*/ 8 char *tpl_addVar(struct templatevars *vars, uint8 addmode, char *name, char *value){8 char *tpl_addVar(struct templatevars *vars, uint8_t addmode, char *name, char *value){ 9 9 if(name == NULL || value == NULL) return ""; 10 int i;10 int32_t i; 11 11 char *tmp,*result = NULL; 12 12 for(i = (*vars).varscnt-1; i >= 0; --i){ … … 20 20 if(!cs_realloc(&(*vars).names, (*vars).varsalloc * 2 * sizeof(char**), -1)) return ""; 21 21 if(!cs_realloc(&(*vars).values, (*vars).varsalloc * 2 * sizeof(char**), -1)) return ""; 22 if(!cs_realloc(&(*vars).vartypes, (*vars).varsalloc * 2 * sizeof(uint8 *), -1)) return "";22 if(!cs_realloc(&(*vars).vartypes, (*vars).varsalloc * 2 * sizeof(uint8_t*), -1)) return ""; 23 23 (*vars).varsalloc = (*vars).varscnt * 2; 24 24 } 25 int len = strlen(name) + 1;25 int32_t len = strlen(name) + 1; 26 26 if(!cs_malloc(&tmp, len * sizeof(char), -1)) return ""; 27 27 memcpy(tmp, name, len); … … 38 38 (*vars).varscnt++; 39 39 } else { 40 int oldlen = 0, newlen = strlen(value);40 int32_t oldlen = 0, newlen = strlen(value); 41 41 if(addmode == TPLAPPEND || addmode == TPLAPPENDONCE) oldlen = strlen((*vars).values[i]); 42 42 if(!cs_realloc(&((*vars).values[i]), (oldlen + newlen + 1) * sizeof(char), -1)) return value; … … 65 65 In either case you will always get a reference back which you may freely use (but you should not call 66 66 free/realloc on this as it will be automatically cleaned!)*/ 67 char *tpl_printf(struct templatevars *vars, uint8 addmode, char *varname, char *fmtstring, ...){68 u nsigned int needed;67 char *tpl_printf(struct templatevars *vars, uint8_t addmode, char *varname, char *fmtstring, ...){ 68 uint32_t needed; 69 69 char test[1]; 70 70 va_list argptr; … … 91 91 /* Returns the value for a name or an empty string if nothing was found. */ 92 92 char *tpl_getVar(struct templatevars *vars, char *name){ 93 int i;93 int32_t i; 94 94 char *result = NULL; 95 95 for(i = (*vars).varscnt-1; i >= 0; --i){ … … 133 133 return NULL; 134 134 }; 135 if(!cs_malloc(&(*vars).vartypes, (*vars).varsalloc * sizeof(uint8 *), -1)){135 if(!cs_malloc(&(*vars).vartypes, (*vars).varsalloc * sizeof(uint8_t*), -1)){ 136 136 free((*vars).names); 137 137 free((*vars).values); … … 151 151 /* Clears all allocated memory for the specified templatevar-structure. */ 152 152 void tpl_clear(struct templatevars *vars){ 153 int i;153 int32_t i; 154 154 for(i = (*vars).varscnt-1; i >= 0; --i){ 155 155 free((*vars).names[i]); … … 167 167 168 168 /* Creates a path to a template file. You need to set the resultsize to the correct size of result. */ 169 char *tpl_getTplPath(const char *name, const char *path, char *result, u nsigned int resultsize){169 char *tpl_getTplPath(const char *name, const char *path, char *result, uint32_t resultsize){ 170 170 char *pch; 171 171 if((strlen(path) + strlen(name) + 6) <= resultsize){ … … 181 181 Note: You must free() the result after using it and you may get NULL if an error occured!*/ 182 182 char *tpl_getUnparsedTpl(const char* name){ 183 int i;184 int tplcnt = sizeof(tpl)/sizeof(char *);185 int tplmapcnt = sizeof(tplmap)/sizeof(char *);183 int32_t i; 184 int32_t tplcnt = sizeof(tpl)/sizeof(char *); 185 int32_t tplmapcnt = sizeof(tplmap)/sizeof(char *); 186 186 char *result; 187 187 … … 195 195 FILE *fp; 196 196 char buffer[1024]; 197 int read, allocated = 1025, size = 0;197 int32_t read, allocated = 1025, size = 0; 198 198 if(!cs_malloc(&result, allocated * sizeof(char), -1)) return NULL; 199 199 if((fp = fopen(path,"r"))!=NULL){ … … 213 213 } 214 214 if(i >= 0 && i < tplmapcnt){ 215 int len = (strlen(tplmap[i])) + 1;215 int32_t len = (strlen(tplmap[i])) + 1; 216 216 if(!cs_malloc(&result, len * sizeof(char), -1)) return NULL; 217 217 memcpy(result, tplmap[i], len); … … 233 233 char varname[33]; 234 234 235 int tmp,respos = 0;236 int allocated = 2 * strlen(tpl) + 1;235 int32_t tmp,respos = 0; 236 int32_t allocated = 2 * strlen(tpl) + 1; 237 237 char *result; 238 238 if(!cs_malloc(&result, allocated * sizeof(char), -1)) return ""; … … 277 277 278 278 /* Saves all templates to the specified paths. Existing files will be overwritten! */ 279 int tpl_saveIncludedTpls(const char *path){280 int tplcnt = sizeof(tpl)/sizeof(char *);281 int tplmapcnt = sizeof(tplmap)/sizeof(char *);282 int i, cnt = 0;279 int32_t tpl_saveIncludedTpls(const char *path){ 280 int32_t tplcnt = sizeof(tpl)/sizeof(char *); 281 int32_t tplmapcnt = sizeof(tplmap)/sizeof(char *); 282 int32_t i, cnt = 0; 283 283 char tmp[256]; 284 284 FILE *fp; … … 318 318 /* Checks if authentication is correct. Returns -1 if not correct, 1 if correct and 2 if nonce isn't valid anymore. 319 319 Note that authstring will be modified. */ 320 int check_auth(char *authstring, char *method, char *path, char *expectednonce){321 int authok = 0, uriok = 0;320 int32_t check_auth(char *authstring, char *method, char *path, char *expectednonce){ 321 int32_t authok = 0, uriok = 0; 322 322 char *authnonce = ""; 323 323 char *authnc = ""; … … 387 387 #endif 388 388 389 int webif_write_raw(char *buf, FILE* f, int len) {389 int32_t webif_write_raw(char *buf, FILE* f, int32_t len) { 390 390 #ifdef WITH_SSL 391 391 if (cfg.http_use_ssl) { … … 396 396 } 397 397 398 int webif_write(char *buf, FILE* f) {398 int32_t webif_write(char *buf, FILE* f) { 399 399 return webif_write_raw(buf, f, strlen(buf)); 400 400 } 401 401 402 int webif_read(char *buf, int num, FILE *f) {402 int32_t webif_read(char *buf, int32_t num, FILE *f) { 403 403 #ifdef WITH_SSL 404 404 if (cfg.http_use_ssl) { … … 409 409 } 410 410 411 void send_headers(FILE *f, int status, char *title, char *extra, char *mime, int cache){411 void send_headers(FILE *f, int32_t status, char *title, char *extra, char *mime, int32_t cache){ 412 412 time_t now; 413 413 char timebuf[32]; … … 444 444 */ 445 445 void send_file(FILE *f, char *filename){ 446 int fileno = 0;446 int32_t fileno = 0; 447 447 448 448 if (!strcmp(filename, "CSS")){ … … 457 457 FILE *fp; 458 458 char buffer[1024]; 459 int read;459 int32_t read; 460 460 461 461 if((fp = fopen(filename, "r"))==NULL) return; … … 474 474 } 475 475 476 void send_error(FILE *f, int status, char *title, char *extra, char *text){476 void send_error(FILE *f, int32_t status, char *title, char *extra, char *text){ 477 477 char buf[(2* strlen(title)) + strlen(text) + 128]; 478 478 char *pos = buf; … … 490 490 491 491 char *getParam(struct uriparams *params, char *name){ 492 int i;492 int32_t i; 493 493 for(i=(*params).paramcount-1; i>=0; --i){ 494 494 if(strcmp((*params).params[i], name) == 0) return (*params).values[i]; … … 498 498 499 499 /* Helper function for urldecode.*/ 500 int x2i(int i){500 int32_t x2i(int32_t i){ 501 501 i=toupper(i); 502 502 i = i - '0'; … … 507 507 /* Decodes values in a http url. Note: The original value is modified! */ 508 508 void urldecode(char *s){ 509 int c, c1, n;509 int32_t c, c1, n; 510 510 char *s0,*t; 511 511 t = s0 = s; … … 551 551 Do not call free() or realloc on the returned reference or you will get memory corruption! */ 552 552 char *xml_encode(struct templatevars *vars, char *chartoencode) { 553 int i, pos = 0, len = strlen(chartoencode);553 int32_t i, pos = 0, len = strlen(chartoencode); 554 554 char *result; 555 555 /* In worst case, every character could get converted to 6 chars (we only support ASCII, for Unicode it would be 7)*/ … … 583 583 } 584 584 585 int b64decode(unsigned char *result){585 int32_t b64decode(unsigned char *result){ 586 586 char inalphabet[256], decoder[256]; 587 587 unsigned char alphabet[64] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 588 int i, len = strlen((char *)result), j = 0, bits = 0, char_count = 0;588 int32_t i, len = strlen((char *)result), j = 0, bits = 0, char_count = 0; 589 589 590 590 for (i = sizeof(alphabet) - 1; i >= 0; --i) { … … 632 632 633 633 /* Format a seconds integer to hh:mm:ss or dd hh:mm:ss depending hrs >24 */ 634 char *sec2timeformat(struct templatevars *vars, int seconds) {634 char *sec2timeformat(struct templatevars *vars, int32_t seconds) { 635 635 636 636 char *value; … … 641 641 return "00:00:00"; 642 642 643 int secs = 0, fullmins = 0, mins = 0, fullhours = 0, hours = 0, days = 0;643 int32_t secs = 0, fullmins = 0, mins = 0, fullhours = 0, hours = 0, days = 0; 644 644 645 645 secs = seconds % 60;
Note:
See TracChangeset
for help on using the changeset viewer.