ReactOS 0.4.15-dev-8344-g0574987
bookmark.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  Bookmark
 

Macros

#define kBookmarkVersion   8
 
#define kBookmarkMinVersion   3
 
#define kBookmarkFileName   "bookmarks"
 
#define kTmpBookmarkFileName   "bookmarks-tmp"
 
#define kOldBookmarkFileName   "hosts"
 
#define kBookmarkBupFileName   "bookmarks.old"
 
#define BMTINDEX(p)   ((int) ((char *) p - (char *) gBookmarkTable) / (int) sizeof(Bookmark))
 

Typedefs

typedef struct BookmarkBookmarkPtr
 
typedef struct Bookmark Bookmark
 

Functions

void BookmarkToURL (BookmarkPtr, char *, size_t)
 
void SetBookmarkDefaults (BookmarkPtr)
 
int ParseHostLine (char *, BookmarkPtr)
 
void CloseBookmarkFile (FILE *)
 
FILEOpenBookmarkFile (int *)
 
FILEOpenTmpBookmarkFile (int)
 
int SaveBookmarkTable (void)
 
int GetNextBookmark (FILE *, Bookmark *)
 
int GetBookmark (const char *const, Bookmark *)
 
int PutBookmark (Bookmark *, int)
 
int LoadBookmarkTable (void)
 
BookmarkPtr SearchBookmarkTable (const char *)
 
void SortBookmarks (void)
 
void DefaultBookmarkName (char *, size_t, char *)
 

Macro Definition Documentation

◆ BMTINDEX

#define BMTINDEX (   p)    ((int) ((char *) p - (char *) gBookmarkTable) / (int) sizeof(Bookmark))

Definition at line 43 of file bookmark.h.

◆ kBookmarkBupFileName

#define kBookmarkBupFileName   "bookmarks.old"

Definition at line 41 of file bookmark.h.

◆ kBookmarkFileName

#define kBookmarkFileName   "bookmarks"

Definition at line 37 of file bookmark.h.

◆ kBookmarkMinVersion

#define kBookmarkMinVersion   3

Definition at line 33 of file bookmark.h.

◆ kBookmarkVersion

#define kBookmarkVersion   8

Definition at line 32 of file bookmark.h.

◆ kOldBookmarkFileName

#define kOldBookmarkFileName   "hosts"

Definition at line 40 of file bookmark.h.

◆ kTmpBookmarkFileName

#define kTmpBookmarkFileName   "bookmarks-tmp"

Definition at line 39 of file bookmark.h.

Typedef Documentation

◆ Bookmark

◆ BookmarkPtr

Definition at line 8 of file bookmark.h.

Function Documentation

◆ BookmarkToURL()

void BookmarkToURL ( BookmarkPtr  bmp,
char url,
size_t  urlsize 
)

Definition at line 36 of file bookmark.c.

37{
38 char pbuf[32];
39
40 /* //<user>:<password>@<host>:<port>/<url-path> */
41 /* Note that if an absolute path is given,
42 * you need to escape the first entry, i.e. /pub -> %2Fpub
43 */
44 (void) Strncpy(url, "ftp://", urlsize);
45 if (bmp->user[0] != '\0') {
46 (void) Strncat(url, bmp->user, urlsize);
47 if (bmp->pass[0] != '\0') {
48 (void) Strncat(url, ":", urlsize);
49 (void) Strncat(url, "PASSWORD", urlsize);
50 }
51 (void) Strncat(url, "@", urlsize);
52 }
53 (void) Strncat(url, bmp->name, urlsize);
54 if (bmp->port != 21) {
55 (void) sprintf(pbuf, ":%u", (unsigned int) bmp->port);
56 (void) Strncat(url, pbuf, urlsize);
57 }
58 if (bmp->dir[0] == '/') {
59 /* Absolute URL path, must escape first slash. */
60 (void) Strncat(url, "/%2F", urlsize);
61 (void) Strncat(url, bmp->dir + 1, urlsize);
62 (void) Strncat(url, "/", urlsize);
63 } else if (bmp->dir[0] != '\0') {
64 (void) Strncat(url, "/", urlsize);
65 (void) Strncat(url, bmp->dir, urlsize);
66 (void) Strncat(url, "/", urlsize);
67 }
68} /* BookmarkToURL */
char * Strncat(char *const, const char *const, const size_t)
Definition: Strncat.c:13
char * Strncpy(char *const, const char *const, const size_t)
Definition: Strncpy.c:11
#define sprintf(buf, format,...)
Definition: sprintf.c:55
BITMAP bmp
Definition: alphablend.c:62
static const WCHAR url[]
Definition: encode.c:1432
Definition: pbuf.h:79

