Exemple #1
0
bool MetaData(const char* filepath, cFields& fields, cRow& props)
{
#define ADD(x, t) do { if (t) { fields.push_back(x); props.push_back(t); } } while(0)
#define ADDSTRING(x, t) do { if (!t.empty()) { fields.push_back(x); props.push_back(t); } } while(0)
#define ADDINT(x, t) do { std::string c = *itoa(t); if (!c.empty()){ fields.push_back(x); props.push_back(c);} } while(0)
    
    TagLib::FileRef f(filepath);

    fields.clear();
    props.clear();

    //cTag t;
    //const char* tmp = NULL;
    std::string tmp;
    
    if (f.isNull()) 
    {
        std::cerr<< "Taglib failed on " << filepath << std::endl;
        ADD("metadata_needs_update", "2"); // failure
        return false;
    }
   
    TagLib::Tag *tag = f.tag();
    
    if (tag) 
    {
#if 0
      tmp   = toString(tag->title()).c_str();   ADD("title",   tmp);
      tmp   = toString(tag->artist()).c_str();  ADD("artist",  tmp);
      tmp   = toString(tag->album()).c_str();   ADD("album",   tmp);
      tmp   = toString(tag->comment()).c_str(); ADD("comment", tmp);
      tmp   = toString(tag->genre()).c_str();   ADD("genre",   tmp);
#else
        tmp   = toString(tag->title());   ADDSTRING("title",   tmp);
        tmp   = toString(tag->artist());  ADDSTRING("artist",  tmp);
        tmp   = toString(tag->album());   ADDSTRING("album",   tmp);
        tmp   = toString(tag->comment()); ADDSTRING("comment", tmp);
        tmp   = toString(tag->genre());   ADDSTRING("genre",   tmp);
#endif
      
      //ADDINT("track", tag->track());
      ADDINT("year",  tag->year());
    }
    
    TagLib::AudioProperties *prop = f.audioProperties();
    if (prop) 
    {
        ADDINT("bitrate",    prop->bitrate());
        ADDINT("samplerate", prop->sampleRate());
      //  ADDINT("channels",   prop->channels());
        ADDINT("length" ,    prop->length());
    }
 
    ADD("metadata_needs_update", "0");
    return true;
}
Exemple #2
0
/*
 * Locate or allocate connection cache entry.
 */
static void dict_ldap_conn_find(DICT_LDAP *dict_ldap)
{
    VSTRING *keybuf = vstring_alloc(10);
    char   *key;
    int     len;

#ifdef LDAP_API_FEATURE_X_OPENLDAP
    int     sslon = dict_ldap->start_tls || dict_ldap->ldap_ssl;

#endif
    LDAP_CONN *conn;

#define ADDSTR(vp, s) vstring_memcat((vp), (s), strlen((s))+1)
#define ADDINT(vp, i) vstring_sprintf_append((vp), "%lu", (unsigned long)(i))

    ADDSTR(keybuf, dict_ldap->server_host);
    ADDINT(keybuf, dict_ldap->server_port);
    ADDINT(keybuf, dict_ldap->bind);
    ADDSTR(keybuf, dict_ldap->bind ? dict_ldap->bind_dn : "");
    ADDSTR(keybuf, dict_ldap->bind ? dict_ldap->bind_pw : "");
    ADDINT(keybuf, dict_ldap->dereference);
    ADDINT(keybuf, dict_ldap->chase_referrals);
    ADDINT(keybuf, dict_ldap->debuglevel);
    ADDINT(keybuf, dict_ldap->version);
#ifdef LDAP_API_FEATURE_X_OPENLDAP
    ADDINT(keybuf, dict_ldap->ldap_ssl);
    ADDINT(keybuf, dict_ldap->start_tls);
    ADDINT(keybuf, sslon ? dict_ldap->tls_require_cert : 0);
    ADDSTR(keybuf, sslon ? dict_ldap->tls_ca_cert_file : "");
    ADDSTR(keybuf, sslon ? dict_ldap->tls_ca_cert_dir : "");
    ADDSTR(keybuf, sslon ? dict_ldap->tls_cert : "");
    ADDSTR(keybuf, sslon ? dict_ldap->tls_key : "");
    ADDSTR(keybuf, sslon ? dict_ldap->tls_random_file : "");
    ADDSTR(keybuf, sslon ? dict_ldap->tls_cipher_suite : "");
#endif

    key = vstring_str(keybuf);
    len = VSTRING_LEN(keybuf);

    if (conn_hash == 0)
	conn_hash = binhash_create(0);

    if ((dict_ldap->ht = binhash_locate(conn_hash, key, len)) == 0) {
	conn = (LDAP_CONN *) mymalloc(sizeof(LDAP_CONN));
	conn->conn_ld = 0;
	conn->conn_refcount = 0;
	dict_ldap->ht = binhash_enter(conn_hash, key, len, (char *) conn);
    }
    ++DICT_LDAP_CONN(dict_ldap)->conn_refcount;

    vstring_free(keybuf);
}
Exemple #3
0
/*
 * Serialize child_config struct to string. Returned buffer must be freed.
 */
