⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gena_server.c

📁 upnpsdk-1.0.4.tar.gz Intel UPnP SDK Source
💻 C
📖 第 1 页 / 共 3 页
字号:
      return UPNP_E_OUTOF_MEMORY;    }    strcpy(UDN_copy,UDN);  strcpy(servId_copy,servId);    HandleLock();  if ( GetHandleInfo(device_handle,&handle_info)!=HND_DEVICE)    {      free(UDN_copy);      free(reference_count);      free(servId_copy);      HandleUnlock();      return GENA_E_BAD_HANDLE;    }  if ( (service = FindServiceId( &handle_info->ServiceTable, 			     servId, UDN)) ==NULL)    {       free(UDN_copy);      free(reference_count);      free(servId_copy);      HandleUnlock();      return GENA_E_BAD_SERVICE;    }  DBGONLY(UpnpPrintf(UPNP_INFO,GENA,__FILE__,__LINE__,"FOUND SERVICE IN INIT NOTFY: UDN %s, ServID: %d ",UDN,servId));    if ( ( (sub=GetSubscriptionSID( sid,service))==NULL) ||       (sub->active))    {      free(UDN_copy);      free(reference_count);      free(servId_copy);      HandleUnlock();      return GENA_E_BAD_SID;    }    DBGONLY(UpnpPrintf(UPNP_INFO,GENA,__FILE__,__LINE__,"FOUND SUBSCRIPTION IN INIT NOTIFY: SID %s ",sid));  sub->active=1;    if ( (return_code=GeneratePropertySet(VarNames,VarValues,					var_count,&propertySet))!=XML_SUCCESS)    {      free(UDN_copy);      free(reference_count);      free(servId_copy);      HandleUnlock();      return return_code;    }    DBGONLY(UpnpPrintf(UPNP_INFO,GENA,__FILE__,__LINE__,"GENERATED PROPERY SET IN INIT NOTIFY: \n'%s'\n",propertySet));  headers_size=strlen("CONTENT-TYPE text/xml\r\n") +    strlen("CONTENT-LENGTH: \r\n")+MAX_CONTENT_LENGTH +    strlen("NT: upnp:event\r\n") +    strlen("NTS: upnp:propchange\r\n")+1;      headers=(char *) malloc(headers_size);    if (headers==NULL)    {      free(propertySet);      free(UDN_copy);      free(servId_copy);      free(reference_count);      HandleUnlock();      return UPNP_E_OUTOF_MEMORY;    }    sprintf(headers,"CONTENT-TYPE: text/xml\r\nCONTENT-LENGTH: %d\r\nNT: upnp:event\r\nNTS: upnp:propchange\r\n",	  strlen(propertySet)+1);     //schedule thread for initial notification  thread_struct=(notify_thread_struct *) malloc(sizeof(notify_thread_struct));  if (thread_struct==NULL)      return_code= UPNP_E_OUTOF_MEMORY;  else    {      (*reference_count)=1;      thread_struct->servId=servId_copy;      thread_struct->UDN=UDN_copy;      thread_struct->headers=headers;      thread_struct->propertySet=propertySet;      strcpy(thread_struct->sid,sid);      thread_struct->eventKey=sub->eventKey++;      thread_struct->reference_count=reference_count;      thread_struct->device_handle=device_handle;      if ( (return_code=tpool_Schedule( genaNotifyThread, thread_struct ))!=0)	{	  if (return_code==-1)	    return_code= UPNP_E_OUTOF_MEMORY;	}      else	return_code=GENA_SUCCESS;          }    if (return_code!=GENA_SUCCESS)    {           free(reference_count);      free(UDN_copy);      free(servId_copy);      free(thread_struct);      free(propertySet);      free(headers);    }  HandleUnlock();  return return_code;    }int genaInitNotifyExt(UpnpDevice_Handle device_handle, char *UDN, char *servId,IN Upnp_Document PropSet, Upnp_SID sid){  char * UDN_copy=NULL;  char * servId_copy=NULL;  char * headers=NULL;  subscription * sub=NULL;  service_info *service=NULL;  int return_code=GENA_SUCCESS;  int headers_size;  int *reference_count=NULL;  struct Handle_Info * handle_info;  Upnp_DOMString propertySet=NULL;  Upnp_DOMString TempPropSet=NULL;  notify_thread_struct *thread_struct=NULL;  DBGONLY(UpnpPrintf(UPNP_INFO,GENA,__FILE__,__LINE__,"GENA BEGIN INITIAL NOTIFY EXT"));  reference_count= (int *) malloc(sizeof(int));     if (reference_count==NULL)    return UPNP_E_OUTOF_MEMORY;    (*reference_count)=0;  UDN_copy=(char *) malloc(strlen(UDN)+1);    if (UDN_copy==NULL)    {      free(reference_count);      return UPNP_E_OUTOF_MEMORY;    }  servId_copy=(char *) malloc(strlen(servId)+1);    if (servId_copy==NULL)    {      free(UDN_copy);      free(reference_count);      return UPNP_E_OUTOF_MEMORY;    }    strcpy(UDN_copy,UDN);  strcpy(servId_copy,servId);    HandleLock();  if ( GetHandleInfo(device_handle,&handle_info)!=HND_DEVICE)    {      free(UDN_copy);      free(reference_count);      free(servId_copy);      HandleUnlock();      return GENA_E_BAD_HANDLE;    }  if ( (service = FindServiceId( &handle_info->ServiceTable, 			     servId, UDN)) ==NULL)    {       free(UDN_copy);      free(reference_count);      free(servId_copy);      HandleUnlock();      return GENA_E_BAD_SERVICE;    }  DBGONLY(UpnpPrintf(UPNP_INFO,GENA,__FILE__,__LINE__,"FOUND SERVICE IN INIT NOTFY EXT: UDN %s, ServID: %d\n",UDN,servId));      if ( ( (sub=GetSubscriptionSID( sid,service))==NULL) ||       (sub->active))    {      free(UDN_copy);      free(reference_count);      free(servId_copy);      HandleUnlock();      return GENA_E_BAD_SID;    }  DBGONLY(UpnpPrintf(UPNP_INFO,GENA,__FILE__,__LINE__,"FOUND SUBSCRIPTION IN INIT NOTIFY EXT: SID %s",sid));  sub->active=1;    TempPropSet = UpnpNewPrintDocument(PropSet);  if(TempPropSet == NULL)  {      free(UDN_copy);      free(reference_count);      free(servId_copy);      HandleUnlock();      return UPNP_E_INVALID_PARAM;  }  else  {      propertySet=strstr(TempPropSet,"<e:propertyset");      if(propertySet == NULL)      {         free(UDN_copy);         free(reference_count);         free(servId_copy);         HandleUnlock();         Upnpfree(TempPropSet);         return UPNP_E_INVALID_PARAM;      }  }  DBGONLY(UpnpPrintf(UPNP_INFO,GENA,__FILE__,__LINE__,"GENERATED PROPERY SET IN INIT EXT NOTIFY: %s",propertySet));  headers_size=strlen("CONTENT-TYPE text/xml\r\n") +    strlen("CONTENT-LENGTH: \r\n")+MAX_CONTENT_LENGTH +    strlen("NT: upnp:event\r\n") +    strlen("NTS: upnp:propchange\r\n")+1;      headers=(char *) malloc(headers_size);    if (headers==NULL)    {      free(propertySet);      free(UDN_copy);      free(servId_copy);      free(reference_count);      HandleUnlock();      return UPNP_E_OUTOF_MEMORY;    }    sprintf(headers,"CONTENT-TYPE: text/xml\r\nCONTENT-LENGTH: %d\r\nNT: upnp:event\r\nNTS: upnp:propchange\r\n",	  strlen(propertySet)+1);     //schedule thread for initial notification  thread_struct=(notify_thread_struct *) malloc(sizeof(notify_thread_struct));  if (thread_struct==NULL)      return_code= UPNP_E_OUTOF_MEMORY;  else    {      (*reference_count)=1;      thread_struct->servId=servId_copy;      thread_struct->UDN=UDN_copy;      thread_struct->headers=headers;      thread_struct->propertySet=propertySet;      strcpy(thread_struct->sid,sid);      thread_struct->eventKey=sub->eventKey++;      thread_struct->reference_count=reference_count;      thread_struct->device_handle=device_handle;      if ( (return_code=tpool_Schedule( genaNotifyThread, thread_struct ))!=0)	{	  if (return_code==-1)	    return_code= UPNP_E_OUTOF_MEMORY;	}      else	return_code=GENA_SUCCESS;          }    if (return_code!=GENA_SUCCESS)    {           free(reference_count);      free(UDN_copy);      free(servId_copy);      free(thread_struct);      free(propertySet);      free(headers);    }  HandleUnlock();  return return_code;    }int genaNotifyAllExt(UpnpDevice_Handle device_handle, char *UDN, char *servId,IN Upnp_Document PropSet){  char * headers=NULL;  int headers_size;  int return_code=GENA_SUCCESS;   char * UDN_copy=NULL;  char * servId_copy=NULL;  int *reference_count =NULL;  struct Handle_Info *handle_info;  Upnp_DOMString propertySet=NULL;  Upnp_DOMString TempPropSet=NULL;  subscription * finger=NULL;  notify_thread_struct * thread_struct=NULL;  service_info *service=NULL;  reference_count= (int *) malloc(sizeof(int));  if (reference_count==NULL)    return UPNP_E_OUTOF_MEMORY;  (*reference_count=0);  UDN_copy=(char *) malloc(strlen(UDN)+1);    if (UDN_copy==NULL)  {    free(reference_count);    return UPNP_E_OUTOF_MEMORY;  }  servId_copy=(char *) malloc(strlen(servId)+1);    if (servId_copy==NULL)    {      free(UDN_copy);      free(reference_count);      return UPNP_E_OUTOF_MEMORY;    }      strcpy(UDN_copy,UDN);  strcpy(servId_copy,servId);    TempPropSet = UpnpNewPrintDocument(PropSet);  if(TempPropSet == NULL)  {     free(UDN_copy);     free(servId_copy);     free(reference_count);     return UPNP_E_INVALID_PARAM;  }  else  {      propertySet=strstr(TempPropSet,"<e:propertyset");      if(propertySet == NULL)      {         free(UDN_copy);         free(servId_copy);         free(reference_count);         Upnpfree(TempPropSet);         return UPNP_E_INVALID_PARAM;      }  }      headers_size=strlen("CONTENT-TYPE text/xml\r\n") +    strlen("CONTENT-LENGTH: \r\n")+MAX_CONTENT_LENGTH +    strlen("NT: upnp:event\r\n") +    strlen("NTS: upnp:propchange\r\n")+1;    headers=(char *) malloc(headers_size);  if (headers==NULL)    {      free(UDN_copy);      free(servId_copy);      free(TempPropSet);      free(reference_count);      return UPNP_E_OUTOF_MEMORY;    }  //changed to add null terminator at end of content  //content length = (length in bytes of property set) + null char  sprintf(headers,"CONTENT-TYPE: text/xml\r\nCONTENT-LENGTH: %d\r\nNT: upnp:event\r\nNTS: upnp:propchange\r\n",strlen(propertySet)+1);    HandleLock();  if ( GetHandleInfo(device_handle,&handle_info)!=HND_DEVICE)    return_code=GENA_E_BAD_HANDLE;  else    {      if ( (service = FindServiceId( &handle_info->ServiceTable, 				     servId, UDN)) !=NULL)	{ 	  finger=GetFirstSubscription(service);	  	  while (finger)	    {	      thread_struct=(notify_thread_struct *) malloc(sizeof(notify_thread_struct));	      if (thread_struct==NULL)		{		  break;		  return_code= UPNP_E_OUTOF_MEMORY;		}	      (*reference_count)++;	      thread_struct->reference_count=reference_count;	      thread_struct->UDN=UDN_copy;	      thread_struct->servId=servId_copy;	      thread_struct->headers=headers;	      thread_struct->propertySet=propertySet;	      strcpy(thread_struct->sid,finger->sid);	      thread_struct->eventKey=finger->eventKey++;	      thread_struct->device_handle=device_handle;	      //if overflow, wrap to 1	      if (finger->eventKey<0)		finger->eventKey=1;	      	      if ( (return_code=tpool_Schedule( genaNotifyThread, thread_struct ))!=0)		{		  if (return_code==-1)		    return_code= UPNP_E_OUTOF_MEMORY;		  break;		}	      	      finger=GetNextSubscription(service,finger);	      	    }	}      else	return_code=GENA_E_BAD_SERVICE;      }    if ((*reference_count)==0)    {      free(reference_count);      free(headers);      free(TempPropSet);      free(UDN_copy);      free(servId_copy);    }  HandleUnlock();    return return_code;}int genaNotifyAll(UpnpDevice_Handle device_handle,	       char *UDN,	       char *servId,	       char **VarNames,	       char **VarValues,		  int var_count	       ){  char * headers=NULL;  char * propertySet=NULL;  int headers_size;  int return_code=GENA_SUCCESS;  char * UDN_copy=NULL;  char * servId_copy=NULL;  int *reference_count =NULL;  struct Handle_Info *handle_info;  subscription * finger=NULL;  notify_thread_struct * thread_struct=NULL;  service_info *service=NULL;  reference_count= (int *) malloc(sizeof(int));  if (reference_count==NULL)    return UPNP_E_OUTOF_MEMORY;  (*reference_count=0);  UDN_copy=(char *) malloc(strlen(UDN)+1);    if (UDN_copy==NULL)  {    free(reference_count);    return UPNP_E_OUTOF_MEMORY;  }  servId_copy=(char *) malloc(strlen(servId)+1);    if (servId_copy==NULL)    {      free(UDN_copy);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -