- fprintf(stderr, "Encoding failed.\n");
- return false;
- }
-
- /* We signal the end of request with a 0 tag. */
- pb_write(&output, &zero, 1);
-
- response.file.funcs.decode = &printfile_callback;
-
- if (!pb_decode(&input, ListFilesResponse_fields, &response))
- {
- fprintf(stderr, "Decode failed: %s\n", PB_GET_ERROR(&input));
- return false;
- }
-
- if (response.path_error)
- {
- fprintf(stderr, "Server reported error.\n");
- return false;
+ ListFilesResponse response = {};
+ pb_istream_t input = pb_istream_from_socket(fd);
+
+ /* Give a pointer to our callback function, which will handle the
+ * filenames as they arrive. */
+ response.file.funcs.decode = &printfile_callback;
+
+ if (!pb_decode(&input, ListFilesResponse_fields, &response))
+ {
+ fprintf(stderr, "Decode failed: %s\n", PB_GET_ERROR(&input));
+ return false;
+ }
+
+ /* If the message from server decodes properly, but directory was
+ * not found on server side, we get path_error == true. */
+ if (response.path_error)
+ {
+ fprintf(stderr, "Server reported error.\n");
+ return false;
+ }