char *
child_config_serialize(const struct child_config *cc)
{
	json_object		*obj,
				*t,
				*s;
	int			x;
	char			*ret;

#define ADD(X, Y)	if (Y != NULL) { \
				t = json_object_new_string(Y); \
				json_object_object_add(obj, X, t); \
			}

#define ADDINT(X, Y)	if (Y != -1) { \
				t = json_object_new_int(Y); \
				json_object_object_add(obj, X, t); \
			}

	obj = json_object_new_object();
	ADD("name", cc->cc_name);
	ADD("stdout", cc->cc_stdout);
	ADD("stderr", cc->cc_stderr);
	ADD("dir", cc->cc_dir);
	ADD("heartbeat", cc->cc_heartbeat);
	ADD("fatal_cb", cc->cc_fatal_cb);
	ADD("username", cc->cc_username);
	ADD("groupname", cc->cc_groupname);
	ADDINT("instances", cc->cc_instances);
	ADDINT("status", cc->cc_status);
	ADDINT("killsig", cc->cc_killsig);
	ADDINT("uid", cc->cc_uid);
	ADDINT("gid", cc->cc_gid);
	ADDINT("error", cc->cc_error);
	ADDINT("age", cc->cc_age);

	if (cc->cc_command != NULL) {
		t = json_object_new_array();
		x = 0;

		while (cc->cc_command[x] != NULL) {
			s = json_object_new_string(cc->cc_command[x]);
			json_object_array_add(t, s);
			x++;
		}
		json_object_object_add(obj, "args", t);
	}

	ret = xstrdup(json_object_to_json_string(obj));
	json_object_put(obj);

	return ret;
}
Exemple #4
0
void
_gcry_rndw32_gather_random_fast (void (*add)(const void*, size_t,
                                             enum random_origins),
                                 enum random_origins origin)
{
  static int addedFixedItems = 0;

  if ( debug_me )
    log_debug ("rndw32#gather_random_fast: ori=%d\n", origin );

  /* Get various basic pieces of system information: Handle of active
     window, handle of window with mouse capture, handle of clipboard
     owner handle of start of clpboard viewer list, pseudohandle of
     current process, current process ID, pseudohandle of current
     thread, current thread ID, handle of desktop window, handle of
     window with keyboard focus, whether system queue has any events,
     cursor position for last message, 1 ms time for last message,
     handle of window with clipboard open, handle of process heap,
     handle of procs window station, types of events in input queue,
     and milliseconds since Windows was started. On 64-bit platform
     some of these return values are pointers and thus 64-bit wide.
     We discard the upper 32-bit of those values.  */

  {
    byte buffer[20*sizeof(intptr_t)], *bufptr;

    bufptr = buffer;
#define ADDINT(f)  do { intptr_t along = (intptr_t)(f);               \
                        memcpy (bufptr, &along, sizeof (intptr_t) );  \
                        bufptr += sizeof (along);                     \
                      } while (0)
#define ADDPTR(f)  do { void *aptr = (f);                          \
                        ADDINT((SIZE_T)aptr);                      \
                      } while (0)

    ADDPTR ( GetActiveWindow ());
    ADDPTR ( GetCapture ());
    ADDPTR ( GetClipboardOwner ());
    ADDPTR ( GetClipboardViewer ());
    ADDPTR ( GetCurrentProcess ());
    ADDINT ( GetCurrentProcessId ());
    ADDPTR ( GetCurrentThread ());
    ADDINT ( GetCurrentThreadId ());
    ADDPTR ( GetDesktopWindow ());
    ADDPTR ( GetFocus ());
    ADDINT ( GetInputState ());
    ADDINT ( GetMessagePos ());
    ADDINT ( GetMessageTime ());
    ADDPTR ( GetOpenClipboardWindow ());
    ADDPTR ( GetProcessHeap ());
    ADDPTR ( GetProcessWindowStation ());
    /* Following function in some cases stops returning events, and cannot
       be used as an entropy source.  */
    /*ADDINT ( GetQueueStatus (QS_ALLEVENTS));*/
    ADDINT ( GetTickCount ());

    gcry_assert ( bufptr-buffer < sizeof (buffer) );
    (*add) ( buffer, bufptr-buffer, origin );
