Ignore:
Timestamp:
04/13/11 23:19:59 (9 years ago)
Author:
Admin
Message:

I noticed that monitor encryption is not working on 64bit plattforms due to other sizes of long on this plattform. This patch converts all numeric types like long to portable types like uint32_t. This is not complete yet (only base folder up to r4987, changes thereafter might be incompletely converted). If you encounter problems through this patch please report in forum.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/oscam-http-helpers.c

    r4896 r4994  
    66/* Adds a name->value-mapping or appends to it. You will get a reference back which you may freely
    77   use (but you should not call free/realloc on this!)*/
    8 char *tpl_addVar(struct templatevars *vars, uint8 addmode, char *name, char *value){   
     8char *tpl_addVar(struct templatevars *vars, uint8_t addmode, char *name, char *value){ 
    99    if(name == NULL || value == NULL) return "";
    10     int i;
     10    int32_t i;
    1111    char *tmp,*result = NULL;
    1212    for(i = (*vars).varscnt-1; i >= 0; --i){
     
    2020            if(!cs_realloc(&(*vars).names, (*vars).varsalloc * 2 * sizeof(char**), -1)) return "";
    2121            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 "";
    2323            (*vars).varsalloc = (*vars).varscnt * 2;
    2424        }
    25         int len = strlen(name) + 1;
     25        int32_t len = strlen(name) + 1;
    2626        if(!cs_malloc(&tmp, len * sizeof(char), -1)) return "";
    2727        memcpy(tmp, name, len);
     
    3838        (*vars).varscnt++;
    3939    } else {
    40         int oldlen = 0, newlen = strlen(value);
     40        int32_t oldlen = 0, newlen = strlen(value);
    4141        if(addmode == TPLAPPEND || addmode == TPLAPPENDONCE) oldlen = strlen((*vars).values[i]);
    4242        if(!cs_realloc(&((*vars).values[i]), (oldlen + newlen + 1) * sizeof(char), -1)) return value;
     
    6565   In either case you will always get a reference back which you may freely use (but you should not call
    6666   free/realloc on this as it will be automatically cleaned!)*/
    67 char *tpl_printf(struct templatevars *vars, uint8 addmode, char *varname, char *fmtstring, ...){
    68     unsigned int needed;
     67char *tpl_printf(struct templatevars *vars, uint8_t addmode, char *varname, char *fmtstring, ...){
     68    uint32_t needed;
    6969    char test[1];
    7070    va_list argptr;
     
    9191/* Returns the value for a name or an empty string if nothing was found. */
    9292char *tpl_getVar(struct templatevars *vars, char *name){
    93     int i;
     93    int32_t i;
    9494    char *result = NULL;
    9595    for(i = (*vars).varscnt-1; i >= 0; --i){
     
    133133        return NULL;
    134134    };
    135     if(!cs_malloc(&(*vars).vartypes, (*vars).varsalloc * sizeof(uint8*), -1)){
     135    if(!cs_malloc(&(*vars).vartypes, (*vars).varsalloc * sizeof(uint8_t*), -1)){
    136136        free((*vars).names);
    137137        free((*vars).values);
     
    151151/* Clears all allocated memory for the specified templatevar-structure. */
    152152void tpl_clear(struct templatevars *vars){
    153     int i;
     153    int32_t i;
    154154    for(i = (*vars).varscnt-1; i >= 0; --i){
    155155        free((*vars).names[i]);
     
    167167
    168168/* 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, unsigned int resultsize){
     169char *tpl_getTplPath(const char *name, const char *path, char *result, uint32_t resultsize){
    170170    char *pch;
    171171    if((strlen(path) + strlen(name) + 6) <= resultsize){
     
    181181   Note: You must free() the result after using it and you may get NULL if an error occured!*/
    182182char *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 *);
    186186  char *result;
    187187
     
    195195            FILE *fp;
    196196            char buffer[1024];
    197             int read, allocated = 1025, size = 0;
     197            int32_t read, allocated = 1025, size = 0;
    198198            if(!cs_malloc(&result, allocated * sizeof(char), -1)) return NULL;
    199199            if((fp = fopen(path,"r"))!=NULL){
     
    213213  }
    214214    if(i >= 0 && i < tplmapcnt){
    215         int len = (strlen(tplmap[i])) + 1;
     215        int32_t len = (strlen(tplmap[i])) + 1;
    216216        if(!cs_malloc(&result, len * sizeof(char), -1)) return NULL;
    217217        memcpy(result, tplmap[i], len);
     
    233233    char varname[33];
    234234
    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;
    237237    char *result;
    238238    if(!cs_malloc(&result, allocated * sizeof(char), -1)) return "";
     
    277277
    278278/* 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;
     279int32_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;
    283283  char tmp[256];
    284284  FILE *fp;
     
    318318/* Checks if authentication is correct. Returns -1 if not correct, 1 if correct and 2 if nonce isn't valid anymore.
    319319   Note that authstring will be modified. */
    320 int check_auth(char *authstring, char *method, char *path, char *expectednonce){
    321     int authok = 0, uriok = 0;
     320int32_t check_auth(char *authstring, char *method, char *path, char *expectednonce){
     321    int32_t authok = 0, uriok = 0;
    322322    char *authnonce = "";
    323323    char *authnc = "";
     
    387387#endif
    388388
    389 int webif_write_raw(char *buf, FILE* f, int len) {
     389int32_t webif_write_raw(char *buf, FILE* f, int32_t len) {
    390390#ifdef WITH_SSL
    391391    if (cfg.http_use_ssl) {
     
    396396}
    397397
    398 int webif_write(char *buf, FILE* f) {
     398int32_t webif_write(char *buf, FILE* f) {
    399399    return webif_write_raw(buf, f, strlen(buf));
    400400}
    401401
    402 int webif_read(char *buf, int num, FILE *f) {
     402int32_t webif_read(char *buf, int32_t num, FILE *f) {
    403403#ifdef WITH_SSL
    404404    if (cfg.http_use_ssl) {
     
    409409}
    410410
    411 void send_headers(FILE *f, int status, char *title, char *extra, char *mime, int cache){
     411void send_headers(FILE *f, int32_t status, char *title, char *extra, char *mime, int32_t cache){
    412412  time_t now;
    413413  char timebuf[32];
     
    444444 */
    445445void send_file(FILE *f, char *filename){
    446     int fileno = 0;
     446    int32_t fileno = 0;
    447447
    448448    if (!strcmp(filename, "CSS")){
     
    457457        FILE *fp;
    458458        char buffer[1024];
    459         int read;
     459        int32_t read;
    460460
    461461        if((fp = fopen(filename, "r"))==NULL) return;
     
    474474}
    475475
    476 void send_error(FILE *f, int status, char *title, char *extra, char *text){
     476void send_error(FILE *f, int32_t status, char *title, char *extra, char *text){
    477477    char buf[(2* strlen(title)) + strlen(text) + 128];
    478478    char *pos = buf;
     
    490490
    491491char *getParam(struct uriparams *params, char *name){
    492     int i;
     492    int32_t i;
    493493    for(i=(*params).paramcount-1; i>=0; --i){
    494494        if(strcmp((*params).params[i], name) == 0) return (*params).values[i];
     
    498498
    499499/* Helper function for urldecode.*/
    500 int x2i(int i){
     500int32_t x2i(int32_t i){
    501501    i=toupper(i);
    502502    i = i - '0';
     
    507507/* Decodes values in a http url. Note: The original value is modified! */
    508508void urldecode(char *s){
    509     int c, c1, n;
     509    int32_t c, c1, n;
    510510    char *s0,*t;
    511511    t = s0 = s;
     
    551551   Do not call free() or realloc on the returned reference or you will get memory corruption! */
    552552char *xml_encode(struct templatevars *vars, char *chartoencode) {
    553     int i, pos = 0, len = strlen(chartoencode);
     553    int32_t i, pos = 0, len = strlen(chartoencode);
    554554    char *result;
    555555    /* In worst case, every character could get converted to 6 chars (we only support ASCII, for Unicode it would be 7)*/
     
    583583}
    584584
    585 int b64decode(unsigned char *result){
     585int32_t b64decode(unsigned char *result){
    586586    char inalphabet[256], decoder[256];
    587587    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;
    589589   
    590590    for (i = sizeof(alphabet) - 1; i >= 0; --i) {
     
    632632
    633633/* Format a seconds integer to hh:mm:ss or dd hh:mm:ss depending hrs >24 */
    634 char *sec2timeformat(struct templatevars *vars, int seconds) {
     634char *sec2timeformat(struct templatevars *vars, int32_t seconds) {
    635635
    636636    char *value;
     
    641641        return "00:00:00";
    642642
    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;
    644644
    645645    secs = seconds % 60;
Note: See TracChangeset for help on using the changeset viewer.