src/libs/ulfius/lib_websocket.c
/**
 * decode a u_map into a string
 */
decode a u_map into a string
decode a u_map into a string
char * print_map(const struct _u_map * map) {
  char * line, * to_return = NULL;
  const char **keys, * value;
  int len, i;
  if (map != NULL) {
    keys = u_map_enum_keys(map);
    for (i=0; keys[i] != NULL; i++) {
      value = u_map_get(map, keys[i]);
      len = snprintf(NULL, 0, "key is %s, value is %s", keys[i], value);
      line = o_malloc((len+1)*sizeof(char));
      snprintf(line, (len+1), "key is %s, value is %s", keys[i], value);
      if (to_return != NULL) {
        len = o_strlen(to_return) + o_strlen(line) + 1;
        to_return = o_realloc(to_return, (len+1)*sizeof(char));
        if (o_strlen(to_return) > 0) {
          strcat(to_return, "\n");
        }
      } else {
        to_return = o_malloc((o_strlen(line) + 1)*sizeof(char));
        to_return[0] = 0;
      }
      strcat(to_return, line);
      o_free(line);
    }
    return to_return;
  } else {
    return NULL;
  }
}
char * print_map ( const struct _u_map * map ) { char * line , * to_return = NULL ; const char * * keys , * value ; int len , i ; if ( map != NULL ) { keys = u_map_enum_keys ( map ) ; for ( i = 0 ; keys [ i ] != NULL ; i ++ ) { value = u_map_get ( map , keys [ i ] ) ; len = snprintf ( NULL , 0 , " " , keys [ i ] , value ) ; line = o_malloc ( ( len + 1 ) * sizeof ( char ) ) ; snprintf ( line , ( len + 1 ) , " " , keys [ i ] , value ) ; if ( to_return != NULL ) { len = o_strlen ( to_return ) + o_strlen ( line ) + 1 ; to_return = o_realloc ( to_return , ( len + 1 ) * sizeof ( char ) ) ; if ( o_strlen ( to_return ) > 0 ) { strcat ( to_return , " \n " ) ; } } else { to_return = o_malloc ( ( o_strlen ( line ) + 1 ) * sizeof ( char ) ) ; to_return [ 0 ] = 0 ; } strcat ( to_return , line ) ; o_free ( line ) ; } return to_return ; } else { return NULL ; } }
decode a u_map into a string
decode a u_map into a string