Diff for /embedaddon/miniupnpd/upnpevents.c between versions 1.1.1.1 and 1.1.1.2

version 1.1.1.1, 2012/02/21 23:16:02 version 1.1.1.2, 2012/05/29 12:55:57
Line 1 Line 1
 /* $Id$ */  /* $Id$ */
 /* MiniUPnP project  /* MiniUPnP project
  * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/   * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
 * (c) 2008-2009 Thomas Bernard * (c) 2008-2011 Thomas Bernard
  * This software is subject to the conditions detailed   * This software is subject to the conditions detailed
  * in the LICENCE file provided within the distribution */   * in the LICENCE file provided within the distribution */
   
Line 37  struct subscriber { Line 37  struct subscriber {
         struct upnp_event_notify * notify;          struct upnp_event_notify * notify;
         time_t timeout;          time_t timeout;
         uint32_t seq;          uint32_t seq;
         /*enum { EWanCFG = 1, EWanIPC, EL3F } service;*/  
         enum subscriber_service_enum service;          enum subscriber_service_enum service;
         char uuid[42];          char uuid[42];
         char callback[];          char callback[];
Line 58  struct upnp_event_notify { Line 57  struct upnp_event_notify {
         int tosend;          int tosend;
     int sent;      int sent;
         const char * path;          const char * path;
   #ifdef ENABLE_IPV6
           int ipv6;
           char addrstr[48];
   #else
         char addrstr[16];          char addrstr[16];
   #endif
         char portstr[8];          char portstr[8];
 };  };
   
Line 80  newSubscriber(const char * eventurl, const char * call Line 84  newSubscriber(const char * eventurl, const char * call
         if(!eventurl || !callback || !callbacklen)          if(!eventurl || !callback || !callbacklen)
                 return NULL;                  return NULL;
         tmp = calloc(1, sizeof(struct subscriber)+callbacklen+1);          tmp = calloc(1, sizeof(struct subscriber)+callbacklen+1);
           if(!tmp)
                   return NULL;
         if(strcmp(eventurl, WANCFG_EVENTURL)==0)          if(strcmp(eventurl, WANCFG_EVENTURL)==0)
                 tmp->service = EWanCFG;                  tmp->service = EWanCFG;
         else if(strcmp(eventurl, WANIPC_EVENTURL)==0)          else if(strcmp(eventurl, WANIPC_EVENTURL)==0)
Line 103  newSubscriber(const char * eventurl, const char * call Line 109  newSubscriber(const char * eventurl, const char * call
 }  }
   
 /* creates a new subscriber and adds it to the subscriber list  /* creates a new subscriber and adds it to the subscriber list
 * also initiate 1st notify */ * also initiate 1st notify
  * TODO : add a check on the number of subscriber in order to
  * prevent memory overflow... */
 const char *  const char *
 upnpevents_addSubscriber(const char * eventurl,  upnpevents_addSubscriber(const char * eventurl,
                          const char * callback, int callbacklen,                           const char * callback, int callbacklen,
Line 184  upnp_event_create_notify(struct subscriber * sub) Line 192  upnp_event_create_notify(struct subscriber * sub)
         }          }
         obj->sub = sub;          obj->sub = sub;
         obj->state = ECreated;          obj->state = ECreated;
   #ifdef ENABLE_IPV6
           obj->s = socket((obj->sub->callback[7] == '[') ? PF_INET6 : PF_INET,
                           SOCK_STREAM, 0);
   #else
         obj->s = socket(PF_INET, SOCK_STREAM, 0);          obj->s = socket(PF_INET, SOCK_STREAM, 0);
   #endif
         if(obj->s<0) {          if(obj->s<0) {
                 syslog(LOG_ERR, "%s: socket(): %m", "upnp_event_create_notify");                  syslog(LOG_ERR, "%s: socket(): %m", "upnp_event_create_notify");
                 goto error;                  goto error;
Line 215  upnp_event_notify_connect(struct upnp_event_notify * o Line 228  upnp_event_notify_connect(struct upnp_event_notify * o
         int i;          int i;
         const char * p;          const char * p;
         unsigned short port;          unsigned short port;
   #ifdef ENABLE_IPV6
           struct sockaddr_storage addr;
   #else
         struct sockaddr_in addr;          struct sockaddr_in addr;
   #endif
         if(!obj)          if(!obj)
                 return;                  return;
         memset(&addr, 0, sizeof(addr));          memset(&addr, 0, sizeof(addr));
Line 226  upnp_event_notify_connect(struct upnp_event_notify * o Line 243  upnp_event_notify_connect(struct upnp_event_notify * o
         }          }
         p = obj->sub->callback;          p = obj->sub->callback;
         p += 7; /* http:// */          p += 7; /* http:// */
        while(*p != '/' && *p != ':')#ifdef ENABLE_IPV6
                obj->addrstr[i++] = *(p++);        if(*p == '[') { /* ip v6 */
                 p++;
                 obj->ipv6 = 1;
                 while(*p != ']' && i < (sizeof(obj->addrstr)-1))
                         obj->addrstr[i++] = *(p++);
                 if(*p == ']')
                         p++;
         } else {
 #endif
                 while(*p != '/' && *p != ':' && i < (sizeof(obj->addrstr)-1))
                         obj->addrstr[i++] = *(p++);
 #ifdef ENABLE_IPV6
         }
 #endif
         obj->addrstr[i] = '\0';          obj->addrstr[i] = '\0';
         if(*p == ':') {          if(*p == ':') {
                 obj->portstr[0] = *p;                  obj->portstr[0] = *p;
Line 244  upnp_event_notify_connect(struct upnp_event_notify * o Line 274  upnp_event_notify_connect(struct upnp_event_notify * o
                 obj->portstr[0] = '\0';                  obj->portstr[0] = '\0';
         }          }
         obj->path = p;          obj->path = p;
   #ifdef ENABLE_IPV6
           if(obj->ipv6) {
                   struct sockaddr_in6 * sa = (struct sockaddr_in6 *)&addr;
                   sa->sin6_family = AF_INET6;
                   inet_pton(AF_INET6, obj->addrstr, &(sa->sin6_addr));
                   sa->sin6_port = htons(port);
           } else {
                   struct sockaddr_in * sa = (struct sockaddr_in *)&addr;
                   sa->sin_family = AF_INET;
                   inet_pton(AF_INET, obj->addrstr, &(sa->sin_addr));
                   sa->sin_port = htons(port);
           }
   #else
         addr.sin_family = AF_INET;          addr.sin_family = AF_INET;
         inet_aton(obj->addrstr, &addr.sin_addr);          inet_aton(obj->addrstr, &addr.sin_addr);
         addr.sin_port = htons(port);          addr.sin_port = htons(port);
   #endif
         syslog(LOG_DEBUG, "%s: '%s' %hu '%s'", "upnp_event_notify_connect",          syslog(LOG_DEBUG, "%s: '%s' %hu '%s'", "upnp_event_notify_connect",
                obj->addrstr, port, obj->path);                 obj->addrstr, port, obj->path);
         obj->state = EConnecting;          obj->state = EConnecting;
Line 291  static void upnp_event_prepare(struct upnp_event_notif Line 335  static void upnp_event_prepare(struct upnp_event_notif
                 xml = getVarsL3F(&l);                  xml = getVarsL3F(&l);
                 break;                  break;
 #endif  #endif
   #ifdef ENABLE_6FC_SERVICE
           case E6FC:
                   xml = getVars6FC(&l);
                   break;
   #endif
   #ifdef ENABLE_DP_SERVICE
           case EDP:
                   xml = getVarsDP(&l);
                   break;
   #endif
         default:          default:
                 xml = NULL;                  xml = NULL;
                 l = 0;                  l = 0;
Line 394  void upnpevents_selectfds(fd_set *readset, fd_set *wri Line 448  void upnpevents_selectfds(fd_set *readset, fd_set *wri
                                 if(obj->s > *max_fd)                                  if(obj->s > *max_fd)
                                         *max_fd = obj->s;                                          *max_fd = obj->s;
                                 break;                                  break;
                           default:
                                   ;
                         }                          }
                 }                  }
         }          }
Line 464  void write_events_details(int s) { Line 520  void write_events_details(int s) {
         write(s, "Subscribers :\n", 14);          write(s, "Subscribers :\n", 14);
         for(sub = subscriberlist.lh_first; sub != NULL; sub = sub->entries.le_next) {          for(sub = subscriberlist.lh_first; sub != NULL; sub = sub->entries.le_next) {
                 n = snprintf(buff, sizeof(buff), " %p timeout=%d seq=%u service=%d\n",                  n = snprintf(buff, sizeof(buff), " %p timeout=%d seq=%u service=%d\n",
                             sub, sub->timeout, sub->seq, sub->service);                             sub, (int)sub->timeout, sub->seq, sub->service);
                 write(s, buff, n);                  write(s, buff, n);
                 n = snprintf(buff, sizeof(buff), "   notify=%p %s\n",                  n = snprintf(buff, sizeof(buff), "   notify=%p %s\n",
                              sub->notify, sub->uuid);                               sub->notify, sub->uuid);

Removed from v.1.1.1.1  
changed lines
  Added in v.1.1.1.2


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>