-
-/**************************************************************************************************
- * Testing
- **************************************************************************************************/
-
-#ifdef SPOT_TEST_MAIN
-
-int main(int argc, char **argv)
-{
- EC_INIT;
- TALLOC_CTX *mem_ctx = talloc_new(NULL);
- DALLOC_CTX *dd = talloc_zero(mem_ctx, DALLOC_CTX);
- int64_t i;
-
- set_processname("spot");
- setuplog("default:info,spotlight:debug", "/dev/tty");
-
- LOG(log_info, logtype_sl, "Start");
-
-#if 0
- i = 2;
- dalloc_add(dd, &i, int64_t);
-
- i = 1;
- dalloc_add(dd, &i, int64_t);
-
-
- char *str = talloc_strdup(dd, "hello world");
- dalloc_add(dd, &str, char *);
-
- sl_bool_t b = true;
- dalloc_add(dd, &b, sl_bool_t);
-
- b = false;
- dalloc_add(dd, &b, sl_bool_t);
-
-
- /* add a nested array */
- DALLOC_CTX *nested = talloc_zero(dd, DALLOC_CTX);
- i = 3;
- dalloc_add(nested, &i, int64_t);
- dalloc_add(dd, nested, DALLOC_CTX);
-
- /* test an allocated CNID array */
- uint32_t id = 16;
- sl_cnids_t *cnids = talloc_zero(dd, sl_cnids_t);
-
- cnids->ca_cnids = talloc_zero(cnids, DALLOC_CTX);
-
- cnids->ca_unkn1 = 1;
- cnids->ca_unkn2 = 2;
-
- dalloc_add(cnids->ca_cnids, &id, uint32_t);
- dalloc_add(dd, cnids, sl_cnids_t);
-
- /* Now the Spotlight types */
- sl_array_t *sl_arrary = talloc_zero(dd, sl_array_t);
- i = 1234;
- dalloc_add(sl_arrary, &i, int64_t);
-
- sl_dict_t *sl_dict = talloc_zero(dd, sl_dict_t);
- i = 5678;
- dalloc_add(sl_dict, &i, int64_t);
- dalloc_add(sl_arrary, sl_dict, sl_dict_t);
-
- dalloc_add(dd, sl_arrary, sl_array_t);
-#endif
-
- /* now parse a real spotlight packet */
- char ibuf[8192];
- char rbuf[8192];
- int fd;
- size_t len;
- DALLOC_CTX *query;
-
- EC_NULL( query = talloc_zero(mem_ctx, DALLOC_CTX) );
-
- EC_NEG1_LOG( fd = open("spotlight-packet2.bin", O_RDONLY) );
- EC_NEG1_LOG( len = read(fd, ibuf, 8192) );
- close(fd);
- EC_NEG1_LOG( dissect_spotlight(query, ibuf + 24) );
-
- /* Now dump the whole thing */
- dd_dump(query, 0);
-
- int qlen;
- char buf[MAX_SLQ_DAT];
- EC_NEG1_LOG( qlen = sl_pack(query, buf) );
-
- EC_NEG1_LOG( fd = open("tmp", O_RDWR | O_CREAT, 0644) );
- write(fd, buf, qlen);
- close(fd);
-
- SLVAL(buf, 0, INT64_C(0x0102030405060708U));
-
-#if 0
- (((unsigned char *)((buf)))[(0)]) = (unsigned char)((((uint64_t)(0x0102030405060708UL))&0xFFFFFFFF&0xFFFF) &0xFF);
- (((unsigned char *)((buf)))[(0)+1]) = (unsigned char)((((uint64_t)(0x0102030405060708UL))&0xFFFFFFFF&0xFFFF) >> 8);
- (((unsigned char *)((buf)))[(0)+2]) = (unsigned char)((((uint64_t)(0x0102030405060708UL))&0xFFFFFFFF>>16) & 0xFF);
- (((unsigned char *)((buf)))[(0)+2 +1]) = (unsigned char)((((uint64_t)(0x0102030405060708UL))&0xFFFFFFFF>>16)>>8);
- (((unsigned char *)((buf)))[(0)+4]) = (unsigned char)((((uint64_t)(0x0102030405060708UL))>>32&0xFFFF)&0xFF);
- (((unsigned char *)((buf)))[(0)+4 +1]) = (unsigned char)((((uint64_t)(0x0102030405060708UL))>>32&0xFFFF)>>8);
- (((unsigned char *)((buf)))[(0)+4 +2]) = (unsigned char)((((uint64_t)(0x0102030405060708UL))>>32>>16)&0xFF);
- (((unsigned char *)((buf)))[(0)+4 +2 +1]) = (unsigned char)((((uint64_t)(0x0102030405060708UL))>>32>>16)>>8);
-#endif
-
- EC_NEG1_LOG( fd = open("tmp2", O_RDWR | O_CREAT, 0644) );
- write(fd, buf, 8);
- close(fd);
-
-EC_CLEANUP:
- if (mem_ctx) {
- talloc_free(mem_ctx);
- mem_ctx = NULL;
- }
- EC_EXIT;
-}
-#endif