コード例 #1
0
ファイル: zfs.c プロジェクト: jamesyan84/zbase
static int ProcessVideoFile(const char *filePath)
{
	ZInfo4(DBG_MISC, "video: %s", filePath);

	ZDB_METAVIDEO *metadata = NULL;
	char filename[MAX_PATH_SIZE] = {0};
	char dstPath[MAX_PATH_SIZE] = {0};
	int isDir;

	if((metadata = GetVideoMetadata((char *)filePath)) == NULL) {
		ZError(DBG_MISC, "Get video metadata failed!");
		return -1;
	}
	getFileName(filePath, &filename[0]);
	sprintf(dstPath, "%s/%s", VIDEO_SORT_FOLDER, filename);
	if(ZUtilIsFilePresent(dstPath, &isDir)) {
		getNewFileName(pzfs, filename);
		sprintf(dstPath, "%s/%s", VIDEO_SORT_FOLDER, filename);
		ZInfo3(DBG_MISC, "File exist, will use new filename [%s]", filename);
	}
	if(metadata->res)
		free(metadata->res);
	metadata->res = strdup(dstPath);
	if(ZDBInsertVideo(zfs.zVDBHandle, metadata)) {
		ZError(DBG_MISC, "Insert Video to DB failed!");
		free(metadata);
		return -2;
	}
	if (rename (filePath, dstPath) != 0) {
		ZError (DBG_MISC, "Move file failed -> %s -> %s", filePath, dstPath);
	}
	free(metadata);
	return 0;
}
コード例 #2
0
ファイル: mpsync.c プロジェクト: jamesyan84/zbase
static int GetNextAssociatedID(PZQSESSION p_session, int* p_id)
{
    char * p_aux;
    char psz_id[9];

    p_aux = p_session->psz_associated;

    if ( p_aux == NULL || !*p_aux)
        return 0;

    ZError( DBG_MISC, "Entering ..." );
    while ( *p_aux && (*p_aux != ',' || *p_aux == ' ') )
        p_aux++;
    if ( *p_aux != 0 )
    {
        memcpy( psz_id, p_session->psz_associated, p_aux- p_session->psz_associated);
        psz_id[p_aux- p_session->psz_associated] = 0;
        p_session->psz_associated = p_aux+1;
        *p_id = atoi(psz_id);
        return 1;
    }
    else
    {
        *p_id = atoi( p_session->psz_associated);
        ZError( DBG_MISC, "id->%d ...", *p_id );
        p_session->psz_associated = NULL;
        return 1;
    }

}
コード例 #3
0
ファイル: znetwork.c プロジェクト: jamesyan84/zbase
int IsLinkUp(const char *dev)
{
    struct ifreq ifr;
    int sockfd;

    /* Create socket */
    sockfd = socket(AF_INET, SOCK_STREAM, 0);
    if (sockfd < 0)
    {
        ZError(DBG_ZDEVCFG,"socket open failed\n");
        return ZQERROR;
        /* Can't clean_exit(), will recurse - Jean II */
    }
    /* Try to read flags. Will fail if device doesn't exist */
    strncpy(ifr.ifr_name, dev, IFNAMSIZ);
    if (ioctl(sockfd, SIOCGIFFLAGS, &ifr) < 0)
    {
        ZError(DBG_ZDEVCFG,"IO control SIOCGIFFLAGS failed\n");
        close (sockfd);
        return ZQERROR;
    }

    int iRet=do_gset(sockfd,&ifr);
    close(sockfd);
    /**
    0 implies link down
    1 implies link up
     **/
    return iRet;
}
コード例 #4
0
ファイル: wakeupd.c プロジェクト: jamesyan84/zbase
/*--------------------------------------------------
* Function: createUDPSocket
* Description:
* 	Create UDP socket to listen or to send.
* Parameters:
* 	@ip:	IP address the socket will create
* 	@port:	port the socket will create
* 	@type:	socket type to create,
* 			0 for Listener
*        		1 for Sender
* Returns:
* 	Return socket file descriptor,
* 	Return -1 if create failed.
*--------------------------------------------------*/
int CreateUDPSocket(char *ip, int port, int type)
{
	struct sockaddr_in  addr;
	int sockfd;
	int onOff = 1;
	addr.sin_family = AF_INET;
	addr.sin_addr.s_addr = inet_addr(ip);
	addr.sin_port = htons(port);
	if ((sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
		ZError(DBG_INIT, "Failed to create UDP socket on %s:%d\n", ip, port);
		return(-1);
	}
	if(type == 0) {
		// Listener
		setsockopt(sockfd,SOL_SOCKET, SO_REUSEADDR, &onOff, sizeof(int));
		if (bind(sockfd, (struct sockaddr *)&addr, sizeof(addr)) != 0) {
			ZError(DBG_INIT, "Failed to bind socket on %s:%d\n", ip, port);
			close(sockfd);
			return(-1);
		}
	}
	else {
		// Sender
		if(connect(sockfd, (struct sockaddr *)&addr, sizeof(addr)) != 0) {
			ZError(DBG_INIT, "Failed to connect socket to %s:%d\n", ip, port);
			close(sockfd);
			return(-1);
		}
	}
	return(sockfd);
}
コード例 #5
0
ファイル: profilelib.c プロジェクト: jamesyan84/zbase
static int sqlite3_get_table_wrap2(PZDB_HANDLE zDB,
                                  char        *sql,
                                  char        ***result,
                                  int         *nrow,
                                  int         *ncol)
{
  char  *errMsg;
  int   retry = 0;
  int   retVal;

  *nrow = *ncol = 0;

   ZError(DBG_ZDB, "SQL Statement->%s", sql);

retry:
  if ((retVal = sqlite3_get_table(zDB->sqlHandle,
                                  sql, result,
                                  nrow,  ncol, &errMsg)) != SQLITE_OK) {
    ZError(DBG_ZDB, "SQL Statement->%s Failed->%s : retry->%d",
           sql, errMsg, retry);
    sqlite3_free(errMsg);
    if (retry++ == ZDB_RETRIES) {
      return(retVal);
    }
    sleep(1);
    goto retry;
  }
  #ifdef PROFILE_DEBUG  
  printf("Result nrow->%d, ncol->%d\n", *nrow, *ncol);
  #endif
  ZInfo3(DBG_ZDB, "Result nrow->%d, ncol->%d", *nrow, *ncol);
  return(retVal);
}
コード例 #6
0
ファイル: wakeupd.c プロジェクト: jamesyan84/zbase
/*--------------------------------------------------
*  Function: SendZMXEvent
*  Description:
* 	Send ZMX event msssage via UDP to @port on local
*  Parameters:
* 	@port:		local port to send
* 	@buffer:	event message to send
* 	@bufferLength:	event message length
*  Returns:
*--------------------------------------------------*/
int SendZMXEvent(int port, char *buffer, int bufferLength)
{
	int udpSocket = -1;
	int ret = 0;
	
	ZInfo4(DBG_MISC, "Will send buffer to port->[%d], buffer: %s, length: %d\n", port, buffer, bufferLength);
	if ((udpSocket = CreateUDPSocket("127.0.0.1", port, 1)) == -1) {
		ZError(DBG_INIT, "Unable to create server socket.");
		return -1;
	}

	if(buffer != NULL) {
		ret = write(udpSocket, buffer, bufferLength);
		if(ret > 0) {
			ZInfo4(DBG_MISC, "%d bytes wrote", ret);
			close(udpSocket);
			return 0;
		}
		else {
			ZError(DBG_MISC, "Error happened when sending ZMX, %d byte wrote", ret);
			close(udpSocket);
			return -1;
		}
	}
	else {
		ZError(DBG_MISC, "ZMX Message is empty");
		close(udpSocket);
		return -1;
	}
}
コード例 #7
0
ファイル: util.c プロジェクト: jamesyan84/zbase
static int matchContentType( char* type1, char* type2 )
{
    char* p_aux1, *p_aux2;
    char* p_type1, *p_type2;
    int i_ret;

    if ( type1== NULL && type2 != NULL ) return -1;
    if ( type1!= NULL && type2 == NULL ) return 1;
    if ( type1== NULL && type2 == NULL ) return 0;

    p_type1 = strdup(type1);
    p_type2 = strdup(type2);
    p_aux1 = strchr( p_type1, '/' );
    p_aux2 = strchr( p_type2, '/' );

    if ( p_aux1 && !p_aux2 ) {
        i_ret = 1;
        goto funcOut;
    }
    if ( !p_aux1 && p_aux2 ) {
        i_ret = -1;
        goto funcOut;
    }

    if ( !p_aux1 && !p_aux2) {
        i_ret = strcasecmp( type1, type2 );
        goto funcOut;
    }


    *p_aux1 = 0;
    *p_aux2 = 0;

    p_aux1++;
    p_aux2++;
    ZError( DBG_MISC, "%s, %s", p_type1, p_aux1 );
    ZError( DBG_MISC, "%s, %s", p_type2, p_aux2 );
    if ( *type1 == '*' || *type2 == '*')
    {
        if ( *p_aux1=='*' || *p_aux2=='*' ) {
            i_ret =  0; goto funcOut;
        }
        i_ret = strcasecmp( p_aux1, p_aux2 ); 
        goto funcOut;
    }
    else
    {
        i_ret = strcasecmp(p_type1, p_type2);
        if (!i_ret) goto funcOut;
        if ( *p_aux1=='*' || *p_aux2=='*' ){
            i_ret = 0; goto funcOut;
        } 
        i_ret = strcasecmp( p_aux1, p_aux2 );
    }
funcOut:
    free( p_type1 );
    free( p_type2 );
    return i_ret;
}
コード例 #8
0
ファイル: kurolyric.c プロジェクト: jamesyan84/zbase
KuroLRC* LoadKuroLRC(const char *uri)
{
	char *utf8Buf = NULL;
	int utf8Len, res;
	gchar *encryptBuf = NULL;
	gchar *decryptBuf = NULL;
	guint encryptLen, decryptLen;
	KuroLRC *lrc = NULL;
	
	/* Check to see if it is the remote uri??? */
	ZInfo1(DBG_INIT, "NOTE: Loading LRC file->%s", uri);
	if(zg_uri_validate(uri)) {
		res = KuroLRCLoadRemote(uri, &encryptBuf, &encryptLen);
		if(res != ZAPP_SUCCESS) {
			ZError(DBG_INIT, "Failed to handle the remote LRC -> %s", uri);
			return NULL;
		}
	}
	else {
		res = KuroLRCLoadLocal(uri, &encryptBuf, &encryptLen);
		if(res != ZAPP_SUCCESS) {
			ZError(DBG_INIT, "Failed to handle the local LRC -> %s", uri);
			return NULL;
		}
	}
	//ZInfo1(DBG_INIT, "Buffer encryptText (%d)->\n%s", encryptLen, encryptBuf);
	
	ZInfo1(DBG_INIT, "NOTE: Decompress LRC data.");
	/* Decrypt buffer */
	DecompressData((const void *)encryptBuf, encryptLen, (void**)&decryptBuf, &decryptLen);
	if(decryptLen == 0) {
		ZError(DBG_INIT, "Failed to DecompressData LRC.");
		return NULL;
	}
	//ZInfo1(DBG_INIT, "Buffer plainText (%d)->\n%s", decryptLen, decryptBuf);
	
	ZInfo1(DBG_INIT, "NOTE: Convert LRC data to utf8.");
	/* Convert the buffer to UTF-8 */
	if(BufToUtf8(decryptBuf, decryptLen, &utf8Buf, &utf8Len) != 0) {
		ZError(DBG_INIT, "Failed to execute BufToUtf8.");
		ZFREE(decryptBuf);
		return NULL;
	}
	ZFREE(decryptBuf);
	ZInfo1(DBG_INIT, "UTF-8 plainText (%d)->\n%s", utf8Len, utf8Buf);
	
	ZInfo1(DBG_INIT, "NOTE: Parse LRC data.");
	/* Parse LRC */
	lrc = ParseKuroLRC(utf8Buf);
	if(lrc == NULL) {
		ZError(DBG_INIT,"Failed to parse LRC.");
		ZFREE(utf8Buf);
		return NULL;
	}
	ZInfo1(DBG_INIT, "NOT: LoadKuroLRC Done");
	ZFREE(utf8Buf);
	return lrc;
}
コード例 #9
0
ファイル: znetwork.c プロジェクト: jamesyan84/zbase
static int GetTestInternetSite(IN int iIndex , OUT char * pSite)
{
	 /*dummy using*/
    int i=0;
	int iRet=ZQERROR;
	const int maxdns=10;
    char *dnsname[maxdns];

	/* Currenly we allow two DNS */
	if(iIndex>2 || iIndex<0)
	{return ZQERROR;}	

	/*Already retrieved DNS values*/
	if(strlen(m_TestSite[0])>0)
	{goto ExitPoint;}

	/* Since there may more than 2 DNS , 
	we need enlarge the array to contain the retrieved DNS*/
	for(i=0;i<maxdns;i++)
    {
    	/* NOTE , the max DNS size is ZMAXELEMVALUE*/
        dnsname[i]=(char *)malloc(sizeof(char)*ZMAXELEMVALUE);
        if(!dnsname[i])
        {
			ZError( DBG_ZDEVCFG, "Allocation error");
            return ZQERROR;
        }
        memset(dnsname[i],0,sizeof(char)*ZMAXELEMVALUE);
    }

	/* Saving value to  m_TestSite */
	iRet=retrieveDNS(dnsname, &i);

	/* We only use the first two DNS */
	strncpy(m_TestSite[0],dnsname[0],ZMAXELEMVALUE-1);
	strncpy(m_TestSite[1],dnsname[1],ZMAXELEMVALUE-1);
	
	for(i=0;i<maxdns;i++)
	{free(dnsname[i]);}
	if (iRet<0)
	{	
		ZError(DBG_ZDEVCFG, "Failed to retrieve DNS");
		return iRet;
	}	

	ZInfo4(DBG_ZDEVCFG, "Using DNT detection:Test DNS 0: %s", m_TestSite[0]);
	ZInfo4(DBG_ZDEVCFG, "Using DNT detection:Test DNS 1: %s", m_TestSite[1]);
		

ExitPoint:
	/* Return test site */
	memset(pSite,0,sizeof(char)*64);	
	sprintf(pSite,"%s",m_TestSite[iIndex]);

	return ZQSUCCESS;
}
コード例 #10
0
    ZString TranslateElementName(const ZString& strDevice)
    {
        if (strDevice.Find(':') != -1)
        {
            return strDevice;
        }
        else
        {
            // get a list of all of the drives on the system
            char cTemp;
            int nDrivesStringLength = GetLogicalDriveStringsA(1, &cTemp);
            if (nDrivesStringLength == 0)
            {
                ZError("Error getting drives list\n");
                return strDevice;
            }

            char* cbDrives = (char*)_alloca(nDrivesStringLength);
    
            nDrivesStringLength = GetLogicalDriveStringsA(nDrivesStringLength, cbDrives);

            if (nDrivesStringLength == 0)
            {
                ZError("Error getting drives list\n");
                return strDevice;
            }

            // search through the list of drives looking for a CD-ROM who's volume 
            // label matches strDevice
            while (cbDrives[0] != '\0')
            {
                const int c_nVolumeNameLength = 1024;
                char cbVolumeName[c_nVolumeNameLength];
                
                if (GetDriveTypeA(cbDrives) == DRIVE_CDROM
                    && GetVolumeInformationA(cbDrives, cbVolumeName, 
                        c_nVolumeNameLength, NULL, NULL, NULL, NULL, 0))
                {
                    if (_stricmp(strDevice, cbVolumeName) == 0)
                    {
                        return cbDrives;
                    }
                }

                cbDrives += strlen(cbDrives) + 1;
            }

            return strDevice;
        }
    }
コード例 #11
0
ファイル: znetwork.c プロジェクト: jamesyan84/zbase
int zRemoveDefGateway(const char * deviceName , char * strLastDefDw)
{
	struct sockaddr_in *dst, *gw, *mask;
    struct rtentry route;
    int sockfd;
    int i_ret = ZQERROR;

	i_ret=retrieveDefGateway(deviceName,strLastDefDw);
	if(i_ret<0)
	{
		ZError( DBG_ZDEVCFG, "Retrieving last default dw failed");		
	}
	
    sockfd = socket(AF_INET, SOCK_DGRAM, 0);
    if (sockfd   ==   -1)
    {
        ZError( DBG_ZDEVCFG, "%s", strerror(errno) );
        return   i_ret;
    }

    memset(&route,0,sizeof(struct rtentry));

    dst = (struct sockaddr_in *)(&(route.rt_dst));
    gw = (struct sockaddr_in *)(&(route.rt_gateway));
    mask = (struct sockaddr_in *)(&(route.rt_genmask));

    /* Make sure we're talking about IP here */
    dst->sin_family = AF_INET;
    gw->sin_family = AF_INET;
    mask->sin_family = AF_INET;

    /* Set up the data for removing the default route */
    dst->sin_addr.s_addr = 0;
    gw->sin_addr.s_addr = 0;
    mask->sin_addr.s_addr = 0;
    route.rt_dev=(char *)deviceName;
    route.rt_flags = RTF_UP | RTF_GATEWAY;
    route.rt_dev = (char*)deviceName; /*add by emman*/
    /* Remove the default route */
    ioctl(sockfd,SIOCDELRT,&route);

	i_ret = ZQSUCCESS;

    if ( sockfd > 0 )
    {close(sockfd);}

    return i_ret;

}
コード例 #12
0
ファイル: zdb.c プロジェクト: jamesyan84/zbase
int isAlbumArtExists (PZFS pzfs, char *album)
{
    char sql[1024] = { 0 };

    char albumName[MAX_NAME_SIZE];
    memset (albumName, 0, MAX_NAME_SIZE);
    /* NOTE: we have to escape before execute sql */
    escapeStr (album, albumName);

    sprintf (sql,
	     "select t_album.albumArtURI from t_album, t_object where t_album.obj_id=t_object.obj_id and t_object.itemstate=0 and t_album.title='%s';",
	     albumName);
    char **result = NULL;
    int ncol;
    int nrow;

    /* Execute sql */
    if (sqlite3_get_table_wrap (pzfs->zDBHandle, sql, &result, &nrow, &ncol)
	!= SQLITE_OK)
	{
	    ZError (DBG_MISC, "query album art data failed.");
	    goto errOut;
	}

    int count;
    ZError (DBG_MISC, "AlbumArt result, nrow->%d, ncol->%d, albumArt->%s",
	    nrow, ncol, ncol > 0 ? result[ncol + 0] : "(none)");

    /* Check, if the albumArtURI empty */
    if (ncol > 0 && result[ncol + 0] && strlen (result[ncol + 0]) > 5)
	{
	    count = 1;
	    ZInfo4 (DBG_MISC, "---- deny insert ---- ");
	}
    else
	{
	    count = 0;
	    ZInfo4 (DBG_MISC, "---- allow insert ---- ");
	}

    if (result)
	ZDBFreeResult (result);
    return count;

  errOut:
    if (result)
	ZDBFreeResult (result);
    return -1;
}
コード例 #13
0
ファイル: cms.c プロジェクト: jamesyan84/zbase
int CMSGetProtocolInfo(struct Upnp_Action_Request *actEvent)
{
  char    *source;
  char    *sink;

  ZTrace(DBG_DMS_CMS, "Entering");

  if ((source = DMSGetVariable(DMS_SERVICE_CMS, "SourceProtocolInfo")) == NULL) {
    ZError(DBG_DMS_CDS, "Unable to get SourceProtocolInfo Variable");
    goto funcOut;
  }

  // No input parameters... Return protInfo in the action Result...
  // ActionResult has to be setup...
  // In case of errors, need to setup ErrCode and ErrStr....
  actEvent->ErrCode = UPNP_E_SUCCESS;
  if (UpnpAddToActionResponse(&actEvent->ActionResult,
                              "GetProtocolInfo",
                              dms.dmsServ[DMS_SERVICE_CMS].serviceType,
                              "Source", source) != UPNP_E_SUCCESS) {
    ZError(DBG_DMS_CMS, "Unable to set Source");
    goto funcOut;
    
  }

  if ((sink = DMSGetVariable(DMS_SERVICE_CMS, "SinkProtocolInfo")) == NULL) {
    ZError(DBG_DMS_CDS, "Unable to get SinkProtocolInfo Variable");
    goto funcOut;
  }


  if (UpnpAddToActionResponse(&actEvent->ActionResult,
                              "GetProtocolInfo",
                              dms.dmsServ[DMS_SERVICE_CMS].serviceType, 
                              "Sink", sink) != UPNP_E_SUCCESS) {
    ZError(DBG_DMS_CMS, "Unable to set Sink");
    goto funcOut;
  }

funcOut:
  if (actEvent->ErrCode != UPNP_E_SUCCESS) {
    actEvent->ActionResult = NULL;
    actEvent->ErrCode = UPNP_E_INTERNAL_ERROR;
    strcpy(actEvent->ErrStr, "Internal Error");
  }
  
  ZTrace(DBG_DMS_CMS, "Exiting->%d", actEvent->ErrCode);
  return actEvent->ErrCode;
}
コード例 #14
0
ファイル: mpsynctest.c プロジェクト: jamesyan84/zbase
void  printAllDMS( )
{
  int ifIndex;
  PCP_DEV_NODE  devNode = NULL;
  ZError( DBG_MISC, "=========================================================================" );
  for (ifIndex = mpsync.numAddr-1; ifIndex >=0; ifIndex--) {
    if (mpsync.dmcHandle[ifIndex] == NULL ) continue;
    devNode = DMCFindFirstDev(mpsync.dmcHandle[ifIndex]);
    while (devNode) {
      ZError( DBG_MISC, "DEV ifindex->%d und->%s, type->%s",  ifIndex, devNode->UDN, devNode->deviceType);
      devNode = DMCFindNextDev(mpsync.dmcHandle[ifIndex]);
    }
    DMCFindCloseDev(mpsync.dmcHandle[ifIndex]);
  }
}
コード例 #15
0
ファイル: zkplayernetwork.c プロジェクト: jamesyan84/zbase
static void ResponseCMD(int sockfd, char *op, int uError)
{
	char bufArray[BUF_8192] = {0};
	char codeArray[BUF_128] = {0};
	int i, n, size;
	ERR_INFO *info = errInfo;
	
	size = sizeof(errInfo)/sizeof(errInfo[0]);
	for(i=0; i<size; i++) {
		if(info[i].uError == uError)
			break;
	}
	if(i==size) {
		ZError(DBG_INIT, "Invalid response uError.");
		return;
	}
	
	if(info[i].uError != 0)
		sprintf(codeArray, "%s%05d", ZKPLAYER_MODULE_CODE, info[i].uError);
	else
		sprintf(codeArray, "0");
	
	n = sprintf(bufArray, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n\
<ret op=\"%s\" mod=\"zkplayer\">\n\
<err>%s</err>\n\
<msg>%s</msg>\n\
</ret>", op, codeArray, info[i].msg);
	
	i = write(sockfd, bufArray, n);
	ZInfo1(DBG_INIT, "Response XML(%d) -> %s\n", i, bufArray);
}
コード例 #16
0
ファイル: trekctrls.cpp プロジェクト: kgersen/Allegiance
    Point GetSidePoint(int side)
    {
        const Rect& rect = GetRect()->GetValue();
        float xmin  = rect.XMin();
        float xmax  = rect.XMax();
        float xhalf = (xmin + xmax) / 2;
        float ymin  = rect.YMin();
        float ymax  = rect.YMax();
        float yhalf = (ymin + ymax) / 2;

        switch (side) {
            case ATLeft:        return Point(xmin,  yhalf);
            case ATTopLeft:     return Point(xmin,  ymax );
            case ATTop:         return Point(xhalf, ymax );
            case ATTopRight:    return Point(xmax,  ymax );
            case ATRight:       return Point(xmax,  yhalf);
            case ATBottomRight: return Point(xmax,  ymin );
            case ATBottom:      return Point(xhalf, ymin );
            case ATBottomLeft:  return Point(xmin,  ymin );
            case ATCenter:      return Point(xhalf, yhalf);

            default:
                ZError("Unknown side");
                return Point::GetZero();
        }
    }
コード例 #17
0
ファイル: zkplayerutil.c プロジェクト: jamesyan84/zbase
/* DFB API */
IDirectFBWindow* dfb_create_window (IDirectFB *dfb, int x, int y, int width, int height, gboolean isAlpha)
{
	DFBResult err;
	DFBWindowDescription dsc;
	IDirectFBWindow *window = NULL;
	IDirectFBDisplayLayer *layer = NULL;
	
	DFBCHECK(dfb->GetDisplayLayer(dfb, DLID_PRIMARY, &layer));
	layer->SetCooperativeLevel(layer, DLSCL_ADMINISTRATIVE);
	
	dsc.flags = DWDESC_POSX | DWDESC_POSY | DWDESC_WIDTH | DWDESC_HEIGHT;
	dsc.posx = x;
	dsc.posy = y;
	dsc.width = width;
	dsc.height = height;
	if(isAlpha) {
		dsc.flags |= DWDESC_CAPS;
		dsc.caps   = DWCAPS_ALPHACHANNEL;
	}
	err = layer->CreateWindow (layer, &dsc, &window);
	if (err!=DR_OK) {
		ZError(DBG_INIT, "Failed  to dfb_create_window.");
		return NULL;
	}
	/* Set ZKPlayer to Bottom but upper ZImagePlayer */
	DFBCHECK(window->LowerToBottom(window));
	DFBCHECK(window->SetOpacity(window, 0x0));
	return window;
}
コード例 #18
0
ファイル: palette.cpp プロジェクト: AllegianceZone/Allegiance
    PaletteImpl(IDirectDrawPaletteX* pddpal) :
        m_pddpal(pddpal)
    {
        DWORD caps;

        DDCall(m_pddpal->GetCaps(&caps));

        int count;

        if (caps & DDPCAPS_4BIT) {
            count = 16;
        } else if (caps & DDPCAPS_8BIT) {
            count = 256;
        } else {
            ZError("Unsupported palette size");
        }

        PALETTEENTRY ppe[256];
        DDCall(m_pddpal->GetEntries(0, 0, count, ppe));

        m_pcolors.SetCount(count);
        for (int index = 0; index < count; index++) {
            float scale = (1.0f / 255);

            m_pcolors.Set(
                index,
                Color(
                    ppe[index].peRed   / 255.0f,
                    ppe[index].peGreen / 255.0f,
                    ppe[index].peBlue  / 255.0f
                )
            );
        }
    }
コード例 #19
0
ファイル: zkplayerutil.c プロジェクト: jamesyan84/zbase
int SocketCreate(char *ip, int port, SOCKET_TYPE type, SOCKET_MODE mode)
{
	struct sockaddr_in  addr;
	int sockfd;
	int onOff = 1;
	
	addr.sin_family = AF_INET;
	addr.sin_port = htons(port);
	addr.sin_addr.s_addr = (ip == NULL) ? htonl(INADDR_ANY) : inet_addr(ip);
	
	if(type == SOCKET_TCP)
		sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
	else
		sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
	if(sockfd == -1) {
		ZError(DBG_INIT, "Failed to create  socket on %s:%d", ip, port);
		return -1;
	}
	
	//080904, JC add
	//set close-on-exec flag to avoid the socket inherited by child process
	fcntl(sockfd, F_SETFD, FD_CLOEXEC);
	
	if(mode == SOCKET_LISTENER) {
		// Listener
		setsockopt(sockfd,SOL_SOCKET, SO_REUSEADDR, (const void *)&onOff, sizeof(onOff));
		if (bind(sockfd, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
			ZError(DBG_INIT, "Failed to bind socket on %s:%d", ip, port);
			goto errOut;
		}
		if(listen(sockfd, 10) == -1) {
			ZError(DBG_INIT, "Failed to listen socket on %s:%d", ip, port);
			goto errOut;
		}
	}
	else {
		// Sender
		if(connect(sockfd, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
			ZError(DBG_INIT, "Failed to connect socket to %s:%d", ip, port);
			goto errOut;
		}
	}
	return(sockfd);
errOut:
	close(sockfd);
	return -1;
}
コード例 #20
0
ファイル: znetwork.c プロジェクト: jamesyan84/zbase
int isRunning(const char * deviceName)
{
    if (NULL==deviceName)
    {
        ZError(DBG_ZDEVCFG, "Invalid parameters , please check.");
        return ZQERROR;
    }

    register int fd = 0;
    struct ifreq ifr;
    int ret = -1;    
    
    if ((fd = socket (AF_INET, SOCK_DGRAM, 0)) >= 0)
    {
		strncpy(ifr.ifr_name, deviceName, sizeof(ifr.ifr_name));
		/* Get interface flags from socket */
		if (ioctl (fd, SIOCGIFFLAGS, &ifr) < 0)
		{
			ZError(DBG_ZDEVCFG, "SIOCGIFFLAGS ioctl ERROR."); 
			close (fd);
			return -1;
		}

		if (ifr.ifr_flags & IFF_UP)
		{
			ret = RUNNING;
		}
		else
		{
			ret = DOWN;
		}
	} 
	else
	{
		ZError(DBG_ZDEVCFG, "Socket failed , fd->[%d].",fd); 
		return ZQERROR;
	}

    close (fd);

	if(ret < 0) 
		ZWarning( DBG_ZDEVCFG, "isRunning return %d [%s]", ret,deviceName);
	
    return ret;	

 }
コード例 #21
0
ファイル: zfs.c プロジェクト: jamesyan84/zbase
static int ProcessPhotoFile(const char *filePath)
{
	ZInfo4(DBG_MISC, "photo: %s", filePath);

	ZDB_METAPHOTO 	*metadata = NULL;
	char		 	filename[MAX_PATH_SIZE] = {0};
	char 			dstPath[MAX_PATH_SIZE] = {0};
	int 			isDir;

	if((metadata = GetPhotoMetadata((char *)filePath)) == NULL) {
		ZError(DBG_MISC, "Get audio metadata failed!");
		return -1;
	}

	getFileName(filePath, &filename[0]);
	sprintf(dstPath, "%s/%s", PHOTO_SORT_FOLDER, filename);
	
	if(ZUtilIsFilePresent(dstPath, &isDir)) {
		getNewFileName(pzfs, filename);
		sprintf(dstPath, "%s/%s", PHOTO_SORT_FOLDER, filename);
		ZInfo3(DBG_MISC, "File exist, will use new filename [%s]", filename);
	}

	if(metadata->res)
		free(metadata->res);
	metadata->res = strdup(dstPath);
	
	if (rename (filePath, dstPath) != 0) {
		ZError (DBG_MISC, "Move file failed -> %s -> %s", filePath, dstPath);
	}
	
	//add by Joe on 2008-10-30
#ifdef 		Z_CFG_PHOTO_THUMBNAIL
	createThumbnailPhoto(dstPath, &metadata->attr2);
#endif
	//end
	
	if(ZDBInsertPhoto(zfs.zPDBHandle, metadata)) {
		ZError(DBG_MISC, "Insert photo to DB failed!");
		free(metadata);
		return -2;
	}
	free(metadata);
	return 0;
}
コード例 #22
0
ファイル: zfs.c プロジェクト: jamesyan84/zbase
int createThumbnailPhoto(const char *path, char **attr2)
{
	IXML_Document 	*doc = NULL;
	char 			reqXML[2048] = {0};
	char 			thumbnail[1024] = {0};
	char 			respondBuf[2048] = {0};
	char 			*errNum = NULL;
	char 			*errMsg = NULL;
	int  			respondLen = 2048;

	getThumbnail(path, thumbnail);

	if(fileExists(thumbnail) == 1)
		remove(thumbnail);

	sprintf (reqXML, "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
			"<cmd>"
			"<InputLocation>%s</InputLocation>"
			"<OutputLocation>%s</OutputLocation>"
			"<Size>128</Size>"
			"</cmd>",
			path, thumbnail);
	
	if(processTCPReqRsp(ZAPP_ZSCALE_SOCKET, reqXML, strlen(reqXML), respondBuf, &respondLen, 3) == 0){
		if((doc = ixmlParseBuffer(respondBuf)) != NULL){
			errNum = ixmlGetFirstDocumentItem(doc, "err");
			if(strcmp(errNum, "0") != 0){
				errMsg = ixmlGetFirstDocumentItem(doc, "msg");
				ZError(DBG_MISC, "create thumbnail failed. errNum->%s, errMsg-> %s", errNum, errMsg);
				free(errMsg);
			}
			else
				*attr2 = strdup(thumbnail);

			free(errNum);
			ixmlDocument_free(doc);
		}
		else
			ZError(DBG_MISC, "zscale respond is NULL");
	}
	else
		ZError(DBG_MISC, "call zscale failed.");

	return 0;
}
コード例 #23
0
ファイル: zqstate.c プロジェクト: jamesyan84/zbase
void dumpWorkStatus()
{
	int i;
	for(i = 0; i < MAX_WORK_STATUS; i++) {
		ZError(DBG_MISC, "workStatus:[%s], state[%d], stop[%d]",
			       	GetWorkName(i), 
				GetWorkStatus(i),
				GetWorkStatusStopFlag(i));
	}
}
コード例 #24
0
ファイル: zdbutil.c プロジェクト: jamesyan84/zbase
/************************************************************************
* Function: updateRenameCount 
* * Parameters:
*       IN long count: current renamecount value
*
* Description:
*       Store rename count value to file 
*
* Returns:
*       0 if successful else appropriate error
***************************************************************************/
int updateRenameCount( long count)
{
    char tmp[1024] = { 0 };
    FILE *fp = NULL;
    if ((fp = fopen (RENAMECOUNTFILE, "r")) == NULL)
        {
            ZError (DBG_MISC, "The count file doesn't exists->%s",
                    RENAMECOUNTFILE);
            return -1;
        }
    fclose (fp);
    /* exists */
    sprintf (tmp, "echo %ld > %s", count, RENAMECOUNTFILE);
    if (executeCMD (tmp) != 0){
            ZError (DBG_MISC, "Update count file failed->%s", tmp);
            return -1;
    }
    return 0;
}
コード例 #25
0
ファイル: zqactionpreprocess.c プロジェクト: jamesyan84/zbase
int PreStartRestore(struct Upnp_Action_Request *actEvent)
{
	ZInfo4(DBG_MISC, "will kill zmonitor zplayer zappdms zappdmr zfs samba");

	if(runCommand(ZSTART " --kill zmonitor zappdms zappdmr zplayer zfs samba>/dev/null 2>&1") != 0) {
		ZError(DBG_MISC, "Fail to kill zmonitor zplayer zappdms zappdmr zfs samba");
		return FALSE;
	}
	return TRUE;
}
コード例 #26
0
ファイル: zfs.c プロジェクト: jamesyan84/zbase
/************************************************************************
* Function: initZFS
* Description:
*       init the zfs
* Parameters:
*      @pzfs:zfs pointer
* Returns:
*      -1 if execute failed, else 0
* Addy by steven 2008-3-4
***************************************************************************/
static int initZFS (PZFS pzfs)
{
    if (inotifyInit (pzfs) != 0)
	{
	    ZError (DBG_MISC, "inotifyInit failed");
	    return -1;
	}
    ZLockInit (&pzfs->iLock);
    ZLockInit (&pzfs->nLock);
    ZLockInit (&pzfs->icLock);
    /* create watch tree, we want the watchTree safe, set offset to zero */
    ZUtilCreateTree (&pzfs->watchTree, 1, 0);
    /* create task queue, we want the taskQ safe */
    if (ZUtilCreateQ (&pzfs->taskQ, 1, 1) != 0)
	{
	    ZError (DBG_MISC, "init taskQ failed");
	    return -1;
	}
    /* NOTE: the is the presist count number (xxx_UUDDPPxxx.mp3) */
    if (getCountNum (pzfs) != 0)
	{
	    ZError (DBG_MISC, "init count failed");
	    return -1;
	}
    ZInfo4 (DBG_MISC, "count->%d", pzfs->count);

    /* initialize zDBHandle for audio */
    if (ZDBOpen (Z_UTIL_ZFS, AUDIO_DB_FILE, &pzfs->zDBHandle) != Z_SUCCESS)
	{
	    ZError (DBG_MISC, "zDBOpen failed 1");
	    return -1;
	}

    /* initialize zDBHandle for video */
    if (ZDBOpen (Z_UTIL_ZFS, VIDEO_DB_FILE, &pzfs->zVDBHandle) != Z_SUCCESS)
	{
	    ZError (DBG_MISC, "zVDBOpen failed 1");
	    return -1;
	}

    /* initialize zDBHandle for photo */
    if (ZDBOpen (Z_UTIL_ZFS, PHOTO_DB_FILE, &pzfs->zPDBHandle) != Z_SUCCESS)
	{
	    ZError (DBG_MISC, "zPDBOpen failed 1");
	    return -1;
	}

    /* init zISDBHandle */
    if (ZDBOpen (Z_UTIL_ZFS, IMPORT_SUMMARY_DB, &pzfs->zISDBHandle) !=
	Z_SUCCESS)
	{
	    ZError (DBG_MISC, "zISDBOpen failed 2");
	    return -1;
	}
	pzfs->b_renice = FALSE;
    iDirty ();			/* import folder dirty, need to be scan */
    return 0;
}
コード例 #27
0
ファイル: kurolyric.c プロジェクト: jamesyan84/zbase
static gint KuroLRCLoadLocal(const gchar *uri, gchar **outbuf, guint *outsize)
{
	struct stat statBuf;
	gchar *buf = NULL;
	guint len = 0;
	FILE *fp = NULL;
	
	ZFREE(*outbuf);
	*outsize = 0;
	
	if(stat(uri, &statBuf) != 0) {
		ZError(DBG_INIT,"Cannot access the LRC file -> %s", uri);
		return ZAPP_FAILED;
	}
	
	/* Read the LRC file to buffer */
	len = sizeof(gchar)*statBuf.st_size + 1;
	buf = (gchar*)malloc(len);
	if(!buf) {
		ZError(DBG_INIT,"Out of memory!");
		return ZAPP_FAILED;
	}
	memset(buf, 0, len);
	
	fp = fopen(uri, "r");
	if(fp == NULL) {
		ZError(DBG_INIT,"Cannot open the LRC file -> %s", uri);
		ZFREE(buf);
		return ZAPP_FAILED;
	}
	
	if(fread(buf, sizeof(char), len, fp) <= 0 ){
		ZError(DBG_INIT,"Cannot read the LRC file -> %s", uri);
		ZFREE(buf);
		fclose(fp);
		return ZAPP_FAILED;
	}
	fclose(fp);
	
	*outbuf = buf;
	*outsize = len;
	return ZAPP_SUCCESS;
}
コード例 #28
0
ファイル: zfs.c プロジェクト: jamesyan84/zbase
int ProcessFile(ZFS_TASK *ptask, PZFS pzfs)
{
	if(ptask == NULL) {
		ZWarning(DBG_MISC, "task is empty");
		return -1;
	}

	char fullPath[MAX_PATH_SIZE] = {0};
	int isDir;

	/* Check to see if the file is exists to avoid in some cases
	 *  that the file which removed may add to task queue twice */
	sprintf (fullPath, "%s/%s", ptask->path, ptask->name);
	if (ZUtilIsFilePresent (fullPath, &isDir) == 0) {
		ZWarning (DBG_MISC, "Warning: the file doesn't exists, ignore it->%s", fullPath);
		return 0;
	}
	ZInfo4 (DBG_MISC, "Handling file -> %s", fullPath);

	int mediaType = GetMediaType(ptask->name);
	ZInfo4(DBG_MISC, "MediaType[%d]", mediaType);
//	if(mediaType == Z_UNKNOWN_FILE) {
//		return -1;
//	}

	if((mediaType > Z_PHOTO_START && mediaType < Z_PHOTO_END) && pzfs->photoConfig) {
			ProcessPhotoFile(fullPath);
	}
	else if((mediaType > Z_AUDIO_START && mediaType < Z_AUDIO_END) && pzfs->audioConfig ) {
			ProcessAudioFile(ptask);
	}
	else if((mediaType > Z_VIDEO_START && mediaType < Z_VIDEO_END) && pzfs->videoConfig) {
			ProcessVideoFile(fullPath);
	}
	else {
		//meet a unsupported file
		if(REMOVE_UNSUPPORTED_FILE) {
			ZInfo4 (DBG_MISC, "Delete unsupport file.");
			if (removeFile (pzfs, ptask->path, ptask->name) != 0) {
				ZError (DBG_MISC, "Remove invalid file failed->%s/%s", ptask->path, ptask->name);
				return -1;
			}
			else {
				deletedPlusOne ();	/* Deleted plus one */
				saveSummary (pzfs);	/* Sync to DB */
			}
		}
		else {
			ZInfo4 (DBG_MISC, "Skip unsupported file.");
		}
	}

	return 0;
}
コード例 #29
0
ファイル: zdbutil.c プロジェクト: jamesyan84/zbase
/************************************************************************
* Function: getRenameCount 
* * Parameters:
*       IN char *curcount: current renamecount value
*
* Description:
*       get the persist count number
*
* Returns:
*	0 if successful else appropriate error
***************************************************************************/
int getRenameCount(long *curcount)
{
    char tmp[1024] = { 0 };
    /* read the count num */
    if(!curcount)
	return -1;
    FILE *fp = NULL;
    if ((fp = fopen (RENAMECOUNTFILE, "r")) == NULL)
        goto newFile;
    if ((fgets (tmp, 1024, fp)) == NULL)
        {
            fclose (fp);
            goto newFile;
        }
    fclose (fp);
    long count;
    sscanf (tmp, "%ld", &count);
    *curcount=count;
    return 0;

  newFile:
    /* Not exists */
    /* Create new file and set default count to zero */
    sprintf (tmp, "touch %s", RENAMECOUNTFILE);
    ZInfo4 (DBG_MISC, "Will execute->%s", tmp);
    if (executeCMD (tmp) != 0)
        {
            ZError (DBG_MISC, "Execute failed->%s", tmp);
            return -1;
        }
    /* write zero to the file */
    sprintf (tmp, "echo 0 > %s", RENAMECOUNTFILE);
    ZInfo4 (DBG_MISC, "Will execute->%s", tmp);
    if (executeCMD (tmp) != 0)
        {
            ZError (DBG_MISC, "Execute failed->%s", tmp);
            return -1;
        }
    *curcount=0; 
    return 0;
}
コード例 #30
0
ファイル: zqstate.c プロジェクト: jamesyan84/zbase
void UpdateDMRState()
{
	IXML_Document *stateDoc = NULL;
	stateDoc = CMDGetStateDMR();
	if(stateDoc == NULL) {
		ZError(DBG_MISC, "Get state from DMR failed!");
		return;
	} else {
		SetDMRState(stateDoc);
		ixmlDocument_free(stateDoc);	
	}
}