Example #1
0
File: bookie.c Project: dmad/bookie
int
main (int argc, char *argv[])
{
  struct arguments args;

  entries_allocated = entries_used = 0;
  entries = NULL;

  if (_get_arguments (&args, argc, argv)) {
    load_entries (&args);

    if (args.list_details)
      do_list_details ();

    if (args.list_by_account)
      do_list_by_account ();
  
    if (args.list_by_date)
      do_list_by_date ();

    if (args.list_total)
      do_list_total ();
  }

  return 0;
}
Example #2
0
static CCNxMetaMessage *
_TransportLinkAdapter_Command(Athena *athena, CCNxInterest *interest)
{
    CCNxMetaMessage *responseMessage;
    responseMessage = athenaTransportLinkAdapter_ProcessMessage(athena->athenaTransportLinkAdapter, interest);
    if (responseMessage) {
        return responseMessage;
    }

    CCNxName *ccnxName = ccnxInterest_GetName(interest);
    if (ccnxName_GetSegmentCount(ccnxName) > AthenaCommandSegment) {
        CCNxNameSegment *nameSegment = ccnxName_GetSegment(ccnxName, AthenaCommandSegment);
        char *command = ccnxNameSegment_ToString(nameSegment);

        char *arguments = _get_arguments(interest);
        if (arguments == NULL) {
            responseMessage = _create_response(athena, ccnxName, "No link arguments given to %s command", command);
            parcMemory_Deallocate(&command);
            return responseMessage;
        }

        if (strcasecmp(command, AthenaCommand_Add) == 0) {
            if (arguments) {
                PARCURI *connectionURI = parcURI_Parse(arguments);
                if (connectionURI == NULL) {
                    responseMessage = _create_response(athena, ccnxName, "Could not parse URI:  %s", arguments);
                    return responseMessage;
                }
                const char *linkName = athenaTransportLinkAdapter_Open(athena->athenaTransportLinkAdapter, connectionURI);
                parcURI_Release(&connectionURI);
                if (linkName) {
                    responseMessage = _create_response(athena, ccnxName, "%s", linkName);
                    athenaInterestControl_LogConfigurationChange(athena, ccnxName, "%s", arguments);
                } else {
                    responseMessage = _create_response(athena, ccnxName, "New %s link failed: %s", arguments, strerror(errno));
                }
            }
        } else if (strcasecmp(command, AthenaCommand_Remove) == 0) {
            if (arguments) {
                int result = athenaTransportLinkAdapter_CloseByName(athena->athenaTransportLinkAdapter, arguments);
                if (result) {
                    responseMessage = _create_response(athena, ccnxName, "removal of %s failed", arguments);
                } else {
                    responseMessage = _create_response(athena, ccnxName, "%s removed", arguments);
                    athenaInterestControl_LogConfigurationChange(athena, ccnxName, "%s", arguments);
                }
            }
        } else {
            responseMessage = _create_response(athena, ccnxName, "Unknown TransportLinkAdapter command %s", command);
        }

        parcMemory_Deallocate(&command);
        parcMemory_Deallocate(&arguments);
    }
    return responseMessage;
}
Example #3
0
static CCNxMetaMessage *
_Control_Command(Athena *athena, CCNxInterest *interest)
{
    CCNxMetaMessage *responseMessage;
    responseMessage = athenaControl_ProcessMessage(athena, interest);
    if (responseMessage) {
        return responseMessage;
    }

    CCNxName *ccnxName = ccnxInterest_GetName(interest);
    if (ccnxName_GetSegmentCount(ccnxName) <= AthenaCommandSegment) {
        responseMessage = _create_response(athena, ccnxName, "No command specified");
        return responseMessage;
    }

    CCNxNameSegment *nameSegment = ccnxName_GetSegment(ccnxName, AthenaCommandSegment);
    char *command = ccnxNameSegment_ToString(nameSegment);

    // Set <level> <debug,info>
    if (strncasecmp(command, AthenaCommand_Set, strlen(AthenaCommand_Set)) == 0) {
        responseMessage = _Control_Command_Set(athena, ccnxName, command);
        parcMemory_Deallocate(&command);
        return responseMessage;
    }

    // Quit
    if (strncasecmp(command, AthenaCommand_Quit, strlen(AthenaCommand_Quit)) == 0) {
        responseMessage = _Control_Command_Quit(athena, ccnxName, command);
        parcMemory_Deallocate(&command);
        return responseMessage;
    }

    // Stats
    if (strncasecmp(command, AthenaCommand_Stats, strlen(AthenaCommand_Stats)) == 0) {
        responseMessage = _Control_Command_Stats(athena, ccnxName, command);
        parcMemory_Deallocate(&command);
        return responseMessage;
    }

    // Spawn
    if (strncasecmp(command, AthenaCommand_Run, strlen(AthenaCommand_Run)) == 0) {
        const char *connectionSpecification = _get_arguments(interest);
        responseMessage = _Control_Command_Spawn(athena, ccnxName, command, connectionSpecification);
        parcMemory_Deallocate(&connectionSpecification);
        parcMemory_Deallocate(&command);
        return responseMessage;
    }

    responseMessage = _create_response(athena, ccnxName, "Unknown command \"%s\"", command);
    parcMemory_Deallocate(&command);
    return responseMessage;
}
Example #4
0
static CCNxMetaMessage *
_FIB_Command(Athena *athena, CCNxInterest *interest, PARCBitVector *ingress)
{
    CCNxMetaMessage *responseMessage;
    responseMessage = athenaFIB_ProcessMessage(athena->athenaFIB, interest);
    if (responseMessage) {
        return responseMessage;
    }

    CCNxName *ccnxName = ccnxInterest_GetName(interest);
    if (ccnxName_GetSegmentCount(ccnxName) > AthenaCommandSegment) {
        CCNxNameSegment *nameSegment = ccnxName_GetSegment(ccnxName, AthenaCommandSegment);
        char *command = ccnxNameSegment_ToString(nameSegment);

        if ((strcasecmp(command, AthenaCommand_Add) == 0) || (strcasecmp(command, AthenaCommand_Remove) == 0)) {
            char *arguments = _get_arguments(interest);

            if (arguments == NULL) {
                responseMessage = _create_response(athena, ccnxName, "No link or prefix arguments given to %s route command", command);
                parcMemory_Deallocate(&command);
                return responseMessage;
            }

            char linkName[MAXPATHLEN];
            char prefix[MAXPATHLEN];
            PARCBitVector *linkVector;

            // {Add,Remove} Route arguments "<prefix> [<linkName>]", if linkName not specified, use the incoming link id ([de-]registration)
            int numberOfArguments = sscanf(arguments, "%s %s", prefix, linkName);
            if (numberOfArguments == 2) {
                int linkId = athenaTransportLinkAdapter_LinkNameToId(athena->athenaTransportLinkAdapter, linkName);
                if (linkId == -1) {
                    responseMessage = _create_response(athena, ccnxName, "Unknown linkName %s", linkName);
                    parcMemory_Deallocate(&command);
                    parcMemory_Deallocate(&arguments);
                    return responseMessage;
                }
                linkVector = parcBitVector_Create();
                parcBitVector_Set(linkVector, linkId);
            } else if (numberOfArguments == 1) { // use ingress link
                linkVector = parcBitVector_Acquire(ingress);
            } else {
                responseMessage = _create_response(athena, ccnxName, "No prefix specified or too many arguments");
                parcMemory_Deallocate(&command);
                parcMemory_Deallocate(&arguments);
                return responseMessage;
            }

            CCNxName *prefixName = ccnxName_CreateFromCString(prefix);
            if (prefixName == NULL) {
                responseMessage = _create_response(athena, ccnxName, "Unable to parse prefix %s", prefix);
                parcMemory_Deallocate(&command);
                parcMemory_Deallocate(&arguments);
                parcBitVector_Release(&linkVector);
                return responseMessage;
            }

            int result = false;
            if (strcasecmp(command, AthenaCommand_Add) == 0) {
                result = athenaFIB_AddRoute(athena->athenaFIB, prefixName, linkVector);
            } else if (strcasecmp(command, AthenaCommand_Remove) == 0) {
                result = athenaFIB_DeleteRoute(athena->athenaFIB, prefixName, linkVector);
            }

            if (result == true) {
                char *routePrefix = ccnxName_ToString(prefixName);
                const char *linkIdName = athenaTransportLinkAdapter_LinkIdToName(athena->athenaTransportLinkAdapter, parcBitVector_NextBitSet(linkVector, 0));
                responseMessage = _create_response(athena, ccnxName, "%s route %s -> %s", command, routePrefix, linkIdName);
                athenaInterestControl_LogConfigurationChange(athena, ccnxName, "%s %s", routePrefix, linkIdName);
                parcMemory_Deallocate(&routePrefix);
            } else {
                responseMessage = _create_response(athena, ccnxName, "%s failed", command);
            }
            parcBitVector_Release(&linkVector);
            ccnxName_Release(&prefixName);

            parcMemory_Deallocate(&arguments);
        } else if (strcasecmp(command, AthenaCommand_List) == 0) {
            // Need to create the response here because as the FIB doesn't know the linkName
            parcLog_Debug(athena->log, "FIB List command invoked");
            PARCList *fibEntries = athenaFIB_CreateEntryList(athena->athenaFIB);
            responseMessage = _create_FIBList_response(athena, ccnxName, fibEntries);
            parcList_Release(&fibEntries);
        } else {
            responseMessage = _create_response(athena, ccnxName, "Unknown command: %s", command);
        }

        parcMemory_Deallocate(&command);
    }
    return responseMessage;
}
Example #5
0
int
main (int argc, char *argv[]) 
{
  struct arguments args;

  if (_get_arguments (&args, argc, argv)) {
    const size_t buffer_size = 1024 * 32;
    int ifd = STDIN_FILENO, ofd = STDOUT_FILENO;
    bool busy = true, add_stamp = true;
    char *buffer;
    
    buffer = malloc (buffer_size);
    if (NULL == buffer) {
      fprintf (stderr, "Could not allocate read buffer because: %s\n",
	       strerror (errno));
      busy = false;
    }
    
    while (busy) {
      ssize_t read_size;
      
      read_size = read (ifd, buffer, buffer_size);
      if (-1 == read_size) {
	fprintf (stderr, "Could not read from fd(%d) because: %s\n",
		 ifd, strerror (errno));
	busy = false;
      } else if (0 == read_size) { /* EOF */
	busy = false;
      } else if (read_size > 0) {
	size_t processed_size = 0;
	size_t offset = 0;

	while (busy && processed_size < read_size) {
	  bool write_block, new_add_stamp;

	  if ('\n' == buffer[processed_size + offset]) {
	    write_block = true;
	    new_add_stamp = true;
	  } else if (processed_size + offset + 1 == read_size) {
	    write_block = true;
	    new_add_stamp = false;
	  } else {
	    write_block = false;
	    ++offset;
	  }

	  if (write_block) {
	    if (add_stamp) {
	      if (!write_stamp (ofd, &args))
		busy = false; /* error occured */
	    }
	    add_stamp = new_add_stamp;
	    
	    if (busy) {
	      if (write (ofd, buffer + processed_size, offset + 1) 
		  != offset + 1) {
		fprintf (stderr, "Could not write stdin to stdout because:"
			 " %s\n", strerror (errno));
		busy = false;
	      } else {
		processed_size += offset + 1;
		offset = 0;
	      }
	    }
	  }
	}
      }
    }

    if (NULL != buffer)
      free (buffer);
  }
  
  return 0;
}