Example #1
0
/**
 * The device is specified from UserAgent. 
 * @param r Request_rec is appointed.
 * @param userAgent UserAgent is appointed here,
 * @return The style which corresponds is returned.
 */
device_table *
chxj_specified_device(request_rec *r, const char *user_agent) 
{
  device_table         *dt = &UNKNOWN_DEVICE;
  mod_chxj_config      *conf;
  mod_chxj_req_config  *request_conf;
  
  DBG(r, "REQ[%X] start %s()", TO_ADDR(r),__func__);

  request_conf = chxj_get_req_config(r);
  if (user_agent) {
    request_conf->user_agent = apr_pstrdup(r->pool, user_agent);
  }
  else {
    request_conf->user_agent = "";
  }
  
  conf = chxj_get_module_config(r->per_dir_config, &chxj_module);
  if(! user_agent){
    request_conf->spec = dt;
    DBG(r, "REQ[%X] end %s() %d", TO_ADDR(r), __func__,conf->detect_device_type);
    return dt;
  }
  
  dt = s_specified_device_from_xml(r,conf, user_agent);

  if (conf->detect_device_type == CHXJ_ADD_DETECT_DEVICE_TYPE_TSV ){
    s_specified_device_from_tsv(r,dt,user_agent);
  }
  /* save to spec cache */
  request_conf->spec = dt;
  
  DBG(r, "REQ[%X] end %s() %d",TO_ADDR(r), __func__,conf->detect_device_type);
  return dt;
}
Example #2
0
static void
s_send_request_to_google_analytics(request_rec *r, const char *utm_url)
{
  apr_pool_t *ppool;
  apr_size_t response_len;
  char *data;
  int ii;
  request_rec *get_r;
  mod_chxj_config *conf;

  DBG(r, "REQ[%X] start %s()", TO_ADDR(r),__func__);
  apr_pool_create(&ppool, r->pool);
  get_r = apr_palloc(ppool, sizeof(request_rec));
  memset(get_r, 0, sizeof(request_rec));
  get_r->pool = ppool;
  get_r->headers_in = apr_table_make(ppool, 4);
  get_r->headers_out = apr_table_make(ppool, 4);
  
  apr_table_setn(get_r->headers_in, "User-Agent",apr_table_get(r->headers_in, "User-Agent"));
  apr_table_setn(get_r->headers_in, "Host", DL_GOOGLE_HOST);

  // ichiou data ni totte oku. tsukawanai kedo.
  data = chxj_serf_get(get_r, ppool, utm_url, 0, &response_len);
  DBG(r, "REQ[%X] response from google:[%s]", TO_ADDR(r), data);
  conf = chxj_get_module_config(r->per_dir_config, &chxj_module);
  if (conf->google_analytics_debug && *conf->google_analytics_debug) {
    FILE *fp;
    if ((fp = fopen(conf->google_analytics_debug, "w")) != NULL) {
      fwrite(data, response_len, 1, fp);
      fclose(fp);
    }
  }
  
  DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
}
Example #3
0
/**
 * style attribute parser.
 * @return merged new css_stylesheet_t object.
 */
css_stylesheet_t *
chxj_css_parse_style_attr(Doc *doc, css_stylesheet_t *old_stylesheet, char *tag_name, char *class_name, char *id_name, char *style_attr_value)
{
  css_stylesheet_t *new_stylesheet;
  css_stylesheet_t *dup_stylesheet = NULL;
  char *attr_value;
  char *class_name_sel = NULL;
  char *id_name_sel    = NULL;

  DBG(doc->r,"REQ[%X] start %s()",TO_ADDR(doc->r),__func__);

  if (class_name) {
    class_name_sel = apr_psprintf(doc->pool, ".%s", class_name);
  }
  if (id_name) {
    id_name_sel = apr_psprintf(doc->pool, "#%s", id_name);
  }

  attr_value = apr_psprintf(doc->pool, 
                            "%s%s%s { %s; }",
                            tag_name, 
                            (class_name) ?  class_name_sel : "",
                            (id_name)    ?  id_name_sel    : "",
                            style_attr_value);

  if (old_stylesheet) {
    dup_stylesheet = s_dup_stylesheet(doc, old_stylesheet);
  }
  new_stylesheet = s_chxj_css_parse_from_buf(doc->r, doc->pool, NULL, dup_stylesheet, attr_value);

  DBG(doc->r,"REQ[%X] end %s()",TO_ADDR(doc->r),__func__);
  return new_stylesheet;
}
Example #4
0
/**
 * The device is specified from UserAgent. 
 * @param r Request_rec is appointed.
 * @param userAgent UserAgent is appointed here,
 * @return The style which corresponds is returned.
 */