Referenced by CurrentURL(), PrintHosts(), and SaveUnsavedBookmark().

◆ CloseBookmarkFile()

void CloseBookmarkFile ( FILE fp)

Definition at line 246 of file bookmark.c.

247{
248 if (fp != NULL)
249 (void) fclose(fp);
250} /* CloseBookmarkFile */
#define NULL
Definition: types.h:112
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)

Referenced by GetBookmark(), LoadBookmarkTable(), OpenBookmarkFile(), PrintHosts(), PutBookmark(), and SaveBookmarkTable().

◆ DefaultBookmarkName()

void DefaultBookmarkName ( char dst,
size_t  siz,
char src 
)

Definition at line 817 of file bookmark.c.

818{
819 char str[128];
820 const char *token;
821 const char *cp;
822
823 (void) STRNCPY(str, src);
824
825 /* Pick the first "significant" part of the hostname. Usually
826 * this is the first word in the name, but if it's something like
827 * ftp.unl.edu, we would want to choose "unl" and not "ftp."
828 */
829 token = str;
830 if ((token = strtok(str, ".")) == NULL)
831 token = str;
832 else if ((ISTRNEQ(token, "ftp", 3)) || (ISTRNEQ(token, "www", 3))) {
833 if ((token = strtok(NULL, ".")) == NULL)
834 token = "";
835 }
836 for (cp = token; ; cp++) {
837 if (*cp == '\0') {
838 /* Token was all digits, like an IP address perhaps. */
839 token = "";
840 }
841 if (!isdigit((int) *cp))
842 break;
843 }
844 (void) Strncpy(dst, token, siz);
845} /* DefaultBookmarkName */
#define isdigit(c)
Definition: acclib.h:68
char * strtok(char *String, const char *Delimiters)
Definition: utclib.c:338
#define STRNCPY(dst, src, n)
Definition: rdesktop.h:168
GLenum src
Definition: glext.h:6340
GLenum GLenum dst
Definition: glext.h:6340
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat token
Definition: glfuncs.h:210
POINT cp
Definition: magnifier.c:59
#define ISTRNEQ(a, b, s)
Definition: util.h:34
const WCHAR * str

Referenced by PromptForBookmarkName().

◆ GetBookmark()

int GetBookmark ( const char * const  bmabbr,
Bookmark bmp 
)

Definition at line 387 of file bookmark.c.

