Logo Search packages:      
Sourcecode: ldns version File versions  Download package

ldns_status ldns_rr_new_frm_fp_l ( ldns_rr **  rr,
FILE *  fp,
uint16_t *  default_ttl,
ldns_rdf **  origin,
ldns_rdf **  prev,
int *  line_nr 
)

creates a new rr from a file containing a string.

Parameters:
[out] rr the new rr
[in] fp the file pointer to use
[in] fp the file pointer to use
[in] default_ttl a default ttl for the rr. If 0 DEF_TTL will be used the pointer will be updated if the file contains a $TTL directive The caller must ldns_rdf_deep_free it.
[in] origin when the owner is relative add this the pointer will be updated if the file contains a $ORIGIN directive The caller must ldns_rdf_deep_free it.
[in] line_nr pointer to an integer containing the current line number (for debugging purposes)
[in] prev when the owner is whitespaces use this as the * ownername the pointer will be updated after the call
Returns:
a ldns_status with an error or LDNS_STATUS_OK

Definition at line 478 of file rr.c.

References ldns_fget_token_l(), ldns_rdf_deep_free(), ldns_rdf_new_frm_str(), LDNS_RDF_TYPE_DNAME, ldns_rr_new_frm_fp_l(), ldns_rr_new_frm_str(), and ldns_str2period().

Referenced by ldns_rr_new_frm_fp(), ldns_rr_new_frm_fp_l(), and ldns_zone_new_frm_fp_l().

{
        char *line;
      const char *endptr;  /* unused */
      ldns_rr *rr;
      char *keyword;
      uint16_t ttl;
      ldns_rdf *tmp;
      ldns_status s;
      ssize_t size;

      s = LDNS_STATUS_ERR;
      if (default_ttl) {
            ttl = *default_ttl;
      } else {
            ttl = 0;
      }

        line = LDNS_XMALLOC(char, LDNS_MAX_LINELEN + 1);
        if (!line) {
                return LDNS_STATUS_MEM_ERR;
        }

        /* read an entire line in from the file */
        if ((size = ldns_fget_token_l(fp, line, LDNS_PARSE_SKIP_SPACE, LDNS_MAX_LINELEN, line_nr)) == -1) {
            LDNS_FREE(line);
            /* if last line was empty, we are now at feof, which is not
             * always a parse error (happens when for instance last line
             * was a comment)
             */
                return LDNS_STATUS_SYNTAX_ERR;
        }

      /* we can have the situation, where we've read ok, but still got
       * no bytes to play with, in this case size is 0 
       */
      if (size == 0) {
            LDNS_FREE(line);
            return LDNS_STATUS_SYNTAX_EMPTY;
      }
      
      if ((keyword = strstr(line, "$ORIGIN "))) {
            if (*origin) {
                  ldns_rdf_deep_free(*origin);
                  *origin = NULL;
            }
            tmp = ldns_rdf_new_frm_str(LDNS_RDF_TYPE_DNAME, keyword + 8);
            if (!tmp) {
                  /* could not parse what next to $ORIGIN */
                  LDNS_FREE(line);
                  return LDNS_STATUS_SYNTAX_DNAME_ERR;
            }
            *origin = tmp;
            s = LDNS_STATUS_SYNTAX_ORIGIN;            
      } else if ((keyword = strstr(line, "$TTL "))) {
            if (default_ttl) {
                  *default_ttl = ldns_str2period(keyword + 5, &endptr);
            }
            s = LDNS_STATUS_SYNTAX_TTL;
      } else {
            if (origin && *origin) {
                  s = ldns_rr_new_frm_str(&rr, (const char*) line, ttl, *origin, prev);
            } else {
                  s = ldns_rr_new_frm_str(&rr, (const char*) line, ttl, NULL, prev);
            }
      
      }
      LDNS_FREE(line);
      if (newrr && s == LDNS_STATUS_OK) {
            *newrr = rr;
      }
      return s;
}


Generated by  Doxygen 1.6.0   Back to index