3 * Copyright (C) 1990, 1993 Regents of The University of Michigan
4 * All Rights Reserved. See COPYRIGHT
9 * This file contains FPCatSearch implementation. FPCatSearch performs
10 * file/directory search based on specified criteria. It is used by client
11 * to perform fast searches on (propably) big volumes. So, it has to be
14 * This implementation bypasses most of adouble/libatalk stuff as long as
15 * possible and does a standard filesystem search. It calls higher-level
16 * libatalk/afpd functions only when it is really needed, mainly while
17 * returning some non-UNIX information or filtering by non-UNIX criteria.
19 * Initial version written by Rafal Lewczuk <rlewczuk@pronet.pl>
25 #endif /* HAVE_CONFIG_H */
41 #define memcpy(d,s,n) bcopy ((s), (d), (n))
42 #define memmove(d,s,n) bcopy ((s), (d), (n))
43 #endif /* ! HAVE_MEMCPY */
46 #include <sys/types.h>
49 #include <netinet/in.h>
51 #include <netatalk/endian.h>
52 #include <atalk/afp.h>
53 #include <atalk/adouble.h>
54 #include <atalk/logger.h>
56 #include <atalk/cnid.h>
59 #include "directory.h"
70 u_int8_t attrs; /* File attributes (8 bits)*/
71 u_int8_t label; /* Label (8 bits)*/
72 char reserved[22]; /* Unknown (at least for now...) */
76 * 0x04 - has a custom icon
77 * 0x20 - name/icon is locked
91 /* This is our search-criteria structure. */
93 u_int32_t rbitmap; /* Request bitmap - which values should we check ? */
94 u_int16_t fbitmap, dbitmap; /* file & directory bitmap - which values should we return ? */
95 u_int16_t attr; /* File attributes */
96 time_t cdate; /* Creation date */
97 time_t mdate; /* Last modification date */
98 time_t bdate; /* Last backup date */
99 u_int32_t pdid; /* Parent DID */
100 u_int16_t offcnt; /* Offspring count */
101 struct finderinfo finfo; /* Finder info */
102 char lname[64]; /* Long name */
103 char utf8name[512]; /* UTF8 name */
107 * Directory tree search is recursive by its nature. But AFP specification
108 * requires FPCatSearch to pause after returning n results and be able to
109 * resume the search later. So we have to do recursive search using flat
110 * (iterative) algorithm and remember all directories to look into in an
111 * stack-like structure. The structure below is one item of directory stack.
115 char *m_name; /* Mac name */
116 char *u_name; /* unix name (== strrchr('/', path)) */
117 struct dir *dir; /* Structure describing this directory */
118 int pidx; /* Parent's dsitem structure index. */
119 int checked; /* Have we checked this directory ? */
120 char *path; /* absolute UNIX path to this directory */
125 static int cur_pos = 0; /* Saved position index (ID) - used to remember "position" across FPCatSearch calls */
126 static DIR *dirpos = NULL; /* UNIX structure describing currently opened directory. */
127 static int save_cidx = -1; /* Saved index of currently scanned directory. */
129 static struct dsitem *dstack = NULL; /* Directory stack data... */
130 static int dssize = 0; /* Directory stack (allocated) size... */
131 static int dsidx = 0; /* First free item index... */
133 static struct scrit c1, c2; /* search criteria */
135 /* Puts new item onto directory stack. */
136 static int addstack(char *uname, char *mname, struct dir *dir, int pidx)
141 /* check if we have some space on stack... */
142 if (dsidx >= dssize) {
144 dstack = realloc(dstack, dssize * sizeof(struct dsitem));
149 /* Put new element. Allocate and copy lname and path. */
150 ds = dstack + dsidx++;
151 if (!(ds->m_name = strdup(mname)))
156 l = strlen(dstack[pidx].path);
157 if (!(ds->path = malloc(l + strlen(uname) + 2) ))
159 strcpy(ds->path, dstack[pidx].path);
160 strcat(ds->path, "/");
161 strcat(ds->path, uname);
162 ds->u_name = ds->path +l +1;
170 /* Removes checked items from top of directory stack. Returns index of the first unchecked elements or -1. */
171 static int reducestack()
174 if (save_cidx != -1) {
181 if (dstack[dsidx-1].checked) {
183 free(dstack[dsidx].m_name);
184 free(dstack[dsidx].path);
185 /* Check if we need to free (or release) dir structures */
190 } /* reducestack() */
192 /* Clears directory stack. */
193 static void clearstack()
198 free(dstack[dsidx].m_name);
199 free(dstack[dsidx].path);
200 /* Check if we need to free (or release) dir structures */
204 /* Fills in dir field of dstack[cidx]. Must fill parent dirs' fields if needed... */
205 static int resolve_dir(struct vol *vol, int cidx)
207 struct dir *dir, *cdir;
209 if (dstack[cidx].dir != NULL)
212 if (dstack[cidx].pidx < 0)
215 if (dstack[dstack[cidx].pidx].dir == NULL && resolve_dir(vol, dstack[cidx].pidx) == 0)
218 cdir = dstack[dstack[cidx].pidx].dir;
221 if (strcmp(dir->d_m_name, dstack[cidx].m_name) == 0)
223 dir = (dir == cdir->d_child->d_prev) ? NULL : dir->d_next;
229 path.u_name = dstack[cidx].path;
230 if (of_stat(&path)==-1) {
231 syslog(LOG_DEBUG, "resolve_dir: stat %s: %s", dstack[cidx].path, strerror(errno));
234 path.m_name = dstack[cidx].m_name;
235 path.u_name = dstack[cidx].u_name;
236 /* adddir works with a filename not absolute pathname */
237 if ((dir = adddir(vol, cdir, &path)) == NULL)
240 dstack[cidx].dir = dir;
245 /* Looks up for an opened adouble structure, opens resource fork of selected file. */
246 static struct adouble *adl_lkup(struct path *path)
248 static struct adouble ad;
251 int isdir = S_ISDIR(path->st.st_mode);
253 if (!isdir && (of = of_findname(path))) {
256 memset(&ad, 0, sizeof(ad));
260 if ( ad_open( path->u_name, ADFLAGS_HF | ((isdir)?ADFLAGS_DIR:0), O_RDONLY, 0, adp) < 0 ) {
266 #define CATPBIT_PARTIAL 31
267 /* Criteria checker. This function returns a 2-bit value. */
268 /* bit 0 means if checked file meets given criteria. */
269 /* bit 1 means if it is a directory and we should descent into it. */
271 * fname - our fname (translated to UNIX)
272 * cidx - index in directory stack
274 static int crit_check(struct vol *vol, struct path *path, int cidx) {
277 struct finderinfo *finfo = NULL, finderinfo;
278 struct adouble *adp = NULL;
279 time_t c_date, b_date;
280 static char convbuf[512];
281 static char convbuf2[512];
284 if (S_ISDIR(path->st.st_mode)) {
289 else if (!c1.fbitmap)
292 /* Kind of optimization:
293 * -- first check things we've already have - filename
294 * -- last check things we get from ad_open()
295 * FIXME strmcp strstr (icase)
298 /* Check for filename */
299 if (c1.rbitmap & (1<<DIRPBIT_LNAME)) {
300 if ( (size_t)(-1) == (len = convert_string(vol->v_maccharset, CH_UCS2, path->m_name, strlen(path->m_name), convbuf, 512)) )
303 if (c1.rbitmap & (1<<CATPBIT_PARTIAL)) {
304 if (strcasestr_w( (ucs2_t*) convbuf, (ucs2_t*) c1.lname) == NULL)
307 if (strcasecmp_w((ucs2_t*) convbuf, (ucs2_t*) c1.lname) != 0)
309 } /* if (c1.rbitmap & ... */
311 if ((c1.rbitmap & (1<<FILPBIT_PDINFO))) {
312 if ( (size_t)(-1) == (len = utf8_precompose( path->m_name, strlen(path->m_name), convbuf2, 512)) )
314 if ( (size_t)(-1) == (len = convert_string( CH_UTF8, CH_UCS2, convbuf2, len, convbuf, 512)) )
317 if (c1.rbitmap & (1<<CATPBIT_PARTIAL)) {
318 if (strcasestr_w((ucs2_t *) convbuf, (ucs2_t*)c1.utf8name) == NULL)
321 if (strcasecmp_w((ucs2_t *)convbuf, (ucs2_t*)c1.utf8name) != 0)
323 } /* if (c1.rbitmap & ... */
328 if ((unsigned)c2.mdate > 0x7fffffff)
329 c2.mdate = 0x7fffffff;
330 if ((unsigned)c2.cdate > 0x7fffffff)
331 c2.cdate = 0x7fffffff;
332 if ((unsigned)c2.bdate > 0x7fffffff)
333 c2.bdate = 0x7fffffff;
335 /* Check for modification date FIXME: should we look at adouble structure ? */
336 if ((c1.rbitmap & (1<<DIRPBIT_MDATE)))
337 if (path->st.st_mtime < c1.mdate || path->st.st_mtime > c2.mdate)
340 /* Check for creation date... */
341 if (c1.rbitmap & (1<<DIRPBIT_CDATE)) {
342 if (adp || (adp = adl_lkup(path))) {
343 if (ad_getdate(adp, AD_DATE_CREATE, (u_int32_t*)&c_date) >= 0)
344 c_date = AD_DATE_TO_UNIX(c_date);
345 else c_date = path->st.st_mtime;
346 } else c_date = path->st.st_mtime;
347 if (c_date < c1.cdate || c_date > c2.cdate)
351 /* Check for backup date... */
352 if (c1.rbitmap & (1<<DIRPBIT_BDATE)) {
353 if (adp || (adp == adl_lkup(path))) {
354 if (ad_getdate(adp, AD_DATE_BACKUP, (u_int32_t*)&b_date) >= 0)
355 b_date = AD_DATE_TO_UNIX(b_date);
356 else b_date = path->st.st_mtime;
357 } else b_date = path->st.st_mtime;
358 if (b_date < c1.bdate || b_date > c2.bdate)
362 /* Check attributes */
363 if ((c1.rbitmap & (1<<DIRPBIT_ATTR)) && c2.attr != 0) {
364 if (adp || (adp = adl_lkup(path))) {
365 ad_getattr(adp, &attr);
366 if ((attr & c2.attr) != c1.attr)
368 } else goto crit_check_ret;
371 /* Check file type ID */
372 if ((c1.rbitmap & (1<<DIRPBIT_FINFO)) && c2.finfo.f_type != 0) {
374 adp = adl_lkup(path);
375 finfo = get_finderinfo(path->m_name, adp, &finderinfo);
376 if (finfo->f_type != c1.finfo.f_type)
380 /* Check creator ID */
381 if ((c1.rbitmap & (1<<DIRPBIT_FINFO)) && c2.finfo.creator != 0) {
384 adp = adl_lkup(path);
385 finfo = get_finderinfo(path->m_name, adp, &finderinfo);
387 if (finfo->creator != c1.finfo.creator)
391 /* Check finder info attributes */
392 if ((c1.rbitmap & (1<<DIRPBIT_FINFO)) && c2.finfo.attrs != 0) {
395 if (adp || (adp = adl_lkup(path))) {
396 finfo = (struct finderinfo*)ad_entry(adp, ADEID_FINDERI);
397 attrs = finfo->attrs;
399 else if (*path->u_name == '.') {
400 attrs = htons(FINDERINFO_INVISIBLE);
403 if ((attrs & c2.finfo.attrs) != c1.finfo.attrs)
408 if ((c1.rbitmap & (1<<DIRPBIT_FINFO)) && c2.finfo.label != 0) {
409 if (adp || (adp = adl_lkup(path))) {
410 finfo = (struct finderinfo*)ad_entry(adp, ADEID_FINDERI);
411 if ((finfo->label & c2.finfo.label) != c1.finfo.label)
413 } else goto crit_check_ret;
415 /* FIXME: Attributes check ! */
417 /* All criteria are met. */
421 ad_close(adp, ADFLAGS_HF);
426 /* Adds an item to resultset. */
427 static int rslt_add(struct vol *vol, char *fname, short cidx, int isdir, char **rbuf)
430 int l = fname != NULL ? strlen(fname) : 0;
434 p0 = p[0] = cidx != -1 ? l + 7 : l + 5;
436 p[1] = isdir ? 128 : 0;
439 if (dstack[cidx].dir == NULL && resolve_dir(vol, cidx) == 0)
441 did = dstack[cidx].dir->d_did;
442 memcpy(p, &did, sizeof(did));
446 /* Fill offset of returned file name */
449 *p = (int)(p - *rbuf) - 1;
460 /* *rbuf[0] = (int)(p-*rbuf); */
464 static int rslt_add_ext ( struct vol *vol, struct path *path, char **buf, short cidx)
469 u_int16_t resultsize;
470 int isdir = S_ISDIR(path->st.st_mode);
472 if (dstack[cidx].dir == NULL && resolve_dir(vol, cidx) == 0)
475 p += sizeof(resultsize); /* Skip resultsize */
476 *p++ = isdir ? FILDIRBIT_ISDIR : FILDIRBIT_ISFILE; /* IsDir ? */
481 struct dir* dir = NULL;
483 dir = dirsearch_byname(dstack[cidx].dir, path->u_name);
485 if ((dir = adddir( vol, dstack[cidx].dir, path)) == NULL) {
489 ret = getdirparams(vol, c1.dbitmap, path, dir, p , &tbuf );
493 ret = getfilparams ( vol, c1.fbitmap, path, dstack[cidx].dir, p, &tbuf);
499 /* Make sure entry length is even */
505 resultsize = htons(tbuf);
506 memcpy ( *buf, &resultsize, sizeof(resultsize) );
516 "./../.AppleDouble/.AppleDB/Network Trash Folder/TheVolumeSettingsFolder/TheFindByContentFolder/.AppleDesktop/.Parent/"
518 /* This function performs search. It is called directly from afp_catsearch
519 * vol - volume we are searching on ...
520 * dir - directory we are starting from ...
521 * c1, c2 - search criteria
522 * rmatches - maximum number of matches we can return
523 * pos - position we've stopped recently
524 * rbuf - output buffer
525 * rbuflen - output buffer length
527 #define NUM_ROUNDS 100
528 static int catsearch(struct vol *vol, struct dir *dir,
529 int rmatches, int *pos, char *rbuf, u_int32_t *nrecs, int *rsize, int ext)
533 struct dirent *entry;
537 char *orig_dir = NULL;
538 int orig_dir_len = 128;
539 char *vpath = vol->v_path;
542 int num_rounds = NUM_ROUNDS;
544 if (*pos != 0 && *pos != cur_pos)
545 return AFPERR_CATCHNG;
547 /* FIXME: Category "offspring count ! */
549 /* So we are beginning... */
550 start_time = time(NULL);
552 /* We need to initialize all mandatory structures/variables and change working directory appropriate... */
555 if (dirpos != NULL) {
560 if (addstack("","", dir, -1) == -1) {
561 result = AFPERR_MISC;
564 dstack[0].path = strdup(vpath);
565 /* FIXME: Sometimes DID is given by client ! (correct this one above !) */
568 /* Save current path */
569 orig_dir = (char*)malloc(orig_dir_len);
570 while (getcwd(orig_dir, orig_dir_len-1)==NULL) {
571 if (errno != ERANGE) {
572 result = AFPERR_MISC;
576 orig_dir = realloc(orig_dir, orig_dir_len);
579 while ((cidx = reducestack()) != -1) {
581 dirpos = opendir(dstack[cidx].path);
582 if (dirpos == NULL) {
585 dstack[cidx].checked = 1;
590 result = AFPERR_NFILE;
595 result = AFPERR_MISC;
596 } /* switch (errno) */
599 chdir(dstack[cidx].path);
600 while ((entry=readdir(dirpos)) != NULL) {
603 if (!(fname = path.m_name = check_dirent(vol, entry->d_name)))
606 path.u_name = entry->d_name;
607 if (of_stat(&path) != 0) {
618 result = AFPERR_MISC;
620 } /* switch (errno) */
621 } /* if (stat(entry->d_name, &path.st) != 0) */
623 for (i = 0; fname[i] != 0; i++)
624 fname[i] = tolower(fname[i]);
626 ccr = crit_check(vol, &path, cidx);
627 /* bit 1 means that we have to descend into this directory. */
628 if ((ccr & 2) && S_ISDIR(path.st.st_mode)) {
629 if (addstack(entry->d_name, fname, NULL, cidx) == -1) {
630 result = AFPERR_MISC;
635 /* bit 0 means that criteria has been met */
638 r = rslt_add_ext ( vol, &path, &rrbuf, cidx);
643 (c1.fbitmap&(1<<FILPBIT_LNAME))|(c1.dbitmap&(1<<DIRPBIT_LNAME)) ?
645 (c1.fbitmap&(1<<FILPBIT_PDID))|(c1.dbitmap&(1<<DIRPBIT_PDID)) ?
647 S_ISDIR(path.st.st_mode), &rrbuf);
651 result = AFPERR_MISC;
655 /* Number of matches limit */
657 goto catsearch_pause;
658 /* Block size limit */
659 if (rrbuf - rbuf >= 448)
660 goto catsearch_pause;
662 /* MacOS 9 doesn't like servers executing commands longer than few seconds */
663 if (--num_rounds <= 0) {
664 if (start_time != time(NULL)) {
666 goto catsearch_pause;
668 num_rounds = NUM_ROUNDS;
670 } /* while ((entry=readdir(dirpos)) != NULL) */
673 dstack[cidx].checked = 1;
674 } /* while (current_idx = reducestack()) != -1) */
676 /* We have finished traversing our tree. Return EOF here. */
684 catsearch_end: /* Exiting catsearch: error condition */
685 *rsize = rrbuf - rbuf;
686 if (orig_dir != NULL) {
693 int catsearch_afp(AFPObj *obj, char *ibuf, int ibuflen,
694 char *rbuf, int *rbuflen, int ext)
699 u_int32_t rmatches, reserved;
704 unsigned char *spec1, *spec2, *bspec1, *bspec2;
706 memset(&c1, 0, sizeof(c1));
707 memset(&c2, 0, sizeof(c2));
710 memcpy(&vid, ibuf, sizeof(vid));
714 if ((vol = getvolbyvid(vid)) == NULL) {
718 memcpy(&rmatches, ibuf, sizeof(rmatches));
719 rmatches = ntohl(rmatches);
720 ibuf += sizeof(rmatches);
722 /* FIXME: (rl) should we check if reserved == 0 ? */
723 ibuf += sizeof(reserved);
725 memcpy(catpos, ibuf, sizeof(catpos));
726 ibuf += sizeof(catpos);
728 memcpy(&c1.fbitmap, ibuf, sizeof(c1.fbitmap));
729 c1.fbitmap = c2.fbitmap = ntohs(c1.fbitmap);
730 ibuf += sizeof(c1.fbitmap);
732 memcpy(&c1.dbitmap, ibuf, sizeof(c1.dbitmap));
733 c1.dbitmap = c2.dbitmap = ntohs(c1.dbitmap);
734 ibuf += sizeof(c1.dbitmap);
736 memcpy(&c1.rbitmap, ibuf, sizeof(c1.rbitmap));
737 c1.rbitmap = c2.rbitmap = ntohl(c1.rbitmap);
738 ibuf += sizeof(c1.rbitmap);
740 if (! (c1.fbitmap || c1.dbitmap)) {
741 return AFPERR_BITMAP;
745 memcpy(&spec_len, ibuf, sizeof(spec_len));
746 spec_len = ntohs(spec_len);
749 spec_len = *(unsigned char*)ibuf;
752 /* Parse file specifications */
754 spec2 = ibuf + spec_len + 2;
761 /* File attribute bits... */
762 if (c1.rbitmap & (1 << FILPBIT_ATTR)) {
763 memcpy(&c1.attr, spec1, sizeof(c1.attr));
764 spec1 += sizeof(c1.attr);
765 memcpy(&c2.attr, spec2, sizeof(c2.attr));
766 spec2 += sizeof(c1.attr);
770 if (c1.rbitmap & (1 << FILPBIT_PDID)) {
771 memcpy(&c1.pdid, spec1, sizeof(pdid));
772 spec1 += sizeof(c1.pdid);
773 memcpy(&c2.pdid, spec2, sizeof(pdid));
774 spec2 += sizeof(c2.pdid);
775 } /* FIXME: PDID - do we demarshall this argument ? */
778 if (c1.rbitmap & (1 << FILPBIT_CDATE)) {
779 memcpy(&c1.cdate, spec1, sizeof(c1.cdate));
780 spec1 += sizeof(c1.cdate);
781 c1.cdate = AD_DATE_TO_UNIX(c1.cdate);
782 memcpy(&c2.cdate, spec2, sizeof(c2.cdate));
783 spec2 += sizeof(c1.cdate);
784 ibuf += sizeof(c1.cdate);;
785 c2.cdate = AD_DATE_TO_UNIX(c2.cdate);
788 /* Modification date */
789 if (c1.rbitmap & (1 << FILPBIT_MDATE)) {
790 memcpy(&c1.mdate, spec1, sizeof(c1.mdate));
791 c1.mdate = AD_DATE_TO_UNIX(c1.mdate);
792 spec1 += sizeof(c1.mdate);
793 memcpy(&c2.mdate, spec2, sizeof(c2.mdate));
794 c2.mdate = AD_DATE_TO_UNIX(c2.mdate);
795 spec2 += sizeof(c1.mdate);
799 if (c1.rbitmap & (1 << FILPBIT_BDATE)) {
800 memcpy(&c1.bdate, spec1, sizeof(c1.bdate));
801 spec1 += sizeof(c1.bdate);
802 c1.bdate = AD_DATE_TO_UNIX(c1.bdate);
803 memcpy(&c2.bdate, spec2, sizeof(c2.bdate));
804 spec2 += sizeof(c2.bdate);
805 c1.bdate = AD_DATE_TO_UNIX(c2.bdate);
809 if (c1.rbitmap & (1 << FILPBIT_FINFO)) {
810 memcpy(&c1.finfo, spec1, sizeof(c1.finfo));
811 spec1 += sizeof(c1.finfo);
812 memcpy(&c2.finfo, spec2, sizeof(c2.finfo));
813 spec2 += sizeof(c2.finfo);
816 if ((c1.rbitmap & (1 << DIRPBIT_OFFCNT)) != 0) {
817 /* Offspring count - only directories */
818 if (c1.fbitmap == 0) {
819 memcpy(&c1.offcnt, spec1, sizeof(c1.offcnt));
820 spec1 += sizeof(c1.offcnt);
821 c1.offcnt = ntohs(c1.offcnt);
822 memcpy(&c2.offcnt, spec2, sizeof(c2.offcnt));
823 spec2 += sizeof(c2.offcnt);
824 c2.offcnt = ntohs(c2.offcnt);
826 else if (c1.dbitmap == 0) {
827 /* ressource fork length */
830 return AFPERR_BITMAP; /* error */
832 } /* Offspring count/ressource fork length */
835 if (c1.rbitmap & (1 << FILPBIT_LNAME)) {
838 /* Get the long filename */
839 /* memcpy(c1.lname, bspec1 + spec1[1] + 1, (bspec1 + spec1[1])[0]);
840 c1.lname[(bspec1 + spec1[1])[0]]= 0;*/
841 memcpy(tmppath, bspec1 + spec1[1] + 1, (bspec1 + spec1[1])[0]);
842 tmppath[(bspec1 + spec1[1])[0]]= 0;
843 len = convert_string ( vol->v_maccharset, CH_UCS2, tmppath, strlen(tmppath), c1.lname, 64);
844 if (len == (size_t)(-1))
850 for (i = 0; c1.lname[i] != 0; i++)
851 c1.lname[i] = tolower(c1.lname[i]);
853 /* FIXME: do we need it ? It's always null ! */
854 memcpy(c2.lname, bspec2 + spec2[1] + 1, (bspec2 + spec2[1])[0]);
855 c2.lname[(bspec2 + spec2[1])[0]]= 0;
857 for (i = 0; c2.lname[i] != 0; i++)
858 c2.lname[i] = tolower(c2.lname[i]);
862 if (c1.rbitmap & (1 << FILPBIT_PDINFO)) {
868 memcpy(&namelen, spec1, sizeof(namelen));
869 namelen = ntohs (namelen);
871 spec1 = bspec1+namelen+4; /* Skip Unicode Hint */
874 memcpy(&namelen, spec1, sizeof(namelen));
875 namelen = ntohs (namelen);
876 if (namelen > 255) /* Safeguard */
879 memcpy (c1.utf8name, spec1+2, namelen);
880 c1.utf8name[(namelen+1)] =0;
882 /* convert charset */
883 len = utf8_precompose( c1.utf8name, namelen, tmppath, 256);
884 len = convert_string(CH_UTF8, CH_UCS2, tmppath, namelen, c1.utf8name, 512);
885 if (len == (size_t)(-1))
892 ret = catsearch(vol, vol->v_dir, rmatches, &catpos[0], rbuf+24, &nrecs, &rsize, ext);
893 memcpy(rbuf, catpos, sizeof(catpos));
894 rbuf += sizeof(catpos);
896 c1.fbitmap = htons(c1.fbitmap);
897 memcpy(rbuf, &c1.fbitmap, sizeof(c1.fbitmap));
898 rbuf += sizeof(c1.fbitmap);
900 c1.dbitmap = htons(c1.dbitmap);
901 memcpy(rbuf, &c1.dbitmap, sizeof(c1.dbitmap));
902 rbuf += sizeof(c1.dbitmap);
904 nrecs = htonl(nrecs);
905 memcpy(rbuf, &nrecs, sizeof(nrecs));
906 rbuf += sizeof(nrecs);
910 } /* catsearch_afp */
912 int afp_catsearch (AFPObj *obj, char *ibuf, int ibuflen,
913 char *rbuf, int *rbuflen)
915 return catsearch_afp( obj, ibuf, ibuflen, rbuf, rbuflen, 0);
919 int afp_catsearch_ext (AFPObj *obj, char *ibuf, int ibuflen,
920 char *rbuf, int *rbuflen)
922 return catsearch_afp( obj, ibuf, ibuflen, rbuf, rbuflen, 1);
925 /* FIXME: we need a clean separation between afp stubs and 'real' implementation */
926 /* (so, all buffer packing/unpacking should be done in stub, everything else
927 should be done in other functions) */