int webhdfs_req_open (webhdfs_req_t *req, webhdfs_t *fs, const char *path) { const webhdfs_conf_t *conf = fs->conf; int r; buffer_open(&(req->buffer)); /* No upload by default */ req->upload_data = NULL; req->upload = NULL; /* Fill URL */ buffer_clear(&(req->buffer)); r = buffer_append_format(&(req->buffer), "%s://%s:%d/webhdfs/v1/%s?", conf->use_ssl ? "https" : "http", conf->host, conf->port, (path != NULL) ? path + 1 : ""); if (conf->user != NULL) r |= buffer_append_format(&(req->buffer), "user.name=%s&", conf->user); if (conf->token != NULL) r |= buffer_append_format(&(req->buffer), "delegation=%s&", conf->token); return(r); }
void _hdata_write(const hdata_class_t * data_class,hdata_t data,hbuffer_t buffer,hbool pattern,hint32 level,InvokeTickDeclare){ hint32 c,i; _hdata_write_object_each_arg_t arg; hdata_type_code type; if(data && data_class && buffer){ type = hdata_type(data_class,data,InvokeTickArg); if(type == HDATA_TYPE_NULL){ buffer_append_str(buffer, "null"); } else if(type == HDATA_TYPE_INT16 ){ buffer_append_format(buffer, "%d",InvokeTickArg, hdata_int16(data_class,data,0,InvokeTickArg)); } else if(type == HDATA_TYPE_INT32){ buffer_append_format(buffer, "%ld",InvokeTickArg,hdata_int32(data_class,data,0,InvokeTickArg)); } else if(type == HDATA_TYPE_INT64){ buffer_append_format(buffer, "%lld",InvokeTickArg,hdata_int64(data_class,data,0,InvokeTickArg)); } else if(type == HDATA_TYPE_DOUBLE){ buffer_append_format(buffer, "%f",InvokeTickArg,hdata_double(data_class,data,0,InvokeTickArg)); } else if(type == HDATA_TYPE_BOOL){ if(hdata_boolean(data_class,data,hbool_false,InvokeTickArg)){ buffer_append_str(buffer, "true"); } else{ buffer_append_str(buffer, "false"); } } else if(type == HDATA_TYPE_STRING){ if(hdata_string(data_class,data,NULL,InvokeTickArg)){ hdata_json_write_string(hdata_string(data_class,data,"",InvokeTickArg),buffer,InvokeTickArg); } else{ buffer_append_str(buffer, "null"); } } else if(type ==HDATA_TYPE_ARRAY){ buffer_append_str(buffer, "["); c = hdata_array_size(data_class,data,InvokeTickArg); for(i=0;i<c;i++){ if(i==0 && pattern){ buffer_append_str(buffer, "\n"); _hdata_json_write_level(buffer,level+1,InvokeTickArg); } else if(pattern){ _hdata_json_write_level(buffer,level+1,InvokeTickArg); } _hdata_write(data_class,hdata_array(data_class,data,i,InvokeTickArg),buffer,pattern,level+1,InvokeTickArg); if(i != c-1){ buffer_append_str(buffer, ","); } if(pattern){ buffer_append_str(buffer, "\n"); } } if(pattern && c>0){ _hdata_json_write_level(buffer,level,InvokeTickArg); buffer_append_str(buffer, "]"); } else{ buffer_append_str(buffer, "]"); } } else if(type ==HDATA_TYPE_OBJECT){ buffer_append_str(buffer, "{"); arg.buffer = buffer; arg.pattern = pattern; arg.level = level+1; arg.first = hbool_true; arg.data_class = data_class; hdata_object_each(data_class,data, _hdata_json_write_object_echo,&arg,InvokeTickArg); if(pattern && *((hchar *)buffer_data(buffer) + buffer_length(buffer) -1) != '{'){ _hdata_json_write_level(buffer,level,InvokeTickArg); buffer_append_str(buffer, "}"); } else{ buffer_append_str(buffer, "}"); } } else if(type == HDATA_TYPE_BYTES){ buffer_append_str(buffer, "\""); buffer_append_str(buffer, HDATA_BASE64_TAG); hbase64_encode(hdata_bytes(data_class, data,InvokeTickArg),hdata_bytes_size(data_class, data,InvokeTickArg),buffer); buffer_append_str(buffer, "\""); } } }