static query_result * add_result (const char *query_string, const char *name, const char *misc_value, const char *email, query_result * results, int *rc) { query_result *r = results; if (name != NULL && email != NULL) { /* perform the query using name, email, and misc fields */ if (strstr_nocase (name, query_string) || strstr_nocase (email, query_string) || strstr_nocase (misc_value, query_string)) { r->next = create_query_result (); r = r->next; r->name = strdup (name); r->email = strdup (email); r->misc = strdup (misc_value); (*rc)++; /* increment results counter */ } } return r; }
static query_result * qr_atoll (query_result ** results_a, int n) { query_result *r = NULL; query_result *returning_r = NULL; query_result *tmp = NULL; int i = 0; r = create_query_result (); returning_r = r; for (i = 0; i < n; i++) { r->next = results_a[i]; r = r->next; r->next = NULL; } tmp = returning_r; returning_r = returning_r->next; delete_query_result (tmp); return returning_r; }
/*---------------------------------------------------------------------------*/ void execute_select_query(void * data) { int i; int retval; char all_true; uint16_t current_epoch, nepochs; field_data_t * field_data; attr_entry_t * attr_entry; expression_data_t * expr_data; qtable_entry_t * qtable_entry = (qtable_entry_t *)data; squery_data_t * squery_data = (squery_data_t *)qtable_entry->qptr; current_epoch = ntoh_leuint16(&squery_data->current_epoch); nepochs = ntoh_leuint16(&squery_data->nepochs); PRINTF("[DEBUG]: Executing query qid %d\n", squery_data->qid); field_data = (field_data_t *)(squery_data + 1); /* Read all needed data. */ for(i=0; i<squery_data->nfields; i++, field_data++) { attr_entry = get_attr_entry(field_data->id); if(attr_entry && attr_entry->get_data) { attr_entry->get_data(&(field_data->data)); } else { PRINTF("[DEBUG]: Warning! get_data not defined attr_id %d\n", field_data->id); } } all_true = TRUE; expr_data = (expression_data_t *)field_data; /* Evaluate expressions. * NOTE: Currently, we consider only about simple conjunctions. */ for(i=0; i<squery_data->nexprs; i++, expr_data++) { if(!evaluate_expression(expr_data)) { PRINTF("[DEBUG]: Expression evalution faild. qid %d\n",squery_data->qid); all_true = FALSE; break; } } if(all_true) { /* Send results to query root. */ packetbuf_clear(); retval = create_query_result(squery_data, packetbuf_dataptr(), 64); if(retval > 0) { packetbuf_set_datalen(retval); if(send_data) { /* SendResult(squery_data->qroot); */ send_data(&qtable_entry->qroot); } } else { PRINTF("[DEBUG]: Error! sending data failed qid %d\n", squery_data->qid); } } current_epoch++; hton_leuint16(&squery_data->current_epoch, current_epoch); if(nepochs == 0 || nepochs > current_epoch) { ctimer_reset(&squery_data->timer); } else { PRINTF("[DEBUG]: Deleting query. qid %d\n", squery_data->qid); remove_query_entry(squery_data->qid, &qtable_entry->qroot); qfree(squery_data); } leds_toggle(LEDS_YELLOW); }