Example #1
0
int main()
{    
    char q_action[64];
    char q_uuid[64];
    char q_chkcode[64];
    memset(q_action, 0, 64);
    memset(q_uuid, 0, 64);
    memset(q_chkcode, 0, 64);
    get_query_string("action", q_action);
    get_query_string("uuid", q_uuid);
    get_query_string("chkcode", q_chkcode);

    if (strcmp(q_action, "save") == 0)
    {
        save_uuid(q_uuid);
    }
    else if (strcmp(q_action, "read") == 0)
    {
        read_chkcode(q_uuid);
    }
    else if (strcmp(q_action, "input") == 0)
    {
        input_chkcode();
    }
    else if (strcmp(q_action, "enter") == 0)
    {
        enter_chkcode(q_uuid, q_chkcode);
    }

	return 0;
}
/**
 * Validates an FCGI request, returning the valid bounding box or
 * throwing an error if there was no valid bounding box.
 */
bbox map_handler::validate_request(request &req) {
  string decoded = http::urldecode(get_query_string(req));
  const std::vector<std::pair<string, string> > params = http::parse_params(decoded);
  auto itr =
    std::find_if(params.begin(), params.end(), is_bbox);

  bbox bounds;
  if ((itr == params.end()) || !bounds.parse(itr->second)) {
    throw http::bad_request("The parameter bbox is required, and must be "
                            "of the form min_lon,min_lat,max_lon,max_lat.");
  }

  // clip the bounding box against the world
  bounds.clip_to_world();

  // check that the bounding box is within acceptable limits. these
  // limits taken straight from the ruby map implementation.
  if (!bounds.valid()) {
    throw http::bad_request("The latitudes must be between -90 and 90, "
                            "longitudes between -180 and 180 and the "
                            "minima must be less than the maxima.");
  }

  // TODO: make configurable parameter?
  if (bounds.area() > MAX_AREA) {
    throw http::bad_request(
        (boost::format("The maximum bbox size is %1%, and your request "
                       "was too large. Either request a smaller area, or use "
                       "planet.osm") %
         MAX_AREA).str());
  }

  return bounds;
}
Example #3
0
static notmuch_query_t *get_query(struct nm_ctxdata *data, int writable)
{
    notmuch_database_t *db = NULL;
    notmuch_query_t *q = NULL;
    const char *str;

    if (!data)
        return NULL;

    db = get_db(data, writable);
    str = get_query_string(data);

    if (!db || !str)
        goto err;

    q = notmuch_query_create(db, str);
    if (!q)
        goto err;

    apply_exclude_tags(q);
    notmuch_query_set_sort(q, NOTMUCH_SORT_NEWEST_FIRST);
    dprint(2, (debugfile, "nm: query successfully initialized\n"));
    return q;
err:
    if (!is_longrun(data))
        release_db(data);
    return NULL;
}
Example #4
0
vector<osm_id_t> parse_id_list_params(request &req, const string &param_name) {
  string decoded = http::urldecode(get_query_string(req));
  const map<string, string> params = http::parse_params(decoded);
  map<string, string>::const_iterator itr = params.find(param_name);

  vector<osm_id_t> myids;

  if (itr != params.end()) {
    // just check for blank string, which shouldn't be converted.
    if (!itr->second.empty()) {
      vector<string> strs;
      al::split(strs, itr->second, al::is_any_of(","));
      try {
        for (vector<string>::iterator itr = strs.begin(); itr != strs.end();
             ++itr) {
          osm_id_t id = lexical_cast<osm_id_t>(*itr);
          myids.push_back(id);
        }
      } catch (const bad_lexical_cast &) {
        // note: this is pretty silly, and may change when the rails_port
        // changes to more sensible behaviour... but for the moment we emulate
        // the ruby behaviour; which is that something non-numeric results in a
        // to_i result of zero.
        myids.push_back(0);
      }
    }
  }

  // ensure list of IDs is unique
  std::sort(myids.begin(), myids.end());
  vector<osm_id_t>::iterator new_end = std::unique(myids.begin(), myids.end());
  myids.erase(new_end, myids.end());

  return myids;
}
Example #5
0
int main(int argc, char *argv[])
{
  int x,m;
  char *qs;
  entry *entries;
    
  int n;
  char **list,**urls;
  
  /* récupération de la chaîne de paramètres */
  qs = get_query_string(argc,argv);

  /* récupération des couples (nom,valeur) */
  entries = get_entries(qs,&m);

  /* émission de l'entête */
  print_html_head("R&eacute;sultat");

  /* affichage éventuel des informations de debug */
  if (DEBUG) print_debug_query(entries,m,qs,argc,argv);

  /* lecture de la liste des images */
  list = readList("/u/q/quenotg/HMUL8R6A/PROJET/test/list.txt",&n);
  if (list == NULL) {printf("Failed to read %s file.\n","list.txt"); exitfail();}
  if (DEBUG) printf("Read list, %d images.<BR>\n",n);
  
  /* lecture des urls des images */
  urls = readList("/u/q/quenotg/HMUL8R6A/PROJET/test/urls.txt",&n);
  if (list == NULL) {printf("Failed to read %s file.\n","list.txt"); exitfail();}
  if (DEBUG) printf("Read list, %d images.<BR>\n",n);
  
  /* émission de la fin de corps et de document */
  print_html_tail();
    
  exit(0);
}
Example #6
0
void
dt_collection_update_query(const dt_collection_t *collection)
{
  char query[1024], confname[200];
  gchar *complete_query = NULL;

  const int _n_r = dt_conf_get_int("plugins/lighttable/collect/num_rules");
  const int num_rules = CLAMP(_n_r, 1, 10);
  char *conj[] = {"and", "or", "and not"};

  complete_query = dt_util_dstrcat(complete_query, "(");

  for(int i=0; i<num_rules; i++)
  {
    snprintf(confname, sizeof(confname), "plugins/lighttable/collect/item%1d", i);
    const int property = dt_conf_get_int(confname);
    snprintf(confname, sizeof(confname), "plugins/lighttable/collect/string%1d", i);
    gchar *text = dt_conf_get_string(confname);
    if(!text) break;
    snprintf(confname, sizeof(confname), "plugins/lighttable/collect/mode%1d", i);
    const int mode = dt_conf_get_int(confname);
    gchar *escaped_text = dt_util_str_replace(text, "'", "''");

    get_query_string(property, escaped_text, query, sizeof(query));

    if(i > 0)
      complete_query = dt_util_dstrcat(complete_query, " %s %s", conj[mode], query);
    else
      complete_query = dt_util_dstrcat(complete_query, "%s", query);

    g_free(escaped_text);
    g_free(text);
  }

  complete_query = dt_util_dstrcat(complete_query, ")");

  // printf("complete query: `%s'\n", complete_query);

  /* set the extended where and the use of it in the query */
  dt_collection_set_extended_where (collection, complete_query);
  dt_collection_set_query_flags (collection, (dt_collection_get_query_flags (collection) | COLLECTION_QUERY_USE_WHERE_EXT));

  /* remove film id from default filter */
  dt_collection_set_filter_flags (collection, (dt_collection_get_filter_flags (collection) & ~COLLECTION_FILTER_FILM_ID));

  /* update query and at last the visual */
  dt_collection_update (collection);

  /* free string */
  g_free(complete_query);

  // remove from selected images where not in this query.
  sqlite3_stmt *stmt = NULL;
  const gchar *cquery = dt_collection_get_query(collection);
  complete_query = NULL;
  if(cquery && cquery[0] != '\0')
  {
    complete_query = dt_util_dstrcat(complete_query, "delete from selected_images where imgid not in (%s)", cquery);
    DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), complete_query, -1, &stmt, NULL);
    DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, 0);
    DT_DEBUG_SQLITE3_BIND_INT(stmt, 2, -1);
    sqlite3_step(stmt);
    sqlite3_finalize(stmt);

    /* free allocated strings */
    g_free(complete_query);
  }


  /* raise signal of collection change, only if this is an original */
  if (!collection->clone)
    dt_control_signal_raise(darktable.signals, DT_SIGNAL_COLLECTION_CHANGED);

}
Example #7
0
File: 905.c Project: shtyd/syspro
void
print_content()
{
	char  *query_string ;
	char **qv ;
	int    qc ;
	char  *arg1, *arg2, *arg3;

	int n1, n2, op;

	printf("<HTML><HEAD></HEAD><BODY><PRE>\n");
	query_string = get_query_string();

	if(  string_split( query_string,'&',&qc, &qv ) < 0 )
	{
		printf("Error while parsing query string\n");
		printf("</PRE></BODY></HTML>\n");
		if( query_string )
			free( query_string );
		exit( -1 );
	}

	arg1 = getparam( qc, qv, "arg1" );
	arg2 = getparam( qc, qv, "arg2" );
	arg3 = getparam( qc, qv, "arg3" );

	if (arg1 == NULL || arg2 == NULL)
	{
		printf("error: QUERY STRING must be \"arg1=INT&arg2=INT&arg3=INT\"\n");
		printf("</PRE></BODY></HTML>\n");
		free_string_vector( qc, qv );
		if( query_string )
			free( query_string );
		exit(-1);
	}

	if (arg3 == NULL)
	{
		printf("error: QUERY STRING must be \"arg1=INT&arg2=INT&arg3=INT\"\n");
		printf("</PRE></BODY></HTML>\n");
		free_string_vector( qc, qv );
		if( query_string )
			free( query_string );
		exit(-1);
	}

	/* printf("arg1: ["); safe_print_string( arg1 ); printf("]\n"); */
	/* printf("arg2: ["); safe_print_string( arg2 ); printf("]\n"); */

	if (*arg1 == '\0' || *arg2 == '\0')
	{
		printf("error: too few arguments to execute this program\n");
		printf("</PRE></BODY></HTML>\n");
		free_string_vector( qc, qv );
		if( query_string )
			free( query_string );
		exit(-1);
	}

	if (!is_figure(arg1) || !is_figure(arg2))
	{
		printf("error:input figure\n");
		printf("</PRE></BODY></HTML>\n");
		free_string_vector( qc, qv );
		if( query_string )
			free( query_string );
		exit(-1);
	}

	if (*arg3 == '\0')
	{
		printf("error: select a kind of calculation\n");
		printf("</PRE></BODY></HTML>\n");
		free_string_vector( qc, qv );
		if( query_string )
			free( query_string );
		exit(-1);
	}

	n1 = atoi(arg1);
	n2 = atoi(arg2);
	op = atoi(arg3);

	if (op == 1)
		printf("%d\n", n1 + n2);
	else if (op == 2)
		printf("%d\n", n1 - n2);
	else if (op == 3)
		printf("%d\n", n1 * n2);
	else if (op == 4)
	{
		if (n2 == 0) 			
			printf("error : divisor is zero\n");
		else
			printf("%d\n", n1 / n2);		
	}

	printf("</PRE></BODY></HTML>\n");
	free_string_vector( qc, qv );
	if( query_string )
		free( query_string );
}
Example #8
0
int main(int argc, char *argv[])
{
  int x,m;
  char *qs;
  entry *entries;
    
  int nbTrain,nbVal,nbDims,nbConcepts,c,**trainAnns,**valAnns,ret;
  char **trainList,**valList,**concepts,*name;
  float **trainDescriptors,**valDescriptors;
  
  /* récupération de la chaîne de paramètres */
  qs = get_query_string(argc,argv);

  /* récupération des couples (nom,valeur) */
  entries = get_entries(qs,&m);

  /* émission de l'entête */
  print_html_head("R&eacute;sultat");

  /* affichage éventuel des informations de debug */
  if (DEBUG) print_debug_query(entries,m,qs,argc,argv);

  trainList = readList("/usr/lib/cgi-bin/RIM/images/train/list.txt",&nbTrain);
  if (trainList == NULL) {printf("Failed to read %s file.\n","train/list.txt"); exitfail();}
  if (DEBUG) printf("Read train list, %d images.<BR>\n",nbTrain);
  
  valList = readList("/usr/lib/cgi-bin/RIM/images/val/list.txt",&nbVal);
  if (valList == NULL) {printf("Failed to read %s file.\n","val/list.txt"); exitfail();}
  if (DEBUG) printf("Read val list, %d images.<BR>\n",nbVal);
  
  trainDescriptors = readDescriptors("/usr/lib/cgi-bin/RIM/images/train/descriptors.bin",nbTrain,&nbDims);
  if (trainDescriptors == NULL) {printf("Failed to read %s file.\n","train/descriptors.bin"); exitfail();}
  if (DEBUG) printf("Read train descripors, %d images, %d dimensions.<BR>\n",nbTrain,nbDims);
  
  valDescriptors = readDescriptors("/usr/lib/cgi-bin/RIM/images/val/descriptors.bin",nbVal,&nbDims);
  if (valDescriptors == NULL) {printf("Failed to read %s file.\n","val/descriptors.bin"); exitfail();}
  if (DEBUG) printf("Read val descripors, %d images, %d dimensions.<BR>\n",nbVal,nbDims);
  
  concepts = readList("/usr/lib/cgi-bin/RIM/images/concepts.txt",&nbConcepts);
  if (concepts == NULL) {printf("Failed to read %s file.\n","concepts.txt"); exitfail();}
  if (DEBUG) printf("Read concept list, %d concepts.<BR>\n",nbConcepts);
  
  trainAnns = malloc(nbConcepts*sizeof(int *));
  if (trainAnns == NULL) {printf("malloc() failed.\n"); exitfail();}
  if (DEBUG) printf("Read train annotations:");
  for (c = 0; c < nbConcepts; c ++) {
    ret = asprintf(&name,"/usr/lib/cgi-bin/RIM/images/train/ann/%s.ann",concepts[c]);
    if (ret < 0) {printf("asprintf() failed.\n"); exitfail();}
    trainAnns[c] = readAnnotations(name,nbTrain);
    if (trainAnns[c] == NULL) {printf("Failed to read train/ann%s.ann file.\n",concepts[c]); exitfail();}
    if (DEBUG) printf(" %s",concepts[c]);
  }
  if (DEBUG) printf(".<BR>\n");
  
  valAnns = malloc(nbConcepts*sizeof(int *));
  if (valAnns == NULL) {printf("malloc() failed.\n"); exitfail();}
  if (DEBUG) printf("Read val annotations:");
  for (c = 0; c < nbConcepts; c ++) {
    ret = asprintf(&name,"/usr/lib/cgi-bin/RIM/images/val/ann/%s.ann",concepts[c]);
    if (ret < 0) {printf("asprintf() failed.\n"); exitfail();}
    valAnns[c] = readAnnotations(name,nbVal);
    if (valAnns[c] == NULL) {printf("Failed to read val/ann%s.ann file.\n",concepts[c]); exitfail();}
    if (DEBUG) printf(" %s",concepts[c]);
  }
  if (DEBUG) printf(".<BR>\n");
  
  /* émission de la fin de corps et de document */
  print_html_tail();
    
  exit(0);
}