@@ -289,26 +289,23 @@ handle_control_getconf(control_connection_t *conn,
289289 const smartlist_t * questions = args -> args ;
290290 smartlist_t * answers = smartlist_new ();
291291 smartlist_t * unrecognized = smartlist_new ();
292- char * msg = NULL ;
293- size_t msg_len ;
294292 const or_options_t * options = get_options ();
295- int i , len ;
296293
297294 SMARTLIST_FOREACH_BEGIN (questions , const char * , q ) {
298295 if (!option_is_recognized (q )) {
299- smartlist_add (unrecognized , (char * ) q );
296+ control_reply_add_printf (unrecognized , 552 ,
297+ "Unrecognized configuration key \"%s\"" , q );
300298 } else {
301299 config_line_t * answer = option_get_assignment (options ,q );
302300 if (!answer ) {
303301 const char * name = option_get_canonical_name (q );
304- smartlist_add_asprintf (answers , " 250-%s\r\n" , name );
302+ control_reply_add_1kv (answers , 250 , KV_OMIT_VALS , name , "" );
305303 }
306304
307305 while (answer ) {
308306 config_line_t * next ;
309- smartlist_add_asprintf (answers , "250-%s=%s\r\n" ,
310- answer -> key , answer -> value );
311-
307+ control_reply_add_1kv (answers , 250 , KV_RAW , answer -> key ,
308+ answer -> value );
312309 next = answer -> next ;
313310 tor_free (answer -> key );
314311 tor_free (answer -> value );
@@ -318,20 +315,10 @@ handle_control_getconf(control_connection_t *conn,
318315 }
319316 } SMARTLIST_FOREACH_END (q );
320317
321- if ((len = smartlist_len (unrecognized ))) {
322- for (i = 0 ; i < len - 1 ; ++ i )
323- control_printf_midreply (conn , 552 ,
324- "Unrecognized configuration key \"%s\"" ,
325- (char * )smartlist_get (unrecognized , i ));
326- control_printf_endreply (conn , 552 ,
327- "Unrecognized configuration key \"%s\"" ,
328- (char * )smartlist_get (unrecognized , len - 1 ));
329- } else if ((len = smartlist_len (answers ))) {
330- char * tmp = smartlist_get (answers , len - 1 );
331- tor_assert (strlen (tmp )> 4 );
332- tmp [3 ] = ' ' ;
333- msg = smartlist_join_strings (answers , "" , 0 , & msg_len );
334- connection_buf_add (msg , msg_len , TO_CONN (conn ));
318+ if (smartlist_len (unrecognized )) {
319+ control_write_reply_lines (conn , unrecognized );
320+ } else if (smartlist_len (answers )) {
321+ control_write_reply_lines (conn , answers );
335322 } else {
336323 send_control_done (conn );
337324 }
@@ -340,8 +327,6 @@ handle_control_getconf(control_connection_t *conn,
340327 smartlist_free (answers );
341328 smartlist_free (unrecognized );
342329
343- tor_free (msg );
344-
345330 return 0 ;
346331}
347332
0 commit comments