apps/dtnrespond/dtnrespond.c
changeset 2 9daf757dfa63
parent 1 44c5e3fa6d30
equal deleted inserted replaced
1:44c5e3fa6d30 2:9daf757dfa63
   452 *******************************************************************************/
   452 *******************************************************************************/
   453 int
   453 int
   454 match_bpq(const dtn_bpq_extension_block_data_t * bpq,
   454 match_bpq(const dtn_bpq_extension_block_data_t * bpq,
   455     const char * matching_filename,
   455     const char * matching_filename,
   456     char * pathname,
   456     char * pathname,
   457     int * found)
   457     int * found,
       
   458     int verbose)
   458 {
   459 {
   459     char line[PATH_MAX];
   460     char line[PATH_MAX];
   460     char trim_response_path[PATH_MAX];
   461     char trim_response_path[PATH_MAX];
   461     char * response_path;
   462     char * response_path;
   462     FILE * file;
   463     FILE * file;
   463     
   464     
   464     *found = 0;
   465     *found = 0;
   465 
   466 
   466     if ((file = fopen(matching_filename, "r")) == 0)
   467     if ((file = fopen(matching_filename, "r")) == 0) {
   467         return -1;
   468         if (verbose) fprintf(stderr, "ERROR: Unable to open matching file: %s\n", matching_filename);    
       
   469         return -1;
       
   470     }
   468     
   471     
       
   472     if (verbose) fprintf(stderr, "trying to match the query: %s\n", bpq->query.query_val);    
       
   473 
   469     memset(line, 0 , PATH_MAX);
   474     memset(line, 0 , PATH_MAX);
   470     while (fgets(line, PATH_MAX, file) != NULL) {
   475     while (fgets(line, PATH_MAX, file) != NULL) {
   471         strtok(line, ",");
   476         strtok(line, ",");
   472         strtok(NULL, ",");
   477         strtok(NULL, ",");
   473         strtok(NULL, ",");
   478         strtok(NULL, ",");
   780                 if (ret != DTN_SUCCESS) {
   785                 if (ret != DTN_SUCCESS) {
   781                     fprintf(stderr, "error decoding query bundle: %d\n", ret);
   786                     fprintf(stderr, "error decoding query bundle: %d\n", ret);
   782                     return ret;
   787                     return ret;
   783                 }
   788                 }
   784 
   789 
   785                 match_bpq(&bpq_block_data, matching_filename, pathname, &found);
   790                 match_bpq(&bpq_block_data, matching_filename, pathname, &found, verbose);
   786                 break;
   791                 break;
   787             }                
   792             }                
   788         }
   793         }
   789 
   794 
   790         // if found respond and continue listening
   795         // if found respond and continue listening