static device_table *
s_specified_device_from_xml(request_rec *r, mod_chxj_config * conf, const char *user_agent) 
{
  ap_regmatch_t        match[10];
  device_table         *returnType = &UNKNOWN_DEVICE;
  device_table_list    *dtl;
  device_table         *dt;
  char                 *device_id;

  DBG(r, "REQ[%X] start %s()", TO_ADDR(r),__func__);
  if (! user_agent) {
    DBG(r, "REQ[%X] end %s() (user_agent is not set)", TO_ADDR(r),__func__);
    return returnType;
  }
            


  if (! conf->devices) {
    ERR(r, "REQ[%X] device_data.xml load failure", TO_ADDR(r));
    DBG(r, "REQ[%X] end %s()", TO_ADDR(r), __func__);
    return returnType;
  }

  for (dtl = conf->devices; dtl; dtl = dtl->next) {
    if (! dtl->pattern) {
      continue;
    }

    /* DBG(r, "pattern is [%s]", dtl->pattern); */
    if (! dtl->regexp) {
      ERR(r,"REQ[%X] compile failed.", TO_ADDR(r));
      DBG(r, "REQ[%X] %s()", TO_ADDR(r),__func__);
      return returnType;
    }

    if (ap_regexec((const ap_regex_t *)dtl->regexp, user_agent, (apr_size_t)dtl->regexp->re_nsub + 1, match, 0) == 0) {
      device_id = ap_pregsub(r->pool, "$1", user_agent, dtl->regexp->re_nsub + 1, match);
      DBG(r, "REQ[%X] device_id:[%s]", TO_ADDR(r), device_id);

      dt = s_get_device_data(r, device_id, dtl);
      if (! dt) {
        dt = dtl->tail;
        if (dt){
          if (conf->detect_device_type > CHXJ_ADD_DETECT_DEVICE_TYPE_NONE ){
            dt->device_id = device_id;
          }
          DBG(r,"REQ[%X] end %s() (Not Found) use [%s]", TO_ADDR(r), __func__, dt->device_id);
          return dt;
        }
      }
      DBG(r,"REQ[%X] end %s() (Found) use [%s]", TO_ADDR(r), __func__, dt->device_id);
      return dt;
    }
  }

  DBG(r,"REQ[%X] end %s()", TO_ADDR(r), __func__);

  return returnType;
}
Example #5
0
void MySensor::begin(void (*_msgCallback)(const MyMessage &), uint8_t _nodeId, boolean _repeaterMode, uint8_t _parentNodeId, rf24_pa_dbm_e paLevel, uint8_t channel, rf24_datarate_e dataRate) {
	Serial.begin(BAUD_RATE);
	isGateway = false;
	repeaterMode = _repeaterMode;
	msgCallback = _msgCallback;

	if (repeaterMode) {
		setupRepeaterMode();
	}
	setupRadio(paLevel, channel, dataRate);

	// Read settings from EEPROM
	eeprom_read_block((void*)&nc, (void*)EEPROM_NODE_ID_ADDRESS, sizeof(NodeConfig));
	// Read latest received controller configuration from EEPROM
	eeprom_read_block((void*)&cc, (void*)EEPROM_LOCAL_CONFIG_ADDRESS, sizeof(ControllerConfig));
	if (cc.isMetric == 0xff) {
		// Eeprom empty, set default to metric
		cc.isMetric = 0x01;
	}

	if (_parentNodeId != AUTO) {
		nc.parentNodeId = _parentNodeId;
		autoFindParent = false;
	} else {
		autoFindParent = true;
	}

	if (_nodeId != AUTO) {
		// Set static id
		nc.nodeId = _nodeId;
	}

	// If no parent was found in eeprom. Try to find one.
	if (autoFindParent && nc.parentNodeId == 0xff) {
		findParentNode();
	}

	// Try to fetch node-id from gateway
	if (nc.nodeId == AUTO) {
		requestNodeId();
	}

	debug(PSTR("%s started, id %d\n"), repeaterMode?"repeater":"sensor", nc.nodeId);

	// Open reading pipe for messages directed to this node (set write pipe to same)
	RF24::openReadingPipe(WRITE_PIPE, TO_ADDR(nc.nodeId));
	RF24::openReadingPipe(CURRENT_NODE_PIPE, TO_ADDR(nc.nodeId));

	// Send presentation for this radio node (attach
	present(NODE_SENSOR_ID, repeaterMode? S_ARDUINO_REPEATER_NODE : S_ARDUINO_NODE);

	// Send a configuration exchange request to controller
	// Node sends parent node. Controller answers with latest node configuration
	// which is picked up in process()
	sendRoute(build(msg, nc.nodeId, GATEWAY_ADDRESS, NODE_SENSOR_ID, C_INTERNAL, I_CONFIG, false).set(nc.parentNodeId));

	// Wait configuration reply.
	waitForReply();
}
Example #6
0
static void
s_write_gif_data(request_rec *r)
{
  DBG(r, "REQ[%X] start %s()", TO_ADDR(r),__func__);
  apr_table_setn(r->headers_out, "Content-Type", "image/gif");
  apr_table_setn(r->headers_out, "Cache-Control","private, no-cache, no-cache=Set-Cookie, proxy-revalidate");
  apr_table_setn(r->headers_out, "Pragma",       "no-cache");
  apr_table_setn(r->headers_out, "Expires",      "Wed, 17 Sep 1975 21:32:10 GMT");
  apr_table_setn(r->headers_out, "Content-Length", "35");
  ap_rwrite(v_GIF_DATA, 35, r);
  DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
}
Example #7
0
static char *
s_get_visitor_id(request_rec *r, const char *guid, const char *account, const char *user_agent, const char *cookie_str)
{
  unsigned char       *md5_value;
  apr_status_t        retval;
  char                *visitor_id;

  DBG(r, "REQ[%X] start %s()", TO_ADDR(r),__func__);

  if (cookie_str && *cookie_str != 0) {
    DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
    return (char *)cookie_str;
  }
  if (! account) {
    ERR(r, "Please set ChxjGoogleAnalyticsAccount");
  }


  char *message = "";
  if (guid && *guid != 0) {
    message = apr_psprintf(r->pool, "%s%s", guid, account);
  }
  else {
    message = apr_psprintf(r->pool, "%s%s", user_agent, s_uniqid(r));
  }

  md5_value = (unsigned char*)apr_palloc(r->pool, APR_MD5_DIGESTSIZE + 1);
  memset(md5_value, 0, APR_MD5_DIGESTSIZE + 1);

  retval = apr_md5(md5_value,
                   (const char*)message,
                   strlen(message));
  if (retval != APR_SUCCESS) {
    ERR(r, "md5 failed.");
    DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
    return NULL;
  }

  DBG(r, "REQ[%X] md5:[%s]", TO_ADDR(r), md5_value);

  visitor_id = apr_pstrdup(r->pool, "0x");
  int ii;
  for (ii=0; ii<APR_MD5_DIGESTSIZE; ii++) {
    visitor_id = apr_pstrcat(r->pool, visitor_id, apr_psprintf(r->pool, "%02X", md5_value[ii]), NULL);
  }
  DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);

  return visitor_id;
}
Example #8
0
static char *
s_uniqid(request_rec *r)
{
  char                *uuid_string;
  apr_uuid_t          uuid;

  DBG(r, "REQ[%X] start %s()", TO_ADDR(r),__func__);
  apr_uuid_get(&uuid);
  uuid_string = apr_palloc(r->pool, APR_UUID_FORMATTED_LENGTH + 1);
  memset(uuid_string, 0, APR_UUID_FORMATTED_LENGTH + 1);
  apr_uuid_format(uuid_string, &uuid);;

  DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
  return uuid_string;

}
Example #9
0
void MySensor::setupRadio(rf24_pa_dbm_e paLevel, uint8_t channel, rf24_datarate_e dataRate) {
	failedTransmissions = 0;

	// Start up the radio library
	RF24::begin();

	if (!RF24::isPVariant()) {
		debug(PSTR("check wires\n"));
		while(1);
	}
	RF24::setAutoAck(1);
	RF24::setAutoAck(BROADCAST_PIPE,false); // Turn off auto ack for broadcast
	RF24::enableAckPayload();
	RF24::setChannel(channel);
	RF24::setPALevel(paLevel);
	RF24::setDataRate(dataRate);
	RF24::setRetries(5,15);
	RF24::setCRCLength(RF24_CRC_16);
	RF24::enableDynamicPayloads();

	// All nodes listen to broadcast pipe (for FIND_PARENT_RESPONSE messages)
	RF24::openReadingPipe(BROADCAST_PIPE, TO_ADDR(BROADCAST_ADDRESS));
	
	RF24::printDetails();
}
static int __sci_adi_read(u32 regPddr)
{
	unsigned long val;
	int cnt = 2000;

	while (FIFO_IS_FULL() && cnt--) {
		udelay(1);
	}
	WARN(cnt == 0, "ADI WAIT timeout!!!");
	__raw_writel(regPddr, REG_ADI_RD_CMD);

	/*
	 * wait read operation complete, RD_data[31] will be
	 * cleared after the read operation complete
	 */
	do {
		val = __raw_readl(REG_ADI_RD_DATA);
	} while ((val & BIT_RD_CMD_BUSY) && cnt--);

	WARN(cnt == 0, "ADI READ timeout!!!");
	/* val high part should be the address of the last read operation */
	BUG_ON(TO_ADDR(val) != (regPddr & MASK_RD_ADDR));

	return (val & MASK_RD_VALU);
}
Example #11
0
static css_stylesheet_t *
s_dup_stylesheet(Doc *doc, css_stylesheet_t *stylesheet)
{
  css_selector_t   *cur_sel; 
  css_stylesheet_t *result;

  result = apr_palloc(doc->pool, sizeof(*result));
  if (! result) {
    ERR(doc->r, "REQ[%X] %s:%d Out of Memory", TO_ADDR(doc->r),APLOG_MARK);
    return NULL;
  }
  memset(result, 0, sizeof(*result));
  result->selector_head.next = &result->selector_head;
  result->selector_head.ref  = &result->selector_head.next;

  for (cur_sel = stylesheet->selector_head.next; cur_sel != &stylesheet->selector_head; cur_sel = cur_sel->next) {
    css_selector_t *new_sel = s_new_selector(doc->pool, result, cur_sel->name);
    css_property_t *cur_prop;
    for (cur_prop = cur_sel->property_head.next; cur_prop != &cur_sel->property_head; cur_prop = cur_prop->next) {
      css_property_t *to_prop = s_css_parser_copy_property(doc->pool, cur_prop);
      list_insert(to_prop, (&new_sel->property_head));
    }
    list_insert(new_sel, (&result->selector_head));
  }

  return result;
}
bool transportInit() {
	// Start up the radio library
	_rf24.begin();

	if (!_rf24.isPVariant()) {
		return false;
	}
	_rf24.setAutoAck(1);
	_rf24.setAutoAck(BROADCAST_PIPE,false); // Turn off auto ack for broadcast
	_rf24.enableAckPayload();
	_rf24.setChannel(MY_RF24_CHANNEL);
	_rf24.setPALevel(_paLevel);
	if (!_rf24.setDataRate(MY_RF24_DATARATE)) {
		return false;
	}
	_rf24.setRetries(5,15);
	_rf24.setCRCLength(RF24_CRC_16);
	_rf24.enableDynamicPayloads();

	// All nodes listen to broadcast pipe (for FIND_PARENT_RESPONSE messages)
	_rf24.openReadingPipe(BROADCAST_PIPE, TO_ADDR(BROADCAST_ADDRESS));


	#if defined(MY_RF24_ENABLE_ENCRYPTION)
		_aes.set_key(_psk, 16); //set up AES-key
	#endif

	//_rf24.printDetails();

	return true;
}
Example #13
0
/**
 * find selector with pseudo class.
 * @return new css_stylesheet_t
 */