388{
389 FILE *fp;
390 char line[512];
391 Bookmark byHostName;
392 Bookmark byHostAbbr;
393 Bookmark byBmAbbr;
394 size_t byBmNameFlag = 0;
395 size_t byBmAbbrFlag = 0;
396 size_t byHostNameFlag = 0;
397 size_t byHostAbbrFlag = 0;
398 int result = -1;
399 int exactMatch = 0;
400 size_t bmabbrLen;
401 char *cp;
402
404 if (fp == NULL)
405 return (-1);
406
407 bmabbrLen = strlen(bmabbr);
408 while (FGets(line, sizeof(line), fp) != NULL) {
409 if (ParseHostLine(line, bmp) < 0)
410 continue;
411 if (ISTREQ(bmp->bookmarkName, bmabbr)) {
412 /* Exact match, done. */
413 byBmNameFlag = bmabbrLen;
414 exactMatch = 1;
415 break;
416 } else if (ISTRNEQ(bmp->bookmarkName, bmabbr, bmabbrLen)) {
417 /* Remember this one, it matched an abbreviated
418 * bookmark name.
419 */
420 byBmAbbr = *bmp;
421 byBmAbbrFlag = bmabbrLen;
422 } else if (ISTREQ(bmp->name, bmabbr)) {
423 /* Remember this one, it matched a full
424 * host name.
425 */
426 byHostName = *bmp;
427 byHostNameFlag = bmabbrLen;
428 } else if ((cp = strchr(bmp->name, '.')) != NULL) {
429 /* See if it matched part of the hostname. */
430 if (ISTRNEQ(bmp->name, "ftp", 3)) {
431 cp = cp + 1;
432 } else if (ISTRNEQ(bmp->name, "www", 3)) {
433 cp = cp + 1;
434 } else {
435 cp = bmp->name;
436 }
437 if (ISTRNEQ(cp, bmabbr, bmabbrLen)) {
438 /* Remember this one, it matched a full
439 * host name.
440 */
441 byHostAbbr = *bmp;
442 byHostAbbrFlag = bmabbrLen;
443 }
444 }
445 }
446
447 if (gBookmarkMatchMode == 0) {
448 /* Only use a bookmark when the exact
449 * bookmark name was used.
450 */
451 if (exactMatch != 0) {
452 result = 0;
453 }
454 } else {
455 /* Pick the best match, if any. */
456 if (byBmNameFlag != 0) {
457 /* *bmp is already set. */
458 result = 0;
459 } else if (byBmAbbrFlag != 0) {
460 result = 0;
461 *bmp = byBmAbbr;
462 } else if (byHostNameFlag != 0) {
463 result = 0;
464 *bmp = byHostName;
465 } else if (byHostAbbrFlag != 0) {
466 result = 0;
467 *bmp = byHostAbbr;
468 }
469 }
470
471 if (result != 0)
472 memset(bmp, 0, sizeof(Bookmark));
473
475 return (result);
476} /* GetBookmark */
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char * strchr(const char *String, int ch)
Definition: utclib.c:501
void CloseBookmarkFile(FILE *fp)
Definition: bookmark.c:246
int ParseHostLine(char *line, BookmarkPtr bmp)
Definition: bookmark.c:135
FILE * OpenBookmarkFile(int *numBookmarks0)
Definition: bookmark.c:275
int gBookmarkMatchMode
Definition: bookmark.c:26
GLuint64EXT * result
Definition: glext.h:11304
#define ISTREQ(a, b)
Definition: util.h:33
char * FGets(char *, size_t, FILE *)
Definition: util.c:111
#define memset(x, y, z)
Definition: compat.h:39
Definition: parser.c:49

Referenced by OpenCmd(), and SetStartupURL().

◆ GetNextBookmark()

int GetNextBookmark ( FILE fp,
Bookmark bmp 
)

Definition at line 257 of file bookmark.c.

258{
259 char line[512];
260
261 while (FGets(line, sizeof(line), fp) != NULL) {
262 if (ParseHostLine(line, bmp) >= 0)
263 return (0);
264 }
265 return (-1);
266} /* GetNextBookmark */

Referenced by LoadBookmarkTable(), OpenBookmarkFile(), and PrintHosts().

◆ LoadBookmarkTable()

int LoadBookmarkTable ( void  )

Definition at line 524 of file bookmark.c.

525{
526 int i, nb;
527 FILE *infp;
528
529 infp = OpenBookmarkFile(&nb);
530 if (infp == NULL) {
531 nb = 0;
532 }
533 if ((nb != gNumBookmarks) && (gBookmarkTable != NULL)) {
534 /* Re-loading the table from disk. */
535 gBookmarkTable = (Bookmark *) realloc(gBookmarkTable, (size_t) (nb + 1) * sizeof(Bookmark));
536 memset(gBookmarkTable, 0, (nb + 1) * sizeof(Bookmark));
537 } else {
538 gBookmarkTable = calloc((size_t) (nb + 1), (size_t) sizeof(Bookmark));
539 }
540
541 if (gBookmarkTable == NULL) {
542 CloseBookmarkFile(infp);
543 return (-1);
544 }
545
546 for (i=0; i<nb; i++) {
547 if (GetNextBookmark(infp, gBookmarkTable + i) < 0) {
548 break;
549 }
550 }
552
553 CloseBookmarkFile(infp);
555 return (0);
556} /* LoadBookmarkTable */
BookmarkPtr gBookmarkTable
Definition: bookmark.c:28
int GetNextBookmark(FILE *fp, Bookmark *bmp)
Definition: bookmark.c:257
int gNumBookmarks
Definition: bookmark.c:27
void SortBookmarks(void)
Definition: bookmark.c:507
#define realloc
Definition: debug_ros.c:6
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define calloc
Definition: rosglue.h:14

Referenced by ReCacheBookmarks().

◆ OpenBookmarkFile()

FILE * OpenBookmarkFile ( int numBookmarks0)

Definition at line 275 of file bookmark.c.

