3273091df96a495d1a541541697309f72a6b7be7
[routeros-api.git] / src / main.c
1 /**
2  * libmikrotik - src/main.c
3  * Copyright (C) 2009  Florian octo Forster
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the
7  * Free Software Foundation; only version 2 of the License is applicable.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
17  *
18  * Authors:
19  *   Florian octo Forster <octo at verplant.org>
20  **/
21
22 #ifndef _ISOC99_SOURCE
23 # define _ISOC99_SOURCE
24 #endif
25
26 #ifndef _POSIX_C_SOURCE
27 # define _POSIX_C_SOURCE 200112L
28 #endif
29
30 #include <stdlib.h>
31 #include <stdio.h>
32 #include <unistd.h>
33 #include <stdint.h>
34 #include <inttypes.h>
35 #include <string.h>
36 #include <errno.h>
37 #include <assert.h>
38
39 #include <sys/types.h>
40 #include <sys/socket.h>
41 #include <netdb.h>
42
43 #include <gcrypt.h>
44
45 #include "routeros_api.h"
46
47 #if 1
48 # define mt_debug(...) fprintf (stdout, __VA_ARGS__)
49 #else
50 # define mt_debug(...) /**/
51 #endif
52
53 /* FIXME */
54 char *strdup (const char *);
55
56 /*
57  * Private structures
58  */
59 struct mt_connection_s
60 {
61         int fd;
62 };
63
64 struct mt_reply_s
65 {
66         unsigned int params_num;
67         char *status;
68         char **keys;
69         char **values;
70
71         mt_reply_t *next;
72 };
73
74 struct mt_login_data_s
75 {
76         const char *username;
77         const char *password;
78 };
79 typedef struct mt_login_data_s mt_login_data_t;
80
81 /*
82  * Private functions
83  */
84 static int read_exact (int fd, void *buffer, size_t buffer_size) /* {{{ */
85 {
86         char *buffer_ptr;
87         size_t have_bytes;
88
89         if ((fd < 0) || (buffer == NULL))
90                 return (EINVAL);
91
92         if (buffer_size == 0)
93                 return (0);
94
95         buffer_ptr = buffer;
96         have_bytes = 0;
97         while (have_bytes < buffer_size)
98         {
99                 size_t want_bytes;
100                 ssize_t status;
101
102                 want_bytes = buffer_size - have_bytes;
103                 errno = 0;
104                 status = read (fd, buffer_ptr, want_bytes);
105                 if (status < 0)
106                 {
107                         if (errno == EAGAIN)
108                                 continue;
109                         else
110                                 return (status);
111                 }
112
113                 assert (status <= want_bytes);
114                 have_bytes += status;
115                 buffer_ptr += status;
116         }
117
118         return (0);
119 } /* }}} int read_exact */
120
121 static mt_reply_t *reply_alloc (void) /* {{{ */
122 {
123         mt_reply_t *r;
124
125         r = malloc (sizeof (*r));
126         if (r == NULL)
127                 return (NULL);
128
129         memset (r, 0, sizeof (*r));
130         r->keys = NULL;
131         r->values = NULL;
132         r->next = NULL;
133
134         return (r);
135 } /* }}} mt_reply_s *reply_alloc */
136
137 static int reply_add_keyval (mt_reply_t *r, const char *key, /* {{{ */
138                 const char *val)
139 {
140         char **tmp;
141
142         tmp = realloc (r->keys, (r->params_num + 1) * sizeof (*tmp));
143         if (tmp == NULL)
144                 return (ENOMEM);
145         r->keys = tmp;
146
147         tmp = realloc (r->values, (r->params_num + 1) * sizeof (*tmp));
148         if (tmp == NULL)
149                 return (ENOMEM);
150         r->values = tmp;
151
152         r->keys[r->params_num] = strdup (key);
153         if (r->keys[r->params_num] == NULL)
154                 return (ENOMEM);
155
156         r->values[r->params_num] = strdup (val);
157         if (r->values[r->params_num] == NULL)
158         {
159                 free (r->keys[r->params_num]);
160                 r->keys[r->params_num] = NULL;
161                 return (ENOMEM);
162         }
163
164         r->params_num++;
165         return (0);
166 } /* }}} int reply_add_keyval */
167
168 static void reply_free (mt_reply_t *r) /* {{{ */
169 {
170         mt_reply_t *next;
171         unsigned int i;
172
173         if (r == NULL)
174                 return;
175
176         next = r->next;
177
178         for (i = 0; i < r->params_num; i++)
179         {
180                 free (r->keys[i]);
181                 free (r->values[i]);
182         }
183
184         free (r->keys);
185         free (r->values);
186
187         free (r);
188
189         reply_free (next);
190 } /* }}} void reply_free */
191
192 static int buffer_init (char **ret_buffer, size_t *ret_buffer_size) /* {{{ */
193 {
194         if ((ret_buffer == NULL) || (ret_buffer_size == NULL))
195                 return (EINVAL);
196
197         if (*ret_buffer_size < 1)
198                 return (EINVAL);
199
200         return (0);
201 } /* }}} int buffer_init */
202
203 static int buffer_add (char **ret_buffer, size_t *ret_buffer_size, /* {{{ */
204                 const char *string)
205 {
206         char *buffer;
207         size_t buffer_size;
208         size_t string_size;
209         size_t req_size;
210
211         if ((ret_buffer == NULL) || (ret_buffer_size == NULL) || (string == NULL))
212                 return (EINVAL);
213
214         buffer = *ret_buffer;
215         buffer_size = *ret_buffer_size;
216
217         string_size = strlen (string);
218         if (string_size == 0)
219                 return (EINVAL);
220
221         if (string_size >= 0x10000000)
222                 req_size = 5 + string_size;
223         else if (string_size >= 0x200000)
224                 req_size = 4 + string_size;
225         else if (string_size >= 0x4000)
226                 req_size = 3 + string_size;
227         else if (string_size >= 0x80)
228                 req_size = 2 + string_size;
229         else
230                 req_size = 1 + string_size;
231
232         if (*ret_buffer_size < req_size)
233                 return (ENOMEM);
234
235         if (string_size >= 0x10000000)
236         {
237                 buffer[0] = 0xF0;
238                 buffer[1] = (string_size >> 24) & 0xff;
239                 buffer[2] = (string_size >> 16) & 0xff;
240                 buffer[3] = (string_size >>  8) & 0xff;
241                 buffer[4] = (string_size      ) & 0xff;
242                 buffer += 5;
243                 buffer_size -= 5;
244         }
245         else if (string_size >= 0x200000)
246         {
247                 buffer[0] = (string_size >> 24) & 0x1f;
248                 buffer[0] |= 0xE0;
249                 buffer[1] = (string_size >> 16) & 0xff;
250                 buffer[2] = (string_size >>  8) & 0xff;
251                 buffer[3] = (string_size      ) & 0xff;
252                 buffer += 4;
253                 buffer_size -= 4;
254         }
255         else if (string_size >= 0x4000)
256         {
257                 buffer[0] = (string_size >> 16) & 0x3f;
258                 buffer[0] |= 0xC0;
259                 buffer[1] = (string_size >>  8) & 0xff;
260                 buffer[2] = (string_size      ) & 0xff;
261                 buffer += 3;
262                 buffer_size -= 3;
263         }
264         else if (string_size >= 0x80)
265         {
266                 buffer[0] = (string_size >>  8) & 0x7f;
267                 buffer[0] |= 0x80;
268                 buffer[1] = (string_size      ) & 0xff;
269                 buffer += 2;
270                 buffer_size -= 2;
271         }
272         else /* if (string_size <= 0x7f) */
273         {
274                 buffer[0] = (char) string_size;
275                 buffer += 1;
276                 buffer_size -= 1;
277         }
278
279         assert (buffer_size >= string_size);
280         memcpy (buffer, string, string_size);
281         buffer += string_size;
282         buffer_size -= string_size;
283
284         *ret_buffer = buffer;
285         *ret_buffer_size = buffer_size;
286
287         return (0);
288 } /* }}} int buffer_add */
289
290 static int buffer_end (char **ret_buffer, size_t *ret_buffer_size) /* {{{ */
291 {
292         if ((ret_buffer == NULL) || (ret_buffer_size == NULL))
293                 return (EINVAL);
294
295         if (*ret_buffer_size < 1)
296                 return (EINVAL);
297
298         /* Add empty word. */
299         (*ret_buffer)[0] = 0;
300         (*ret_buffer)++;
301         (*ret_buffer_size)--;
302
303         return (0);
304 } /* }}} int buffer_end */
305
306 static int send_command (mt_connection_t *c, /* {{{ */
307                 const char *command,
308                 size_t args_num, const char * const *args)
309 {
310         char buffer[4096];
311         char *buffer_ptr;
312         size_t buffer_size;
313
314         size_t i;
315         int status;
316
317         /* FIXME: For debugging only */
318         memset (buffer, 0, sizeof (buffer));
319
320         buffer_ptr = buffer;
321         buffer_size = sizeof (buffer);
322
323         status = buffer_init (&buffer_ptr, &buffer_size);
324         if (status != 0)
325                 return (status);
326
327         status = buffer_add (&buffer_ptr, &buffer_size, command);
328         if (status != 0)
329                 return (status);
330
331         for (i = 0; i < args_num; i++)
332         {
333                 if (args[i] == NULL)
334                         return (EINVAL);
335
336                 status = buffer_add (&buffer_ptr, &buffer_size, args[i]);
337                 if (status != 0)
338                         return (status);
339         }
340
341         status = buffer_end (&buffer_ptr, &buffer_size);
342         if (status != 0)
343                 return (status);
344
345         buffer_ptr = buffer;
346         buffer_size = sizeof (buffer) - buffer_size;
347         while (buffer_size > 0)
348         {
349                 ssize_t bytes_written;
350
351                 errno = 0;
352                 bytes_written = write (c->fd, buffer_ptr, buffer_size);
353                 if (bytes_written < 0)
354                 {
355                         if (errno == EAGAIN)
356                                 continue;
357                         else
358                                 return (errno);
359                 }
360                 assert (bytes_written <= buffer_size);
361
362                 buffer_ptr += bytes_written;
363                 buffer_size -= bytes_written;
364         } /* while (buffer_size > 0) */
365
366         return (0);
367 } /* }}} int send_command */
368
369 static int read_word (mt_connection_t *c, /* {{{ */
370                 char *buffer, size_t *buffer_size)
371 {
372         size_t req_size;
373         uint8_t word_length[5];
374         int status;
375
376         if ((buffer == NULL) || (*buffer_size < 1))
377                 return (EINVAL);
378
379         /* read one byte from the socket */
380         status = read_exact (c->fd, word_length, 1);
381         if (status != 0)
382                 return (status);
383
384         /* Calculate `req_size' */
385         if (((unsigned char) buffer[0]) == 0xF0) /* {{{ */
386         {
387                 status = read_exact (c->fd, &word_length[1], 4);
388                 if (status != 0)
389                         return (status);
390
391                 req_size = (buffer[1] << 24)
392                         | (buffer[2] << 16)
393                         | (buffer[3] << 8)
394                         | buffer[4];
395         }
396         else if ((buffer[0] & 0xE0) == 0xE0)
397         {
398                 status = read_exact (c->fd, &word_length[1], 3);
399                 if (status != 0)
400                         return (status);
401
402                 req_size = ((buffer[0] & 0x1F) << 24)
403                         | (buffer[1] << 16)
404                         | (buffer[2] << 8)
405                         | buffer[3];
406         }
407         else if ((buffer[0] & 0xC0) == 0xC0)
408         {
409                 status = read_exact (c->fd, &word_length[1], 2);
410                 if (status != 0)
411                         return (status);
412
413                 req_size = ((buffer[0] & 0x3F) << 16)
414                         | (buffer[1] << 8)
415                         | buffer[2];
416         }
417         else if ((buffer[0] & 0x80) == 0x80)
418         {
419                 status = read_exact (c->fd, &word_length[1], 1);
420                 if (status != 0)
421                         return (status);
422
423                 req_size = ((buffer[0] & 0x7F) << 8)
424                         | buffer[1];
425         }
426         else if ((buffer[0] & 0x80) == 0)
427         {
428                 req_size = (size_t) word_length[0];
429         }
430         else
431         {
432                 /* First nibble is `F' but second nibble is not `0'. */
433                 return (EPROTO);
434         } /* }}} */
435
436         if (*buffer_size < req_size)
437                 return (ENOMEM);
438
439         /* Empty word. This ends a `sentence' and must therefore be valid. */
440         if (req_size == 0)
441         {
442                 buffer[0] = 0;
443                 *buffer_size = 0;
444                 return (0);
445         }
446
447         status = read_exact (c->fd, buffer, req_size);
448         if (status != 0)
449                 return (status);
450         *buffer_size = req_size;
451
452         return (0);
453 } /* }}} int buffer_decode_next */
454
455 static mt_reply_t *receive_reply (mt_connection_t *c) /* {{{ */
456 {
457         char buffer[4096];
458         size_t buffer_size;
459         int status;
460
461         mt_reply_t *head;
462         mt_reply_t *tail;
463
464         head = NULL;
465         tail = NULL;
466
467         while (42)
468         {
469                 buffer_size = sizeof (buffer) - 1;
470                 status = read_word (c, buffer, &buffer_size);
471                 if (status != 0)
472                         break;
473                 assert (buffer_size < sizeof (buffer));
474                 buffer[buffer_size] = 0;
475
476                 /* Empty word means end of reply */
477                 if (buffer_size == 0)
478                         break;
479
480                 if (buffer[0] == '!') /* {{{ */
481                 {
482                         mt_reply_t *tmp;
483
484                         tmp = reply_alloc ();
485                         if (tmp == NULL)
486                         {
487                                 status = ENOMEM;
488                                 break;
489                         }
490
491                         tmp->status = strdup (&buffer[1]);
492                         if (tmp->status == NULL)
493                         {
494                                 reply_free (tmp);
495                                 status = ENOMEM;
496                                 break;
497                         }
498
499                         if (tail == NULL)
500                         {
501                                 head = tmp;
502                                 tail = tmp;
503                         }
504                         else
505                         {
506                                 tail->next = tmp;
507                                 tail = tmp;
508                         }
509                 } /* }}} if (buffer[0] == '!') */
510                 else if (buffer[0] == '=') /* {{{ */
511                 {
512                         char *key = &buffer[1];
513                         char *val;
514
515                         key = &buffer[1];
516                         val = strchr (key, '=');
517                         if (val == NULL)
518                         {
519                                 fprintf (stderr, "Ignoring misformed word: %s\n", buffer);
520                                 continue;
521                         }
522                         *val = 0;
523                         val++;
524
525                         reply_add_keyval (tail, key, val);
526                 } /* }}} if (buffer[0] == '=') */
527                 else
528                 {
529                         printf ("Ignoring unknown word: %s\n", buffer);
530                 }
531         } /* while (42) */
532         
533         if (status != 0)
534         {
535                 reply_free (head);
536                 return (NULL);
537         }
538
539         return (head);
540 } /* }}} mt_reply_t *receive_reply */
541
542 static int create_socket (const char *node, const char *service) /* {{{ */
543 {
544         struct addrinfo  ai_hint;
545         struct addrinfo *ai_list;
546         struct addrinfo *ai_ptr;
547         int status;
548
549         mt_debug ("create_socket (node = %s, service = %s);\n",
550                         node, service);
551
552         memset (&ai_hint, 0, sizeof (ai_hint));
553 #ifdef AI_ADDRCONFIG
554         ai_hint.ai_flags |= AI_ADDRCONFIG;
555 #endif
556         ai_hint.ai_family = AF_UNSPEC;
557         ai_hint.ai_socktype = SOCK_STREAM;
558
559         ai_list = NULL;
560         status = getaddrinfo (node, service, &ai_hint, &ai_list);
561         if (status != 0)
562                 return (-1);
563         assert (ai_list != NULL);
564
565         for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
566         {
567                 int fd;
568                 int status;
569
570                 fd = socket (ai_ptr->ai_family, ai_ptr->ai_socktype,
571                                 ai_ptr->ai_protocol);
572                 if (fd < 0)
573                 {
574                         mt_debug ("create_socket: socket(2) failed.\n");
575                         continue;
576                 }
577
578                 status = connect (fd, ai_ptr->ai_addr, ai_ptr->ai_addrlen);
579                 if (status != 0)
580                 {
581                         mt_debug ("create_socket: connect(2) failed.\n");
582                         close (fd);
583                         continue;
584                 }
585
586                 return (fd);
587         }
588
589         freeaddrinfo (ai_list);
590
591         return (-1);
592 } /* }}} int create_socket */
593
594 static int login2_handler (mt_connection_t *c, const mt_reply_t *r, /* {{{ */
595                 void *user_data)
596 {
597         if (r == NULL)
598                 return (EINVAL);
599
600         printf ("login2_handler has been called.\n");
601
602         return (0);
603 } /* }}} int login2_handler */
604
605 static void hash_binary_to_hex (char hex[33], uint8_t binary[16]) /* {{{ */
606 {
607         int i;
608
609         for (i = 0; i < 16; i++)
610         {
611                 char tmp[3];
612                 snprintf (tmp, 3, "%02"PRIx8, binary[i]);
613                 tmp[2] = 0;
614                 hex[2*i] = tmp[0];
615                 hex[2*i+1] = tmp[1];
616         }
617         hex[32] = 0;
618 } /* }}} void hash_binary_to_hex */
619
620 static void hash_hex_to_binary (uint8_t binary[16], char hex[33]) /* {{{ */
621 {
622         int i;
623
624         for (i = 0; i < 16; i++)
625         {
626                 char tmp[3];
627
628                 tmp[0] = hex[2*i];
629                 tmp[1] = hex[2*i + 1];
630                 tmp[2] = 0;
631
632                 binary[i] = (uint8_t) strtoul (tmp, /* endptr = */ NULL, /* base = */ 16);
633         }
634 } /* }}} void hash_hex_to_binary */
635
636 static void make_password_hash (char response_hex[33], /* {{{ */
637                 const char *password, size_t password_length, char challenge_hex[33])
638 {
639         uint8_t challenge_bin[16];
640         uint8_t response_bin[16];
641         char data_buffer[password_length+17];
642         gcry_md_hd_t md_handle;
643
644         hash_hex_to_binary (challenge_bin, challenge_hex);
645
646         data_buffer[0] = 0;
647         memcpy (&data_buffer[1], password, password_length);
648         memcpy (&data_buffer[1+password_length], challenge_bin, 16);
649
650         gcry_md_open (&md_handle, GCRY_MD_MD5, /* flags = */ 0);
651         gcry_md_write (md_handle, data_buffer, sizeof (data_buffer));
652         memcpy (response_bin, gcry_md_read (md_handle, GCRY_MD_MD5), 16);
653         gcry_md_close (md_handle);
654
655         hash_binary_to_hex (response_hex, response_bin);
656 } /* }}} void make_password_hash */
657
658 static int login_handler (mt_connection_t *c, const mt_reply_t *r, /* {{{ */
659                 void *user_data)
660 {
661         const char *ret;
662         char challenge_hex[33];
663         char response_hex[33];
664         mt_login_data_t *login_data;
665
666         const char *params[2];
667         char param_name[1024];
668         char param_response[64];
669
670         if (r == NULL)
671                 return (EINVAL);
672
673         printf ("login_handler has been called.\n");
674
675         login_data = user_data;
676         if (login_data == NULL)
677                 return (EINVAL);
678
679         ret = mt_reply_param_val_by_key (r, "ret");
680         if (ret == NULL)
681         {
682                 mt_debug ("login_handler: Reply does not have parameter \"ret\".\n");
683                 return (EPROTO);
684         }
685         mt_debug ("login_handler: ret = %s;\n", ret);
686
687         if (strlen (ret) != 32)
688         {
689                 mt_debug ("login_handler: Unexpected length of the \"ret\" argument.\n");
690                 return (EPROTO);
691         }
692         strcpy (challenge_hex, ret);
693
694         make_password_hash (response_hex, 
695                         login_data->password, strlen (login_data->password),
696                         challenge_hex);
697
698         snprintf (param_name, sizeof (param_name), "=name=%s", login_data->username);
699         snprintf (param_response, sizeof (param_response),
700                         "=response=00%s", response_hex);
701         params[0] = param_name;
702         params[1] = param_response;
703
704         return (mt_query (c, "/login", 2, params, login2_handler,
705                                 /* user data = */ NULL));
706 } /* }}} int login_handler */
707
708 /*
709  * Public functions
710  */
711 mt_connection_t *mt_connect (const char *node, const char *service, /* {{{ */
712                 const char *username, const char *password)
713 {
714         int fd;
715         mt_connection_t *c;
716         int status;
717         mt_login_data_t user_data;
718
719         if ((node == NULL) || (username == NULL) || (password == NULL))
720                 return (NULL);
721
722         fd = create_socket (node, (service != NULL) ? service : ROUTEROS_API_PORT);
723         if (fd < 0)
724                 return (NULL);
725
726         c = malloc (sizeof (*c));
727         if (c == NULL)
728         {
729                 close (fd);
730                 return (NULL);
731         }
732         memset (c, 0, sizeof (*c));
733
734         c->fd = fd;
735
736         user_data.username = username;
737         user_data.password = password;
738         status = mt_query (c, "/login", /* args num = */ 0, /* args = */ NULL,
739                         login_handler, &user_data);
740
741         return (c);
742 } /* }}} mt_connection_t *mt_connect */
743
744 int mt_disconnect (mt_connection_t *c) /* {{{ */
745 {
746         if (c == NULL)
747                 return (EINVAL);
748
749         if (c->fd >= 0)
750         {
751                 close (c->fd);
752                 c->fd = -1;
753         }
754
755         free (c);
756
757         return (0);
758 } /* }}} int mt_disconnect */
759
760 int mt_query (mt_connection_t *c, /* {{{ */
761                 const char *command,
762                 size_t args_num, const char * const *args,
763                 mt_reply_handler_t handler, void *user_data)
764 {
765         int status;
766         mt_reply_t *r;
767
768         status = send_command (c, command, args_num, args);
769         if (status != 0)
770                 return (status);
771
772         r = receive_reply (c);
773         if (r == NULL)
774                 return (EPROTO);
775
776         /* Call the callback function with the data we received. */
777         status = (*handler) (c, r, user_data);
778
779         /* Free the allocated memory ... */
780         reply_free (r);
781
782         /* ... and return. */
783         return (status);
784 } /* }}} int mt_query */
785
786 const mt_reply_t *mt_reply_next (const mt_reply_t *r) /* {{{ */
787 {
788         if (r == NULL)
789                 return (NULL);
790
791         return (r->next);
792 } /* }}} mt_reply_t *mt_reply_next */
793
794 int mt_reply_num (const mt_reply_t *r) /* {{{ */
795 {
796         int ret;
797         const mt_reply_t *ptr;
798
799         ret = 0;
800         for (ptr = r; ptr != NULL; ptr = ptr->next)
801                 ret++;
802
803         return (ret);
804 } /* }}} int mt_reply_num */
805
806 const char *mt_reply_status (const mt_reply_t *r) /* {{{ */
807 {
808         if (r == NULL)
809                 return (NULL);
810         return (r->status);
811 } /* }}} char *mt_reply_status */
812
813 const char *mt_reply_param_key_by_index (const mt_reply_t *r, /* {{{ */
814                 unsigned int index)
815 {
816         if (r == NULL)
817                 return (NULL);
818
819         if (index >= r->params_num)
820                 return (NULL);
821
822         return (r->keys[index]);
823 } /* }}} char *mt_reply_param_key_by_index */
824
825 const char *mt_reply_param_val_by_index (const mt_reply_t *r, /* {{{ */
826                 unsigned int index)
827 {
828         if (r == NULL)
829                 return (NULL);
830
831         if (index >= r->params_num)
832                 return (NULL);
833
834         return (r->values[index]);
835 } /* }}} char *mt_reply_param_key_by_index */
836
837 const char *mt_reply_param_val_by_key (const mt_reply_t *r, /* {{{ */
838                 const char *key)
839 {
840         unsigned int i;
841
842         if ((r == NULL) || (key == NULL))
843                 return (NULL);
844
845         for (i = 0; i < r->params_num; i++)
846                 if (strcmp (r->keys[i], key) == 0)
847                         return (r->values[i]);
848
849         return (NULL);
850 } /* }}} char *mt_reply_param_val_by_key */
851
852 /* vim: set ts=2 sw=2 noet fdm=marker : */