css_stylesheet_t *
chxj_find_pseudo_selectors(Doc *doc, css_stylesheet_t *stylesheet)
{
  css_selector_t *cur_sel; 
  css_stylesheet_t *result;
  char *pattern_str = "^a:(link|focus|visited)$";
  ap_regex_t *pattern1 = chxj_ap_pregcomp(doc->pool, pattern_str, AP_REG_EXTENDED|AP_REG_ICASE);

  result = apr_palloc(doc->pool, sizeof(*result));
  if (! result) {
    ERR(doc->r,"REQ[%X] %s:%d Out of Memory", TO_ADDR(doc->r),APLOG_MARK);
    return NULL;
  }
  memset(result, 0, sizeof(*result));
  result->selector_head.next = &result->selector_head;
  result->selector_head.ref  = &result->selector_head.next;

  for (cur_sel = stylesheet->selector_head.next; cur_sel != &stylesheet->selector_head; cur_sel = cur_sel->next) {
    ap_regmatch_t match[256];
    if (chxj_ap_regexec(pattern1, cur_sel->name, pattern1->re_nsub + 1, match, 0) == 0) {
      css_selector_t *new_sel = s_new_selector(doc->pool, result, cur_sel->name);
      css_property_t *cur_prop;
      for (cur_prop = cur_sel->property_head.next; cur_prop != &cur_sel->property_head; cur_prop = cur_prop->next) {
        css_property_t *to_prop = s_css_parser_copy_property(doc->pool, cur_prop);
        list_insert(to_prop, (&new_sel->property_head));
      }
      list_insert(new_sel, (&result->selector_head));
    }
  }

  chxj_ap_pregfree(doc->pool, pattern1);

  return result;
}
Example #14
0
static void 
s_css_parser_from_uri_start_selector(SCSSParserPtr_t parser, SCSSNodePtr_t selectors)
{
  int ii;
  SCSSNodePtr_t cur = NULL;
  CB_INIT;
  ERROR_OCCORED;

  app_data->selector_count = 0;
  for (cur = selectors->next; cur != selectors; cur = cur->next)
    app_data->selector_count++;

  app_data->selector_list = apr_palloc(app_data->pool, sizeof(char *) * app_data->selector_count);
  if (! app_data->selector_list) {
    ERR(app_data->r, "REQ[%X] %s:%d Out of memory", TO_ADDR(app_data->r),APLOG_MARK);
    app_data->error_occured = 1;
    return;
  }
  ii = 0;
  for (cur = selectors->next; cur != selectors; cur = cur->next) {
    app_data->selector_list[ii++] = apr_pstrdup(app_data->pool, (char *)cur->name);
  }
  app_data->property_head.next = &app_data->property_head;
  app_data->property_head.ref  = &app_data->property_head.next;
}
Example #15
0
/**
 * style value parser.
 * <style>css</style>
 * @return merged new css_stylesheet_t object.
 */