276{
277 char pathName[256], path2[256];
278 char line[256];
279 FILE *fp;
280 int version;
281 int numBookmarks;
282 Bookmark junkbm;
283
284 if (gOurDirectoryPath[0] == '\0')
285 return NULL; /* Don't create in root directory. */
286 (void) OurDirectoryPath(pathName, sizeof(pathName), kBookmarkFileName);
287 fp = fopen(pathName, FOPEN_READ_TEXT);
288 if (fp == NULL) {
289 /* See if it exists under the old name. */
291 if (rename(path2, pathName) == 0) {
292 /* Rename succeeded, now open it. */
293 fp = fopen(pathName, FOPEN_READ_TEXT);
294 if (fp == NULL)
295 return NULL;
296 }
297 return NULL; /* Okay to not have one yet. */
298 }
299
300 (void) _chmod(pathName, 00600);
301 if (FGets(line, sizeof(line), fp) == NULL) {
302 (void) fprintf(stderr, "%s: invalid format.\n", pathName);
303 (void) fclose(fp);
304 return NULL;
305 }
306
307 /* Sample line we're looking for:
308 * "NcFTP bookmark-file version: 8"
309 */
310 version = -1;
311 (void) sscanf(line, "%*s %*s %*s %d", &version);
313 if (version < 0) {
314 (void) fprintf(stderr, "%s: invalid format, or bad version.\n", pathName);
315 (void) fclose(fp);
316 return NULL;
317 }
318 (void) STRNCPY(path2, pathName);
319 (void) sprintf(line, ".v%d", version);
321 (void) rename(pathName, path2);
322 (void) fprintf(stderr, "%s: old version.\n", pathName);
323 (void) fclose(fp);
324 return NULL;
325 }
326
327 /* Sample line we're looking for:
328 * "Number of entries: 28" or "# # # 1"
329 */
330 numBookmarks = -1;
331
332 /* At the moment, we can't trust the number stored in the
333 * file. It's there for future use.
334 */
335 if (FGets(line, sizeof(line), fp) == NULL) {
336 (void) fprintf(stderr, "%s: invalid format.\n", pathName);
337 (void) fclose(fp);
338 return NULL;
339 }
340
341 if (numBookmarks0 == (int *) 0) {
342 /* If the caller doesn't care how many bookmarks are *really*
343 * in the file, then we can return now.
344 */
345 return(fp);
346 }
347
348 /* Otherwise, we have to read through the whole file because
349 * unfortunately the header line can't be trusted.
350 */
351 for (numBookmarks = 0; ; numBookmarks++) {
352 if (GetNextBookmark(fp, &junkbm) < 0)
353 break;
354 }
355
356 /* Now we have to re-open and re-position the file.
357 * We don't use rewind() because it doesn't always work.
358 * This introduces a race condition, but the bookmark
359 * functionality wasn't designed to be air-tight.
360 */
362 fp = fopen(pathName, FOPEN_READ_TEXT);
363 if (fp == NULL)
364 return (NULL);
365 if (FGets(line, sizeof(line), fp) == NULL) {
366 (void) fprintf(stderr, "%s: invalid format.\n", pathName);
367 (void) fclose(fp);
368 return NULL;
369 }
370
371 if (FGets(line, sizeof(line), fp) == NULL) {
372 (void) fprintf(stderr, "%s: invalid format.\n", pathName);
373 (void) fclose(fp);
374 return NULL;
375 }
376
377 /* NOW we're done. */
378 *numBookmarks0 = numBookmarks;
379 return (fp);
380} /* OpenBookmarkFile */
#define STRNCAT(d, s)
Definition: Strn.h:48
char gOurDirectoryPath[]
Definition: util.c:17
#define kOldBookmarkFileName
Definition: bookmark.h:40
#define kBookmarkFileName
Definition: bookmark.h:37
#define kBookmarkMinVersion
Definition: bookmark.h:33
static const WCHAR version[]
Definition: asmname.c:66
#define stderr
Definition: stdio.h:100
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
_Check_return_ _CRTIMP int __cdecl sscanf(_In_z_ const char *_Src, _In_z_ _Scanf_format_string_ const char *_Format,...)
char * OurDirectoryPath(char *const dst, const size_t siz, const char *const fname)
Definition: util.c:486
static const WCHAR path2[]
Definition: path.c:29
#define FOPEN_READ_TEXT
Definition: syshdrs.h:82
_Check_return_ _CRTIMP int __cdecl _chmod(_In_z_ const char *_Filename, _In_ int _Mode)
_Check_return_ int __cdecl rename(_In_z_ const char *_OldFilename, _In_z_ const char *_NewFilename)

