}
return (int)ldns_buffer_read_u8(buffer);
}
-
-/* fast forwards the buffer, skipping the given char, setting the
- * buffer position to the location of the first different char
- * (or to the end of the buffer)
- */
-void
-ldns_bskipc(ldns_buffer *buffer, char c)
-{
- while (c == (char) ldns_buffer_read_u8_at(buffer, ldns_buffer_position(buffer))) {
- if (ldns_buffer_available_at(buffer, buffer->_position + sizeof(char), sizeof(char))) {
- buffer->_position += sizeof(char);
- } else {
- return;
- }
- }
-}
-
-/* fast forwards the buffer, skipping all chars in the given string,
- * setting the buffer position to the first char that is not contained
- * in the string (or to the end of the buffer)
- */
-void
-ldns_bskipcs(ldns_buffer *buffer, const char *s)
-{
- bool found;
- char c;
- char *d;
-
- while(ldns_buffer_available_at(buffer, buffer->_position, sizeof(char))) {
- c = (char) ldns_buffer_read_u8_at(buffer,
- buffer->_position);
- found = false;
- for (d = (char *) s; *d; d++) {
- if (*d == c) {
- found = true;
- }
- }
- if (found && buffer->_limit > buffer->_position) {
- buffer->_position += sizeof(char);
- } else {
- return;
- }
- }
-}
-
-
*/
void *ldns_buffer_export(ldns_buffer *buffer);
-/*
- * Get the next character from a buffer. Advance the position
- * pointer with 1.
- * When end of buffer is reached return EOF
- */
-int ldns_bgetc(ldns_buffer *buffer);
-
-/**
- * Skip all of the characters in the given string in the buffer, moving
- * the position to the first character that is not in *s
- */
-void ldns_bskipcs(ldns_buffer *buffer, const char *s);
-
#endif /* _BUFFER_H_ */
#include <ldns/buffer.h>
-#define LDNS_PARSE_SKIP_SPACE "\f\n\r\t\v"
+#define LDNS_PARSE_SKIP_SPACE "\f\n\r\v"
#define LDNS_PARSE_NORMAL " \f\n\r\t\v"
#define MAXLINE_LEN 512
#define MAXKEYWORD_LEN 32
*/
char * ldns_str_remove_comment(char *str);
-#endif /* _PARSE_H_ */
+/*
+ * Get the next character from a buffer. Advance the position
+ * pointer with 1.
+ * When end of buffer is reached return EOF
+ */
+int ldns_bgetc(ldns_buffer *buffer);
+
+/**
+ * Skip all of the characters in the given string in the buffer, moving
+ * the position to the first character that is not in *s
+ */
+void ldns_bskipcs(ldns_buffer *buffer, const char *s);
+
+/**
+ * Skip all of the characters in the given string in the fp, moving
+ * the position to the first character that is not in *s
+ */
+void ldns_fskipcs(FILE *fp, const char *s);
+
+
+
+
+
+
+#endif /* _PARSE_H */
}
/* walk along the file until you get a hit */
+/* number of occurences.... !! */
ssize_t
ldns_fget_all_keyword_data(FILE *f, const char *keyword, const char *k_del, char *data,
const char *d_del)
if (p < 0) {
/* more ) then ( - close off the string */
*t = '\0';
- return -1;
+ return 0;
}
if (c == '\n' && p != 0) {
}
}
*t = '\0';
+ if (i == 0) {
+ /* nothing read */
+ return -1;
+ }
if (p != 0) {
return -1;
}
- return 0;
+ return (ssize_t)i;
tokenread:
- /* skip something here too; ldns_fskipc(f, del) */
+ ldns_fskipcs(f, del);
*t = '\0';
if (p != 0) {
return -1;
return -1;
}
}
-
*t = '\0';
if (i == 0) {
/* nothing read */
}
return str2;
}
+
+/* fast forwards the buffer, skipping the given char, setting the
+ * buffer position to the location of the first different char
+ * (or to the end of the buffer)
+ */
+void
+ldns_bskipc(ldns_buffer *buffer, char c)
+{
+ while (c == (char) ldns_buffer_read_u8_at(buffer, ldns_buffer_position(buffer))) {
+ if (ldns_buffer_available_at(buffer, buffer->_position + sizeof(char), sizeof(char))) {
+ buffer->_position += sizeof(char);
+ } else {
+ return;
+ }
+ }
+}
+
+/* fast forwards the buffer, skipping all chars in the given string,
+ * setting the buffer position to the first char that is not contained
+ * in the string (or to the end of the buffer)
+ */
+void
+ldns_bskipcs(ldns_buffer *buffer, const char *s)
+{
+ bool found;
+ char c;
+ char *d;
+
+ while(ldns_buffer_available_at(buffer, buffer->_position, sizeof(char))) {
+ c = (char) ldns_buffer_read_u8_at(buffer,
+ buffer->_position);
+ found = false;
+ for (d = (char *) s; *d; d++) {
+ if (*d == c) {
+ found = true;
+ }
+ }
+ if (found && buffer->_limit > buffer->_position) {
+ buffer->_position += sizeof(char);
+ } else {
+ return;
+ }
+ }
+}
+
+void
+ldns_fskipc(FILE *fp, char c)
+{
+
+
+}
+
+
+void
+ldns_fskipcs(FILE *fp, const char *s)
+{
+ bool found;
+ char c;
+ char *d;
+
+ while ((c = fgetc(fp)) != EOF) {
+ found = false;
+ for (d = (char *) s; *d; d++) {
+ if (*d == c) {
+ found = true;
+ }
+ }
+ if (!found) {
+ /* with getc, we've read too far */
+ ungetc(c, fp);
+ return;
+ }
+ }
+}
keyword[0] = "domain";
keyword[1] = "nameserver";
word = XMALLOC(char, MAXLINE_LEN);
- expect = 0;
+ expect = RESOLV_KEYWORD;
r = ldns_resolver_new();
if (!r) {
return NULL;
}
-
gtr = ldns_fget_token(fp, word, LDNS_PARSE_NORMAL, 0);
while (gtr > 0) {
/* do something */
}
/* no keyword recognized */
if (expect == 0) {
- /* dprintf("[%s] unreg keyword\n", word); */
+ dprintf("[%s] unreg keyword\n", word);
}
break;
case RESOLV_DEFDOMAIN:
604800 \n\
3600 \n\
)";
- soa_string2 = "miek.nl. 3600 IN SOA elektron.atoom.net. miekg.atoom.net. \
+ soa_string2 = "miek.nl. 3600 IN SOA elektron.atoom.net. miekg.atoom.net. (\
2002120700 ; serial \n\
21600 ; more shit\n\
7200 ; ahh retry \n\
604800 ; meaningless number to annoy me\n\
-3600 ; negative caching";
+3600 ; negative caching\n\
+)";
rr = ldns_rr_new_frm_str(soa_string1);
ldns_rr_print(stdout, rr);
int
main()
{
- FILE *f;
- char *tok;
- size_t b;
+ ldns_resolver *r;
- if (!(f = fopen("blaat", "r"))) {
- exit(1);
+ r = ldns_resolver_new_frm_file(NULL);
+ if (!r) {
+ printf("something wrong?\n");
}
- tok = XMALLOC(char, 1024);
-
- while ((b = ldns_get_token(f, tok, LDNS_PARSE_SKIP_SPACE)) != 0) {
- fprintf(stdout, "%d: %s\n", (int)b, tok);
- }
- fclose(f);
-
- if (!(f = fopen("Kdnssec.nl.+005+32820.private", "r"))) {
- exit(1);
- }
-
- /* ldns_get_keyword_data(f, "Algorithm", ": \t", tok, LDNS_STR);*/
- if (ldns_get_keyword_data(f, "Private-key-format",
- ":", tok, LDNS_PARSE_SKIP_SPACE) != -1) {
- printf("found it, found it\n");
- printf("%s\n", tok);
- }
-
- fclose(f);
+ ldns_resolver_print(stdout, r);
return 0;
}
#include <ldns/rr.h>
-/* #define dprintf(X,Y) printf((X), (Y)) */
-#define dprintf(X, Y)
+#define dprintf(X,Y) printf((X), (Y))
+/* #define dprintf(X, Y) */
/**
* splint static inline workaround