css_stylesheet_t *
chxj_css_parse_style_value(Doc *doc, css_stylesheet_t *old_stylesheet, char *style_attr_value)
{
  css_stylesheet_t *new_stylesheet;
  css_stylesheet_t *dup_stylesheet = NULL;

  DBG(doc->r,"REQ[%X] start %s()",TO_ADDR(doc->r),__func__);

  if (old_stylesheet) {
    dup_stylesheet = s_dup_stylesheet(doc, old_stylesheet);
  }
  new_stylesheet = s_chxj_css_parse_from_buf(doc->r, doc->pool, NULL, dup_stylesheet, style_attr_value);

  DBG(doc->r,"REQ[%X] end %s()",TO_ADDR(doc->r),__func__);
  return new_stylesheet;
}
bool MyTransportNRF24::send(uint8_t to, const void* data, uint8_t len) {
	// Make sure radio has powered up
	rf24.powerUp();
	rf24.stopListening();
	rf24.openWritingPipe(TO_ADDR(_base_address, to));
	bool ok = rf24.write(data, len);
	rf24.startListening();
	return ok;
}
Example #17
0
static char *
s_get_ip(request_rec *r, const char *remote_address)
{
  DBG(r, "REQ[%X] start %s()", TO_ADDR(r),__func__);
  if (! remote_address || *remote_address == '\0') {
    DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
    return apr_pstrdup(r->pool, "");
  }

  char *ret = apr_pstrdup(r->pool, remote_address);
  
  char *idx= strrchr(ret, '.');
  if (idx == NULL) {
    DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
    return apr_pstrdup(r->pool, "");
  }
  *++idx = '0';
  *++idx = 0;
  DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
  return ret;
}
Example #18
0
/**
 * allocate prop_list_stack.
 */