Referenced by GetBookmark(), LoadBookmarkTable(), PrintHosts(), and PutBookmark().

◆ OpenTmpBookmarkFile()

FILE * OpenTmpBookmarkFile ( int  nb)

Definition at line 666 of file bookmark.c.

667{
668 FILE *outfp;
669 char pidStr[32];
670 char pathName[256], path2[256];
671
672 if (gOurDirectoryPath[0] == '\0')
673 return (NULL); /* Don't create in root directory. */
674
676 (void) OurDirectoryPath(pathName, sizeof(pathName), kTmpBookmarkFileName);
677 (void) sprintf(pidStr, "-%u.txt", (unsigned int) getpid());
678 (void) STRNCAT(pathName, pidStr);
679
680 outfp = fopen(pathName, FOPEN_WRITE_TEXT);
681 if (outfp == NULL) {
682 (void) fprintf(stderr, "Could not save bookmark.\n");
683 perror(pathName);
684 return (NULL);
685 }
686 (void) _chmod(pathName, 00600);
687 if (nb > 0) {
688 if (fprintf(outfp, "NcFTP bookmark-file version: %d\nNumber of bookmarks: %d\n", kBookmarkVersion, nb) < 0) {
689 (void) fprintf(stderr, "Could not save bookmark.\n");
690 perror(pathName);
691 (void) fclose(outfp);
692 return (NULL);
693 }
694 } else {
695 if (fprintf(outfp, "NcFTP bookmark-file version: %d\nNumber of bookmarks: ??\n", kBookmarkVersion) < 0) {
696 (void) fprintf(stderr, "Could not save bookmark.\n");
697 perror(pathName);
698 (void) fclose(outfp);
699 return (NULL);
700 }
701 }
702
703 return (outfp);
704} /* OpenTmpBookmarkFile */
#define kTmpBookmarkFileName
Definition: bookmark.h:39
#define kBookmarkVersion
Definition: bookmark.h:32
_CRTIMP void __cdecl perror(_In_opt_z_ const char *_ErrMsg)
#define FOPEN_WRITE_TEXT
Definition: syshdrs.h:83
#define getpid
Definition: wintirpc.h:52

Referenced by PutBookmark(), and SaveBookmarkTable().

◆ ParseHostLine()

int ParseHostLine ( char line,
BookmarkPtr  bmp 
)

Definition at line 135 of file bookmark.c.