#undef ADDINT
#undef ADDPTR
  }

  /* Get multiword system information: Current caret position, current
     mouse cursor position.  */
  {
    POINT point;

    GetCaretPos (&point);
    (*add) ( &point, sizeof (point), origin );
    GetCursorPos (&point);
    (*add) ( &point, sizeof (point), origin );
  }

  /* Get percent of memory in use, bytes of physical memory, bytes of
     free physical memory, bytes in paging file, free bytes in paging
     file, user bytes of address space, and free user bytes.  */
  {
    MEMORYSTATUS memoryStatus;

    memoryStatus.dwLength = sizeof (MEMORYSTATUS);
    GlobalMemoryStatus (&memoryStatus);
    (*add) ( &memoryStatus, sizeof (memoryStatus), origin );
  }

  /* Get thread and process creation time, exit time, time in kernel
     mode, and time in user mode in 100ns intervals.  */
  {
    HANDLE handle;
    FILETIME creationTime, exitTime, kernelTime, userTime;
    SIZE_T minimumWorkingSetSize, maximumWorkingSetSize;

    handle = GetCurrentThread ();
    GetThreadTimes (handle, &creationTime, &exitTime,
                    &kernelTime, &userTime);
    (*add) ( &creationTime, sizeof (creationTime), origin );
    (*add) ( &exitTime, sizeof (exitTime), origin );
    (*add) ( &kernelTime, sizeof (kernelTime), origin );
    (*add) ( &userTime, sizeof (userTime), origin );

    handle = GetCurrentProcess ();
    GetProcessTimes (handle, &creationTime, &exitTime,
                     &kernelTime, &userTime);
    (*add) ( &creationTime, sizeof (creationTime), origin );
    (*add) ( &exitTime, sizeof (exitTime), origin );
    (*add) ( &kernelTime, sizeof (kernelTime), origin );
    (*add) ( &userTime, sizeof (userTime), origin );

    /* Get the minimum and maximum working set size for the current
       process.  */
    GetProcessWorkingSetSize (handle, &minimumWorkingSetSize,
                              &maximumWorkingSetSize);
    /* On 64-bit system, discard the high 32-bits. */
    (*add) ( &minimumWorkingSetSize, sizeof (int), origin );
    (*add) ( &maximumWorkingSetSize, sizeof (int), origin );
  }


  /* The following are fixed for the lifetime of the process so we only
   * add them once */
  if (!addedFixedItems)
    {
      STARTUPINFO startupInfo;

      /* Get name of desktop, console window title, new window
         position and size, window flags, and handles for stdin,
         stdout, and stderr.  */
      startupInfo.cb = sizeof (STARTUPINFO);
      GetStartupInfo (&startupInfo);
      (*add) ( &startupInfo, sizeof (STARTUPINFO), origin );
      addedFixedItems = 1;
    }

  /* The performance of QPC varies depending on the architecture it's
     running on and on the OS, the MS documentation is vague about the
     details because it varies so much.  Under Win9x/ME it reads the
     1.193180 MHz PIC timer.  Under NT/Win2K/XP it may or may not read the
     64-bit TSC depending on the HAL and assorted other circumstances,
     generally on machines with a uniprocessor HAL
     KeQueryPerformanceCounter() uses a 3.579545MHz timer and on machines
     with a multiprocessor or APIC HAL it uses the TSC (the exact time
     source is controlled by the HalpUse8254 flag in the kernel).  That
     choice of time sources is somewhat peculiar because on a
     multiprocessor machine it's theoretically possible to get completely
     different TSC readings depending on which CPU you're currently
     running on, while for uniprocessor machines it's not a problem.
     However, the kernel appears to synchronise the TSCs across CPUs at
     boot time (it resets the TSC as part of its system init), so this
     shouldn't really be a problem.  Under WinCE it's completely platform-
     dependent, if there's no hardware performance counter available, it
     uses the 1ms system timer.

     Another feature of the TSC (although it doesn't really affect us here)
     is that mobile CPUs will turn off the TSC when they idle, Pentiums
     will change the rate of the counter when they clock-throttle (to
     match the current CPU speed), and hyperthreading Pentiums will turn
     it off when both threads are idle (this more or less makes sense,
     since the CPU will be in the halted state and not executing any
     instructions to count).

     To make things unambiguous, we detect a CPU new enough to call RDTSC
     directly by checking for CPUID capabilities, and fall back to QPC if
     this isn't present.

     On AMD64, TSC is always available and intrinsic is provided for accessing
     it.  */