css_prop_list_stack_t *
chxj_new_prop_list_stack(Doc *doc)
{
  css_prop_list_stack_t *new_stack = apr_palloc(doc->pool, sizeof(css_prop_list_stack_t));
  if (! new_stack) {
    ERR(doc->r,"REQ[%X] %s:%d Out of memory.",TO_ADDR(doc->r),APLOG_MARK);
    return NULL;
  }
  new_stack->head.next = &new_stack->head;
  new_stack->head.ref  = &new_stack->head.next;
  return new_stack;
}
Example #19
0
char *
chxj_header_inf_set_content_type(request_rec *r, char *default_string)
{
  char *h_out     = NULL;
  char *err_h_out = NULL;

  DBG(r,"REQ[%X] start %s()",TO_ADDR(r),__func__);

  h_out     = (char *)apr_table_get(r->headers_out, HTTP_X_CHXJ_SET_CONTENT_TYPE);
  err_h_out = (char *)apr_table_get(r->err_headers_out, HTTP_X_CHXJ_SET_CONTENT_TYPE);

  if (err_h_out) {
    DBG(r,"REQ[%X] end %s()",TO_ADDR(r),__func__);
    return err_h_out;
  }
  if (h_out) {
    DBG(r,"REQ[%X] end %s()",TO_ADDR(r),__func__);
    return h_out;
  }

  DBG(r,"REQ[%X] end %s()",TO_ADDR(r),__func__);
  return default_string;
}
Example #20
0
int
chxj_google_analytics_handler(request_rec *r)
{
  mod_chxj_config *conf;

  DBG(r, "REQ[%X] start %s()", TO_ADDR(r),__func__);
  conf = chxj_get_module_config(r->per_dir_config, &chxj_module);
  if (conf->use_google_analytics != 1
     || conf->google_analytics_account == NULL
     || conf->google_analytics_target == NULL) {
    DBG(r, "REQ[%X] end %s() (ChxjUseGoogleAnalytics Off)", TO_ADDR(r),__func__);
    return DECLINED;
  }
  if (strcmp(r->handler, "chxj-google-analytics-handler")) {
    DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
    return DECLINED;
  }
  s_track_page_view(r);

  chxj_remove_filter(r);
  DBG(r,"REQ[%X] end %s()", TO_ADDR(r),__func__);
  return OK;
}
Example #21
0
static char *
s_cmp_now_node_vs_current_style(Doc *doc, request_rec *r, apr_pool_t *pool, char *src, ap_regex_t *pattern4, Node *node)
{
  ap_regmatch_t match[256];
  if (chxj_ap_regexec(pattern4, src, pattern4->re_nsub + 1, match, 0) == 0) {
    char *tag_name   = chxj_ap_pregsub(pool, "$1", src, pattern4->re_nsub + 1, match);
    char *class_name = chxj_ap_pregsub(pool, "$2", src, pattern4->re_nsub + 1, match);
    char *id_name    = chxj_ap_pregsub(pool, "$3", src, pattern4->re_nsub + 1, match);
    DBG(r, "REQ[%X] tag:[%s] class:[%s] id:[%s]", TO_ADDR(r),tag_name, class_name, id_name);
    if (!node) {
      DBG(r, "REQ[%X] unmatch(parent is null)",TO_ADDR(r));
      return NULL;
    }
    char *node_tag_name   = NULL;
    char *node_class_name = NULL;
    char *node_id_name    = NULL;
    s_get_tag_and_class_and_id(doc, node, &node_tag_name, &node_class_name, &node_id_name);
    if (*tag_name == 0 || strcasecmp(node_tag_name, tag_name) == 0 || strcmp("*", tag_name) == 0) {
      if (class_name && *class_name != 0) {
        if (!node_class_name) {
          DBG(r, "REQ[%X] unmatch (class) node:[NULL]",TO_ADDR(r));
          return NULL;
        }
        if (strcasecmp(node_class_name, &class_name[1]) != 0) {
          DBG(r,"REQ[%X] unmatch (class) node:[%s] style:[%s]", TO_ADDR(r),node_class_name, &class_name[1]);
          return NULL;
        }
      }
      if (id_name && *id_name != 0) {
        if (!node_id_name) {
          DBG(r,"REQ[%X] unmatch (id) node:[NULL]",TO_ADDR(r));
          return NULL;
        }
        if (strcasecmp(node_id_name, &id_name[1]) != 0) {
          DBG(r,"REQ[%X] unmatch (id)",TO_ADDR(r));
          return NULL;
        }
      }
      DBG(r,"REQ[%X] match",TO_ADDR(r));
      return src;
    }
    DBG(r,"REQ[%X] unmatch(tag) tag:[%s] vs [%s]", TO_ADDR(r),tag_name, node_tag_name);
  }
  return NULL;
}
Example #22
0
boolean MySensor::sendWrite(uint8_t next, MyMessage &message, bool broadcast) {
	uint8_t length = mGetLength(message);
	message.last = nc.nodeId;
	mSetVersion(message, PROTOCOL_VERSION);
	// Make sure radio has powered up
	RF24::powerUp();
	RF24::stopListening();
	RF24::openWritingPipe(TO_ADDR(next));
	bool ok = RF24::write(&message, min(MAX_MESSAGE_LENGTH, HEADER_SIZE + length), broadcast);
	RF24::startListening();

	debug(PSTR("send: %d-%d-%d-%d s=%d,c=%d,t=%d,pt=%d,l=%d,st=%s:%s\n"),
			message.sender,message.last, next, message.destination, message.sensor, mGetCommand(message), message.type, mGetPayloadType(message), mGetLength(message), ok?"ok":"fail", message.getString(convBuf));

	return ok;
}
Example #23
0
css_prop_list_t *
chxj_dup_css_prop_list(Doc *doc, css_prop_list_t *old)
{
  css_property_t *cur_prop;
  css_prop_list_t *new_prop_list;

  new_prop_list = chxj_css_create_prop_list(doc, NULL);
  if (! new_prop_list) {
    ERR(doc->r,"REQ[%X] %s:%d Out of memory.",TO_ADDR(doc->r),APLOG_MARK);
    return NULL;
  }
  if (old) {
    for (cur_prop = old->head.next; cur_prop != &old->head; cur_prop = cur_prop->next) {
      css_property_t *cp_prop = s_css_parser_copy_property(doc->pool, cur_prop);
      list_insert(cp_prop, (&new_prop_list->head));
    }
  }
  return new_prop_list;
}
Example #24
0
bool MyTransportNRF24::init() {
	// Start up the radio library
	rf24.begin();

	if (!rf24.isPVariant()) {
		return false;
	}
	rf24.setAutoAck(1);
	rf24.setAutoAck(BROADCAST_PIPE,false); // Turn off auto ack for broadcast
	rf24.enableAckPayload();
	rf24.setChannel(RF24_CHANNEL);
	rf24.setPALevel(_paLevel);
	rf24.setDataRate(RF24_DATARATE);
	rf24.setRetries(5,15);
	rf24.setCRCLength(RF24_CRC_16);
	rf24.enableDynamicPayloads();

	// All nodes listen to broadcast pipe (for FIND_PARENT_RESPONSE messages)
	rf24.openReadingPipe(BROADCAST_PIPE, TO_ADDR(BROADCAST_ADDRESS));
	return true;
}
Example #25
0
css_prop_list_t *
chxj_css_create_prop_list(Doc *doc, css_selector_t *sel)
{
  css_prop_list_t *prop_list;
  prop_list = apr_palloc(doc->pool, sizeof(*prop_list));
  if (! prop_list) {
    ERR(doc->r,"REQ[%X] %s:%d Out of memory.",TO_ADDR(doc->r),APLOG_MARK);
    return NULL;
  }
  prop_list->head.next = &prop_list->head;
  prop_list->head.ref  = &prop_list->head.next;
  if (sel)  {
    css_property_t *cur_prop;
    for (cur_prop = sel->property_head.next; 
         cur_prop != &sel->property_head; 
         cur_prop = cur_prop->next) {
      css_property_t *cp_prop = s_css_parser_copy_property(doc->pool, cur_prop);
      list_insert(cp_prop, (&prop_list->head));
    }
  }
  return prop_list;
}
bool transportSend(uint8_t to, const void* data, uint8_t len) {
	#if defined(MY_RF24_ENABLE_ENCRYPTION)
		memcpy(_dataenc,data,len); // copy input data because it is read-only

		_aes.set_IV(0);//not sure if necessary
		len = len > 16 ? 32 : 16;
		_aes.cbc_encrypt(_dataenc, _dataenc, len/16); //encrypt
	#endif

	// Make sure radio has powered up

	_rf24.powerUp();
	_rf24.stopListening();
	_rf24.openWritingPipe(TO_ADDR(to));
	#if defined(MY_RF24_ENABLE_ENCRYPTION)
		bool ok = _rf24.write(_dataenc, len, to == BROADCAST_ADDRESS);
	#else
		bool ok = _rf24.write(data, len, to == BROADCAST_ADDRESS);
	#endif
	_rf24.startListening();
	return ok;
}
Example #27
0
boolean MySensor::process() {
	uint8_t pipe;
	boolean available = RF24::available(&pipe);

	if (!available || pipe>6)
		return false;

	uint8_t len = RF24::getDynamicPayloadSize();
	RF24::read(&msg, len);
	RF24::writeAckPayload(pipe,&pipe, 1 );

	// Add string termination, good if we later would want to print it.
	msg.data[mGetLength(msg)] = '\0';
	debug(PSTR("read: %d-%d-%d s=%d,c=%d,t=%d,pt=%d,l=%d:%s\n"),
				msg.sender, msg.last, msg.destination,  msg.sensor, mGetCommand(msg), msg.type, mGetPayloadType(msg), mGetLength(msg), msg.getString(convBuf));

	if(!(mGetVersion(msg) == PROTOCOL_VERSION)) {
		debug(PSTR("version mismatch\n"));
		return false;
	}

	uint8_t command = mGetCommand(msg);
	uint8_t type = msg.type;
	uint8_t sender = msg.sender;
	uint8_t last = msg.last;
	uint8_t destination = msg.destination;

	if (repeaterMode && command == C_INTERNAL && type == I_FIND_PARENT) {
		// Relaying nodes should always answer ping messages
		// Wait a random delay of 0-2 seconds to minimize collision
		// between ping ack messages from other relaying nodes
		delay(millis() & 0x3ff);
		sendWrite(sender, build(msg, nc.nodeId, sender, NODE_SENSOR_ID, C_INTERNAL, I_FIND_PARENT_RESPONSE, false).set(nc.distance), true);
		return false;
	} else if (destination == nc.nodeId) {
		// Check if sender requests an ack back.
		if (mGetRequestAck(msg)) {
			// Copy message
			ack = msg;
			mSetRequestAck(ack,false); // Reply without ack flag (otherwise we would end up in an eternal loop)
			mSetAck(ack,true);
			ack.sender = nc.nodeId;
			ack.destination = msg.sender;
			sendRoute(ack);
		}

		// This message is addressed to this node
		if (repeaterMode && last != nc.parentNodeId) {
			// Message is from one of the child nodes. Add it to routing table.
			addChildRoute(sender, last);
		}

		if (command == C_INTERNAL) {
			if (type == I_FIND_PARENT_RESPONSE && !isGateway) {
				// We've received a reply to a FIND_PARENT message. Check if the distance is
				// shorter than we already have.
				uint8_t distance = msg.getByte();
				if (distance<nc.distance-1) {
					// Found a neighbor closer to GW than previously found
					nc.distance = distance + 1;
					nc.parentNodeId = msg.sender;
					eeprom_write_byte((uint8_t*)EEPROM_PARENT_NODE_ID_ADDRESS, nc.parentNodeId);
					eeprom_write_byte((uint8_t*)EEPROM_DISTANCE_ADDRESS, nc.distance);
					debug(PSTR("new parent=%d, d=%d\n"), nc.parentNodeId, nc.distance);
				}
				return false;
			} else if (sender == GATEWAY_ADDRESS) {
				bool isMetric;

				if (type == I_REBOOT) {
					wdt_enable(WDTO_15MS);
					for (;;);
				} else if (type == I_ID_RESPONSE) {
					if (nc.nodeId == AUTO) {
						nc.nodeId = msg.getByte();
						// Write id to EEPROM
						if (nc.nodeId == AUTO) {
							// sensor net gateway will return max id if all sensor id are taken
							debug(PSTR("full\n"));
							while (1); // Wait here. Nothing else we can do...
						} else {
							RF24::openReadingPipe(CURRENT_NODE_PIPE, TO_ADDR(nc.nodeId));
							eeprom_write_byte((uint8_t*)EEPROM_NODE_ID_ADDRESS, nc.nodeId);
						}
						debug(PSTR("id=%d\n"), nc.nodeId);
					}
				} else if (type == I_CONFIG) {
					// Pick up configuration from controller (currently only metric/imperial)
					// and store it in eeprom if changed
					isMetric = msg.getByte() == 'M' ;
					if (cc.isMetric != isMetric) {
						cc.isMetric = isMetric;
						eeprom_write_byte((uint8_t*)EEPROM_CONTROLLER_CONFIG_ADDRESS, isMetric);
						//eeprom_write_block((const void*)&cc, (uint8_t*)EEPROM_CONTROLLER_CONFIG_ADDRESS, sizeof(ControllerConfig));
					}
				} else if (type == I_CHILDREN) {
					if (repeaterMode && msg.getByte() == 'C') {
						// Clears child relay data for this node
						debug(PSTR("rd=clear\n"));
						for (uint8_t i=0;i< sizeof(childNodeTable); i++) {
							removeChildRoute(i);
						}
						sendRoute(build(msg, nc.nodeId, GATEWAY_ADDRESS, NODE_SENSOR_ID, C_INTERNAL, I_CHILDREN,false).set(""));
					}
				} else if (type == I_TIME) {
					if (timeCallback != NULL) {
						// Deliver time to callback
						timeCallback(msg.getULong());
					}
				}
				return false;
			}
		}
		// Call incoming message callback if available
		if (msgCallback != NULL) {
			msgCallback(msg);
		}
		// Return true if message was addressed for this node...
		return true;
	} else if (repeaterMode && pipe == CURRENT_NODE_PIPE) {
		// We should try to relay this message to another node

		uint8_t route = getChildRoute(msg.destination);
		if (route>0 && route<255) {
			// This message should be forwarded to a child node. If we send message
			// to this nodes pipe then all children will receive it because the are
			// all listening to this nodes pipe.
			//
			//    +----B
			//  -A
			//    +----C------D
			//
			//  We're node C, Message comes from A and has destination D
			//
			// lookup route in table and send message there
			sendWrite(route, msg);
		} else  {
			// A message comes from a child node and we have no
			// route for it.
			//
			//    +----B
			//  -A
			//    +----C------D    <-- Message comes from D
			//
			//     We're node C
			//
			// Message should be passed to node A (this nodes relay)

			// This message should be routed back towards sensor net gateway
			sendWrite(nc.parentNodeId, msg);
			// Add this child to our "routing table" if it not already exist
			addChildRoute(sender, last);
		}
	}
	return false;
}
Example #28
0
void MySensor::requestNodeId() {
	debug(PSTR("req node id\n"));
	RF24::openReadingPipe(CURRENT_NODE_PIPE, TO_ADDR(nc.nodeId));
	sendRoute(build(msg, nc.nodeId, GATEWAY_ADDRESS, NODE_SENSOR_ID, C_INTERNAL, I_ID_REQUEST, false).set(""));
	waitForReply();
}
Example #29
0
static css_stylesheet_t *
s_chxj_css_parse_from_buf(request_rec *r, apr_pool_t *pool, struct css_already_import_stack *imported_stack, css_stylesheet_t *old_stylesheet, const char *css)
{
  apr_size_t  srclen;
  SCSSParserPtr_t     parser  = NULL;
  SCSSSACHandlerPtr_t handler = NULL;
  css_stylesheet_t *stylesheet = NULL;
  struct css_app_data app_data;
  struct css_already_import_stack *new_stack;

  DBG(r,"REQ[%X] start %s()",TO_ADDR(r),__func__);
  DBG(r,"REQ[%X] css:[%s]", TO_ADDR(r),css);
  srclen = strlen(css);
  
  /* create parser */
  parser = scss_parser_new_from_buf(pool, css, "");
  if (!parser) {
    ERR(r,"REQ[%X] %s:%d end chxj_css_parse_from_uri(): scss_parser_new_from_buf() failed", TO_ADDR(r),APLOG_MARK);
    return NULL;
  }
  handler = scss_doc_handler_new(parser);
  if (!handler) {
    ERR(r,"REQ[%X] %s:%d end chxj_css_parse_from_uri(): scss_doc_handler_new() failed", TO_ADDR(r),APLOG_MARK);
    return NULL;
  }

  stylesheet = apr_palloc(pool, sizeof(*stylesheet));
  memset(stylesheet, 0, sizeof(*stylesheet));
  stylesheet->selector_head.next = &stylesheet->selector_head;
  stylesheet->selector_head.ref  = &stylesheet->selector_head.next;

  memset(&app_data, 0, sizeof(struct css_app_data));
  app_data.stylesheet     = stylesheet;
  app_data.selector_list  = NULL;
  app_data.selector_count = 0;
  app_data.pool           = pool;
  app_data.error_occured  = 0;
  app_data.r              = r;
  if (imported_stack) {
    s_copy_already_import_stack(pool, &app_data.imported_stack_head, imported_stack);
  }
  else {
    app_data.imported_stack_head.next = &app_data.imported_stack_head;
    app_data.imported_stack_head.ref  = &app_data.imported_stack_head.next;
  }

  scss_doc_set_user_data(parser->doc, &app_data);

  new_stack = apr_palloc(pool, sizeof(*new_stack));
  memset(new_stack, 0, sizeof(*new_stack));
  new_stack->next = new_stack;
  new_stack->ref  = &new_stack->next;
  new_stack->full_url = "";
  list_insert(new_stack, (&app_data.imported_stack_head));

  handler->startSelector = s_css_parser_from_uri_start_selector;
  handler->endSelector   = s_css_parser_from_uri_end_selector;
  handler->property      = s_css_parser_from_uri_property;
  handler->import        = s_css_parser_from_uri_import_style;

  scss_parse_stylesheet(parser);
  DBG(r,"REQ[%X] css:[%s]", TO_ADDR(r),css);
  DBG(r,"REQ[%X] end %s()",TO_ADDR(r),__func__);
  return s_merge_stylesheet(pool, old_stylesheet, app_data.stylesheet);
}
Example #30
0
/**
 * The device is specified from TSV file. 
 * @param r Request_rec is appointed.
 * @param userAgent UserAgent is appointed here,
 * @return The style which corresponds is returned.
 */