136{
137 char token[128];
138 char pass[128];
139 char *s, *d;
140 char *tokenend;
141 long L;
142 int i;
143 int result;
144 int n, n1, n2;
145
147 s = line;
148 tokenend = token + sizeof(token) - 1;
149 result = -1;
150 for (i=1; ; i++) {
151 if (*s == '\0')
152 break;
153 /* Some tokens may need to have a comma in them. Since this is a
154 * field delimiter, these fields use \, to represent a comma, and
155 * \\ for a backslash. This chunk gets the next token, paying
156 * attention to the escaped stuff.
157 */
158 for (d = token; *s != '\0'; ) {
159 if ((*s == '\\') && (s[1] != '\0')) {
160 if (d < tokenend)
161 *d++ = s[1];
162 s += 2;
163 } else if (*s == ',') {
164 ++s;
165 break;
166 } else if ((*s == '$') && (s[1] != '\0') && (s[2] != '\0')) {
167 n1 = HexCharToNibble(s[1]);
168 n2 = HexCharToNibble(s[2]);
169 if ((n1 >= 0) && (n2 >= 0)) {
170 n = (n1 << 4) | n2;
171 if (d < tokenend)
172 *(unsigned char *)d++ = (unsigned int) n;
173 }
174 s += 3;
175 } else {
176 if (d < tokenend)
177 *d++ = *s;
178 ++s;
179 }
180 }
181 *d = '\0';
182 switch(i) {
183 case 1: (void) STRNCPY(bmp->bookmarkName, token); break;
184 case 2: (void) STRNCPY(bmp->name, token); break;
185 case 3: (void) STRNCPY(bmp->user, token); break;
186 case 4: (void) STRNCPY(bmp->pass, token); break;
187 case 5: (void) STRNCPY(bmp->acct, token); break;
188 case 6: (void) STRNCPY(bmp->dir, token);
189 result = 0; /* Good enough to have these fields. */
190 break;
191 case 7:
192 if (token[0] != '\0')
193 bmp->xferType = (int) token[0];
194 break;
195 case 8:
196 /* Most of the time, we won't have a port. */
197 if (token[0] == '\0')
198 bmp->port = (unsigned int) kDefaultFTPPort;
199 else
200 bmp->port = (unsigned int) atoi(token);
201 break;
202 case 9:
203 (void) sscanf(token, "%lx", &L);
204 bmp->lastCall = (time_t) L;
205 break;
206 case 10: bmp->hasSIZE = atoi(token); break;
207 case 11: bmp->hasMDTM = atoi(token); break;
208 case 12: bmp->hasPASV = atoi(token); break;
209 case 13: bmp->isUnix = atoi(token);
210 result = 3; /* Version 3 had all fields to here. */
211 break;
212 case 14: (void) STRNCPY(bmp->lastIP, token); break;
213 case 15: (void) STRNCPY(bmp->comment, token); break;
214 case 16:
215 case 17:
216 case 18:
217 case 19:
218 break;
219 case 20: bmp->xferMode = token[0];
220 result = 7; /* Version 7 has all fields to here. */
221 break;
222 case 21: bmp->hasUTIME = atoi(token);
223 break;
224 case 22: (void) STRNCPY(bmp->ldir, token);
225 result = 8; /* Version 8 has all fields to here. */
226 break;
227 default:
228 result = 99; /* Version >8 ? */
229 goto done;
230 }
231 }
232done:
233
234 /* Decode password, if it was base-64 encoded. */
235 if (strncmp(bmp->pass, kPasswordMagic, kPasswordMagicLen) == 0) {
237 (void) STRNCPY(bmp->pass, pass);
238 }
239 return (result);
240} /* ParseHostLine */
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
void SetBookmarkDefaults(BookmarkPtr bmp)
Definition: bookmark.c:74
static int HexCharToNibble(int c)
Definition: bookmark.c:94
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
__kernel_time_t time_t
Definition: linux.h:252
GLdouble s
Definition: gl.h:2039
GLdouble n
Definition: glext.h:7729
_Check_return_ int __cdecl atoi(_In_z_ const char *_Str)
#define d
Definition: ke_i.h:81
void FromBase64(void *dst0, const void *src0, size_t n, int terminate)
Definition: util.c:128
#define kPasswordMagic
Definition: util.h:47
#define kPasswordMagicLen
Definition: util.h:48
#define kDefaultFTPPort
Definition: ncftp.h:312
#define L(x)
Definition: ntvdm.h:50
int n2
Definition: dwarfget.c:147
int n1
Definition: dwarfget.c:147
pass
Definition: typegen.h:25

Referenced by GetBookmark(), and GetNextBookmark().

◆ PutBookmark()

int PutBookmark ( Bookmark bmp,
int  savePassword 
)

Definition at line 748 of file bookmark.c.

749{
750 FILE *infp, *outfp;
751 char line[256];
752 char bmAbbr[64];
753 int replaced = 0;
754 size_t len;
755
756 outfp = OpenTmpBookmarkFile(0);
757 if (outfp == NULL)
758 return (-1);
759
760 (void) STRNCPY(bmAbbr, bmp->bookmarkName);
761 (void) STRNCAT(bmAbbr, ",");
762 len = strlen(bmAbbr);
763
764 /* This may fail the first time we ever save a bookmark. */
765 infp = OpenBookmarkFile(NULL);
766 if (infp != NULL) {
767 while (FGets(line, sizeof(line), infp) != NULL) {
768 if (strncmp(line, bmAbbr, len) == 0) {
769 /* Replace previous entry. */
770 if (WriteBmLine(bmp, outfp, savePassword) < 0) {
771 (void) fprintf(stderr, "Could not save bookmark.\n");
772 perror("reason");
773 (void) fclose(outfp);
774 }
775 replaced = 1;
776 } else {
777 if (fprintf(outfp, "%s\n", line) < 0) {
778 (void) fprintf(stderr, "Could not save bookmark.\n");
779 perror("reason");
780 (void) fclose(outfp);
781 return (-1);
782 }
783 }
784 }
785 CloseBookmarkFile(infp);
786 }
787
788 if (replaced == 0) {
789 /* Add it as a new bookmark. */
790 if (WriteBmLine(bmp, outfp, savePassword) < 0) {
791 (void) fprintf(stderr, "Could not save bookmark.\n");
792 perror("reason");
793 (void) fclose(outfp);
794 return (-1);
795 }
796 }
797
798 if (fclose(outfp) < 0) {
799 (void) fprintf(stderr, "Could not save bookmark.\n");
800 perror("reason");
801 return (-1);
802 }
803
804 if (SwapBookmarkFiles() < 0) {
805 (void) fprintf(stderr, "Could not rename bookmark file.\n");
806 perror("reason");
807 return (-1);
808 }
809 return (0);
810} /* PutBookmark */
FILE * OpenTmpBookmarkFile(int nb)
Definition: bookmark.c:666
static int WriteBmLine(Bookmark *bmp, FILE *outfp, int savePassword)
Definition: bookmark.c:601
static int SwapBookmarkFiles(void)
Definition: bookmark.c:642
GLenum GLsizei len
Definition: glext.h:6722

