Exemplo n.º 1
0
int printer_anon_map_entry_print_node(PrinterBase_ptr self,
                                      node_ptr n,
                                      int priority)
{
  const NuSMVEnv_ptr env = EnvObject_get_environment(ENV_OBJECT(self));
  const ErrorMgr_ptr errmgr =
    ERROR_MGR(NuSMVEnv_get_value(env, ENV_ERROR_MANAGER));

  if (Nil == n) return 1;
  
  switch(node_get_type(n)) {
  case DOT:
    {
      /* since "." is also a separator, we can skip print the "," if
         immediately followed by "." */
      return
        _PRINT(NODE_ANONYMIZER_DOT_STR) &&
        _THROW(car(n)) &&
        ((Nil != cdr(n) && DOT == node_get_type(cdr(n))) || _PRINT(NODE_ANONYMIZER_SEPARATOR_STR)) &&
        _THROW(cdr(n));
    }

  case ATOM:
    /* Here ideally we would let the PrinterWffCore handle it. We can't because
       PrinterWffCore and this printer both handle DOT nodes. So we are
       duplicating the PrinterWffCore code for ATOM and NUMBER */
    if (!_PRINT(UStringMgr_get_string_text((string_ptr) car(n)))) return 0;
    if (cdr(n)) {
      char buf[20];
      int chars = snprintf(buf, 20, "_%d", NODE_TO_INT(cdr(n)));
      SNPRINTF_CHECK(chars, 20);

      return _PRINT(buf);
    }
    return 1;

  case NUMBER:
    {
      char buf[20];
      int c = snprintf(buf, 20, "%d", NODE_TO_INT(car(n)));
      SNPRINTF_CHECK(c, 20);

      return _PRINT(buf);
    }
    /* end of code duplication */

  default:
    ErrorMgr_internal_error(errmgr, "%s: not supported type = %d",
                            __func__,
                            node_get_type(n));
  }
}
Exemplo n.º 2
0
/*
 * http_build_header - create a header string
 * Will eventually want to expand this if we want to specify
 * content type, etc.
 */
int http_build_header (char *buffer,
		       uint32_t maxlen,
		       uint32_t *at,
		       http_client_t *cptr,
		       const char *method,
		       const char *add_header,
		       char *content_body)
{
  int ret;
#define SNPRINTF_CHECK(fmt, value) \
  ret = snprintf(buffer + *at, maxlen - *at, (fmt), value); \
  if (ret == -1) { \
    return (-1); \
  }\
  *at += ret;

  SNPRINTF_CHECK("%s ", method);
  if (cptr->m_content_location != NULL && 
      (strcmp(cptr->m_content_location, "/") != 0 ||
       *cptr->m_resource != '/')) {
    SNPRINTF_CHECK("%s", cptr->m_content_location);
  } 
  SNPRINTF_CHECK("%s HTTP/1.1\r\n",
		 cptr->m_resource);
  SNPRINTF_CHECK("Host: %s\r\n",
		 cptr->m_host);
  SNPRINTF_CHECK("User-Agent: %s\r\n", user_agent);
  SNPRINTF_CHECK("Connection: Keep-Alive%s", "\r\n");
  if (add_header != NULL) {
    SNPRINTF_CHECK("%s\r\n", add_header);
  }
  if (content_body != NULL) {
    int len = strlen(content_body);
    SNPRINTF_CHECK("Content-length: %d\r\n\r\n", len);
    SNPRINTF_CHECK("%s", content_body);
  } else {
    SNPRINTF_CHECK("%s", "\r\n");
  }
#undef SNPRINTF_CHECK
  return (ret);
}