static device_table *
s_specified_device_from_tsv(request_rec *r,device_table *spec,const char *user_agent)
{
  if(spec->device_id == NULL){
    return spec;
  }
  
  DBG(r, "REQ[%X] start %s() device_id:[%s]", TO_ADDR(r), __func__,spec->device_id);
  mod_chxj_config      *conf;
  
  conf = chxj_get_module_config(r->per_dir_config, &chxj_module);
  
  if(conf->device_hash == NULL){
    DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
    return spec;
  }
  char *key = apr_psprintf(r->pool,"%d.%s",spec->provider,spec->device_id);
  
  apr_table_t *ht = apr_hash_get(conf->device_hash,key,APR_HASH_KEY_STRING);
  
  if(ht != NULL){
    DBG(r, "REQ[%X] found ! %s() %s", TO_ADDR(r), __func__,key);
    int i;
    for ( i=0; i< conf->device_keys->nelts; i++){
      const char *k = ((const char**)conf->device_keys->elts)[i];
      char *val = (char *)apr_table_get(ht,k);
      if(val == NULL){
        continue;
      }
      DBG(r, "REQ[%X] start chxj_specified_device_from_tsv() [%s] = [%s]:[%s]",TO_ADDR(r),spec->device_id,k,val);
      if (STRCASEEQ('d','D',"device_name",k)){
        spec->device_name = apr_pstrdup(r->pool,val);
      }
      if (STRCASEEQ('w','W',"width",k)){
        if(chxj_chk_numeric(val) == 0){
          spec->width = chxj_atoi(val);
        }
      }
      else if (STRCASEEQ('h','H',"heigh",k)){
        if(chxj_chk_numeric(val) == 0){
          spec->heigh = chxj_atoi(val);
        }
      }
      else if (STRCASEEQ('h','H',"height",k)){
        if(chxj_chk_numeric(val) == 0){
          spec->heigh = chxj_atoi(val);
        }
      }
      else if (STRCASEEQ('w','W',"wp_width",k)){
        if(chxj_chk_numeric(val) == 0){
          spec->wp_width = chxj_atoi(val);
        }
      }
      else if (STRCASEEQ('w','W',"wp_heigh",k)){
        if(chxj_chk_numeric(val) == 0){
          spec->wp_heigh = chxj_atoi(val);
        }
      }
      else if (STRCASEEQ('w','W',"wp_height",k)){
        if(chxj_chk_numeric(val) == 0){
          spec->wp_heigh = chxj_atoi(val);
        }
      }
      else if (STRCASEEQ('c','C',"cache",k)){
        if(chxj_chk_numeric(val) == 0){
          spec->cache = chxj_atoi(val);
        }
      }
      else if (STRCASEEQ('g','G',"gif",k)){
        int tmp = get_boolean_value(r,val);
        if(tmp > -1 ){
            spec->available_gif = tmp;
        }
      }
      else if (STRCASEEQ('j','J',"jpeg",k)){
        int tmp = get_boolean_value(r,val);
        if(tmp > -1 ){
            spec->available_jpeg = tmp;
        }
      }
      else if (STRCASEEQ('p','P',"png",k)){
        int tmp = get_boolean_value(r,val);
        if(tmp > -1 ){
          spec->available_png = tmp;
        }
      }
      else if (STRCASEEQ('b','B',"bmp2",k)){
        int tmp = get_boolean_value(r,val);
        if(tmp > -1 ){
          spec->available_bmp2 = tmp;
        }
      }
      else if (STRCASEEQ('b','B',"bmp4",k)){
        int tmp = get_boolean_value(r,val);
        if(tmp > -1 ){
          spec->available_bmp4 = tmp;
        }
      }
      else if (STRCASEEQ('c','C',"color",k)){
        if(chxj_chk_numeric(val) == 0){
          spec->color = chxj_atoi(val);
        }
      }
      else if (STRCASEEQ('e','E',"emoji_type",k)){
        spec->emoji_type = apr_pstrdup(r->pool,val);
      }
      else if (STRCASEEQ('h','H',"html_spec_type",k)){
        if (STRCASEEQ('x','X',"xhtml_mobile_1_0",val)) {
          spec->html_spec_type = CHXJ_SPEC_XHtml_Mobile_1_0;
        }
        else if (STRCASEEQ('c','C',"chtml_1_0",val)) {
          spec->html_spec_type = CHXJ_SPEC_Chtml_1_0;
        }
        else if (STRCASEEQ('c','C',"chtml_2_0",val)) {
          spec->html_spec_type = CHXJ_SPEC_Chtml_2_0;
        }
        else if (STRCASEEQ('c','C',"chtml_3_0",val)) {
          spec->html_spec_type = CHXJ_SPEC_Chtml_3_0;
        }
        else if (STRCASEEQ('c','C',"chtml_4_0",val)) {
          spec->html_spec_type = CHXJ_SPEC_Chtml_4_0;
        }
        else if (STRCASEEQ('c','C',"chtml_5_0",val)) {
          spec->html_spec_type = CHXJ_SPEC_Chtml_5_0;
        }
        else if (STRCASEEQ('c','C',"chtml_6_0",val)) {
          spec->html_spec_type = CHXJ_SPEC_Chtml_6_0;
        }
        else if (STRCASEEQ('c','C',"chtml_7_0",val)) {
          spec->html_spec_type = CHXJ_SPEC_Chtml_7_0;
        }
        else if (STRCASEEQ('h','H',"hdml",val)) {
          spec->html_spec_type = CHXJ_SPEC_Hdml;
        }
        else if (STRCASEEQ('i','I',"ixhtml",val)) {
          spec->html_spec_type = CHXJ_SPEC_Chtml_7_0;
        }
        else if (STRCASEEQ('j','J',"jhtml",val)) {
          spec->html_spec_type = CHXJ_SPEC_Jhtml;
        }
        else if (STRCASEEQ('j','J',"jxhtml",val)) {
          spec->html_spec_type = CHXJ_SPEC_Jxhtml;
        }
        else if (STRCASEEQ('i','I',"iphone2",val)) {
          spec->html_spec_type = CHXJ_SPEC_iPhone2;
        }
        else if (STRCASEEQ('i','I',"iphone3",val)) {
          spec->html_spec_type = CHXJ_SPEC_iPhone3;
        }
        else if (STRCASEEQ('i','I',"iphone4",val)) {
          spec->html_spec_type = CHXJ_SPEC_iPhone4;
        }
        else if (STRCASEEQ('a','A',"android_s",val)) {
          spec->html_spec_type = CHXJ_SPEC_softbank_android;
        }
        else if (STRCASEEQ('a','A',"android_a",val)) {
          spec->html_spec_type = CHXJ_SPEC_au_android;
        }
        else if (STRCASEEQ('a','A',"android_d",val)) {
          spec->html_spec_type = CHXJ_SPEC_docomo_android;
        }
        else if (STRCASEEQ('a','A',"android",val)) {
          spec->html_spec_type = CHXJ_SPEC_android;
        }
      }
      else if (STRCASEEQ('o','O',"output_encoding",k)){
          spec->output_encoding = apr_pstrdup(r->pool,val);
      }
    }
  }
  
  DBG(r, "REQ[%X] end %s() [%d]",TO_ADDR(r),__func__,spec->provider);
  return spec;
}