Referenced by SaveCurrentAsBookmark().

◆ SaveBookmarkTable()

int SaveBookmarkTable ( void  )

Definition at line 710 of file bookmark.c.

711{
712 int i;
713 FILE *outfp;
714 int nb;
715
716 if ((gNumBookmarks < 1) || (gBookmarkTable == NULL))
717 return (0); /* Nothing to save. */
718
719 /* Get a count of live bookmarks. */
720 for (i=0, nb=0; i<gNumBookmarks; i++) {
721 if (gBookmarkTable[i].deleted == 0)
722 nb++;
723 }
724 outfp = OpenTmpBookmarkFile(nb);
725 if (outfp == NULL) {
726 return (-1);
727 }
728
729 for (i=0; i<gNumBookmarks; i++) {
730 if (gBookmarkTable[i].deleted == 0) {
731 if (WriteBmLine(gBookmarkTable + i, outfp, 1) < 0) {
732 CloseBookmarkFile(outfp);
733 return (-1);
734 }
735 }
736 }
737 CloseBookmarkFile(outfp);
738 if (SwapBookmarkFiles() < 0) {
739 return (-1);
740 }
741 return (0);
742} /* SaveBookmarkTable */

◆ SearchBookmarkTable()

BookmarkPtr SearchBookmarkTable ( const char key)

Definition at line 498 of file bookmark.c.

499{
501} /* SearchBookmarkTable */
static int BookmarkSearchProc(const void *key, const void *b)
Definition: bookmark.c:490
Definition: copy.c:22
#define bsearch

◆ SetBookmarkDefaults()

void SetBookmarkDefaults ( BookmarkPtr  bmp)

Definition at line 74 of file bookmark.c.

75{
76 (void) memset(bmp, 0, sizeof(Bookmark));
77
78 bmp->xferType = 'I';
79 bmp->xferMode = 'S'; /* Use FTP protocol default as ours too. */
84 bmp->isUnix = 1;
85 bmp->lastCall = (time_t) 0;
86 bmp->deleted = 0;
87} /* SetBookmarkDefaults */
#define kCommandAvailabilityUnknown
Definition: ncftp.h:379

Referenced by OpenCmd(), OpenURL(), ParseHostLine(), and SetStartupURL().

◆ SortBookmarks()

void SortBookmarks ( void  )

Definition at line 507 of file bookmark.c.

508{
509 if ((gBookmarkTable == NULL) || (gNumBookmarks < 2))
510 return;
511
512 /* Sorting involves swapping entire Bookmark structures.
513 * Normally the proper thing to do is to use an array
514 * of pointers to Bookmarks and sort them, but even
515 * these days a large bookmark list can be sorted in
516 * the blink of an eye.
517 */
519} /* SortBookmarks */
static int BookmarkSortProc(const void *a, const void *b)
Definition: bookmark.c:482
void __cdecl qsort(_Inout_updates_bytes_(_NumOfElements *_SizeOfElements) void *_Base, _In_ size_t _NumOfElements, _In_ size_t _SizeOfElements, _In_ int(__cdecl *_PtFuncCompare)(const void *, const void *))

Referenced by LoadBookmarkTable().