#ifdef __WIN64__
    {
      unsigned __int64 aint64;

      /* Note: cryptlib does not discard upper 32 bits of TSC on WIN64, but does
       * on WIN32.  Is this correct?  */
      aint64 = __rdtsc();
      (*add) (&aint64, sizeof(aint64), origin);
    }
#else
#ifdef __GNUC__
/*   FIXME: We would need to implement the CPU feature tests first.  */
/*   if (cpu_has_feature_rdtsc) */
/*     { */
/*       uint32_t lo, hi; */
      /* We cannot use "=A", since this would use %rax on x86_64. */
/*       __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi)); */
      /* Ignore high 32 bits, hwich are >1s res.  */
/*       (*add) (&lo, 4, origin ); */
/*     } */
/*   else */
#endif /*!__GNUC__*/
    {
      LARGE_INTEGER performanceCount;

      if (QueryPerformanceCounter (&performanceCount))
        {
          if ( debug_me )
          log_debug ("rndw32#gather_random_fast: perf data\n");
          (*add) (&performanceCount, sizeof (performanceCount), origin);
        }
      else
        {
          /* Millisecond accuracy at best... */
          DWORD aword = GetTickCount ();
          (*add) (&aword, sizeof (aword), origin );
        }
    }
#endif /*__WIN64__*/


}
Exemple #5
0
void initosl(void)
{
    PyObject *mdl;

    if (PyType_Ready(PPyImageType) < 0)
        return;

    if (PyType_Ready(PPyControllerType) < 0)
        return;

    if (PyType_Ready(PPySoundType) < 0)
        return;

    if (PyType_Ready(PPyMapType) < 0)
        return;

    if (PyType_Ready(PPyFontType) < 0)
        return;

    mdl = Py_InitModule3("osl", functions, "");
    if (!mdl)
        return;

    ADDINT(PF_8888);
    ADDINT(PF_5650);
    ADDINT(PF_5551);
    ADDINT(PF_4444);
    ADDINT(PF_8BIT);
    ADDINT(PF_4BIT);

    ADDINT(FX_NONE);
    ADDINT(FX_FLAT);
    ADDINT(FX_RGBA);
    ADDINT(FX_ALPHA);
    ADDINT(FX_ADD);
    ADDINT(FX_SUB);
    ADDINT(FX_COLOR);

    ADDINT(IN_VRAM);
    ADDINT(IN_RAM);

    ADDINT(DEFAULT_BUFFER);
    ADDINT(SECONDARY_BUFFER);

    ADDINT(MB_OK);
    ADDINT(MB_CANCEL);
    ADDINT(MB_YES);
    ADDINT(MB_NO);
    ADDINT(MB_QUIT);

    ADDINT(KEY_SELECT);
    ADDINT(KEY_START);
    ADDINT(KEY_UP);
    ADDINT(KEY_RIGHT);
    ADDINT(KEY_DOWN);
    ADDINT(KEY_LEFT);
    ADDINT(KEY_L);
    ADDINT(KEY_R);
    ADDINT(KEY_TRIANGLE);
    ADDINT(KEY_CIRCLE);
    ADDINT(KEY_CROSS);
    ADDINT(KEY_SQUARE);
    ADDINT(KEY_HOLD);
    ADDINT(KEY_HOME);
    ADDINT(KEY_NOTE);

    ADDINT(FMT_STREAM);
    ADDINT(FMT_NONE);

    osl_Error = PyErr_NewException("osl.Error", NULL, NULL);
    PyModule_AddObject(mdl, "Error", osl_Error);

    Py_INCREF(PPyImageType);
    PyModule_AddObject(mdl, "Image", (PyObject*)PPyImageType);

    Py_INCREF(PPyControllerType);
    PyModule_AddObject(mdl, "Controller", (PyObject*)PPyControllerType);

    Py_INCREF(PPySoundType);
    PyModule_AddObject(mdl, "Sound", (PyObject*)PPySoundType);

    Py_INCREF(PPyMapType);
    PyModule_AddObject(mdl, "Map", (PyObject*)PPyMapType);

    Py_INCREF(PPyFontType);
    PyModule_AddObject(mdl, "Font", (PyObject*)PPyFontType);
}