Пример #1
0
/* Add a service listener */
void xPL_addServiceListener(xPL_ServicePtr theService, xPL_ServiceListener theListener, xPL_MessageType messageType, String schemaClass, String schemaType, xPL_ObjectPtr userValue) {
  xPL_ServiceListenerDefPtr theServiceListener;

  /* See if there is a slot to install and allocate more if not */
  if (theService->listenerCount == theService->listenerAllocCount) {
    theService->listenerAllocCount += GROW_LIST_BY;
    theService->serviceListenerList = realloc(theService->serviceListenerList, sizeof(xPL_ServiceListenerDef) * theService->listenerAllocCount);
  }

  theServiceListener = &(theService->serviceListenerList[theService->listenerCount++]);
  bzero(theServiceListener, sizeof(xPL_ServiceListenerDef));

  /* Install values */
  theServiceListener->serviceListener = theListener;
  theServiceListener->matchMessageType = messageType;

  /* Install optional schema related matches */
  if ((schemaClass != NULL) && (strlen(schemaClass) > 0)) {
    theServiceListener->matchSchemaClass = xPL_StrDup(schemaClass);
  }
  if ((schemaType != NULL) && (strlen(schemaType) > 0)) {
    theServiceListener->matchSchemaType = xPL_StrDup(schemaType);
  }

  theServiceListener->userValue = userValue;
}
Пример #2
0
static void updateClientIdent(xPL_MessagePtr theMessage, hubClientPtr theClient) {
  char identBuff[64];

  /* Build an ident for this message */
  strcpy(identBuff, xPL_getSourceVendor(theMessage));
  strcat(identBuff, "-");
  strcat(identBuff, xPL_getSourceDeviceID(theMessage));
  strcat(identBuff, ".");
  strcat(identBuff, xPL_getSourceInstanceID(theMessage));

  /* See if there is a change */
  if (theClient->clientIdent == NULL) {
    theClient->clientIdent = xPL_StrDup(identBuff);
    return;
  }

  /* See if there is a change */
  if (!strcmp(theClient->clientIdent, identBuff)) return;
  xPL_Debug("Client changing Ident from %s to %s", theClient->clientIdent, identBuff);
  STR_FREE(theClient->clientIdent);
  theClient->clientIdent = xPL_StrDup(identBuff);
}
Пример #3
0
void xPL_setServiceVersion(xPL_ServicePtr theService, String theVersion) {
  /* Free any previous version */
  if (theService->serviceVersion != NULL) STR_FREE(theService->serviceVersion);


  /* Clear the service version */
  if ((theVersion == NULL) || (strlen(theVersion) == 0)) {
    theService->serviceVersion = NULL;
    return;
  }

  /* Copy in string */
  theService->serviceVersion = xPL_StrDup(theVersion);
}
Пример #4
0
void xPL_setServiceInstanceID(xPL_ServicePtr theService, String newInstanceID) {
  /* Skip if name is already this ID */
  if ((theService->serviceInstanceID != NULL) && !xPL_strcmpIgnoreCase(theService->serviceInstanceID, newInstanceID)) return;

  /* If the service is enabled, send a goodbye heartbeat with our old data */
  if (theService->serviceEnabled) xPL_sendGoodbyeHeartbeat(theService);

  /* Copy the ID */
  STR_FREE(theService->serviceInstanceID);
  theService->serviceInstanceID = xPL_StrDup(newInstanceID);

  /* If service was enabled, send new heartbeat */
  if (theService->serviceEnabled) xPL_sendHeartbeat(theService);
}
Пример #5
0
static void buildLocalIPList() {
  int ifIndex, localIndex;
  struct ifconf interfaceList;
  struct ifreq * ifInfo;
  char ifBuff[sizeof(struct ifreq) * MAX_LOCAL_ADDR];
  int localNetCount = 0;
  
  /* Init the interface info request */
  bzero(ifBuff, sizeof(struct ifreq) * MAX_LOCAL_ADDR);
  interfaceList.ifc_len = MAX_LOCAL_ADDR;
  interfaceList.ifc_buf = ifBuff;

  /* Get our interfaces */
  if (ioctl(xPL_getFD(), SIOCGIFCONF, &interfaceList) != 0) {
    xPL_Debug("Unable to get IP addr list");
    return;
  }

  /* Determine how many interfaces are real ones */
  for (ifIndex = 0; ifIndex < interfaceList.ifc_len; ifIndex++) {
    ifInfo = &(interfaceList.ifc_req[ifIndex]);
    if (ifInfo->ifr_addr.sa_family != AF_INET ) continue;
    localNetCount++;
  }

  /* Free last list, if any */
  if (localIPAddrCount) {
    for (localIndex = 0; localIndex < localIPAddrCount; localIndex++) {
      STR_FREE(localIPAddrs[localIndex]);
    }
    free(localIPAddrs);
    localIPAddrCount = 0;
  }

  /* Allocate sufficiant space */
  xPL_Debug("There are %d local network addresses on this system");
  localIPAddrs = (String *) malloc(sizeof(String) * localNetCount);
  for (ifIndex = 0; ifIndex < interfaceList.ifc_len; ifIndex++) {
    ifInfo = &(interfaceList.ifc_req[ifIndex]);
    if (ifInfo->ifr_addr.sa_family != AF_INET ) continue;

    localIPAddrs[localIPAddrCount++] = xPL_StrDup(inet_ntoa(((struct sockaddr_in *) &(ifInfo->ifr_addr))->sin_addr));
    xPL_Debug("  Found %s", localIPAddrs[localIPAddrCount - 1]);
  }
}