Changeset e374dee for libfaim/util.c
- Timestamp:
- Oct 10, 2003, 5:12:30 PM (21 years ago)
- Branches:
- master, barnowl_perlaim, debian, owl, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
- Children:
- fe6f1d3
- Parents:
- f4d0975
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libfaim/util.c
r862371b re374dee 1 1 /* 2 * 3 * 4 * 2 * A little bit of this 3 * A little bit of that 4 * It started with a kiss 5 * Now we're up to bat 5 6 */ 6 7 … … 9 10 #include <ctype.h> 10 11 11 faim_export faim_shortfunc int aimutil_putstr(u_char *dest, const char *src, int len) 12 #ifdef _WIN32 13 #include "win32dep.h" 14 #endif 15 16 faim_internal void faimdprintf(aim_session_t *sess, int dlevel, const char *format, ...) 17 { 18 if (!sess) { 19 fprintf(stderr, "faimdprintf: no session! boo! (%d, %s)\n", dlevel, format); 20 return; 21 } 22 if ((dlevel <= sess->debug) && sess->debugcb) { 23 va_list ap; 24 va_start(ap, format); 25 sess->debugcb(sess, dlevel, format, ap); 26 va_end(ap); 27 } 28 29 return; 30 } 31 32 faim_export int aimutil_putstr(char *dest, const char *src, int len) 12 33 { 13 34 memcpy(dest, src, len); … … 20 41 * 21 42 */ 22 faim_export int aimutil_tokslen(char *toSearch, int index, char dl)43 faim_export int aimutil_tokslen(char *toSearch, int theindex, char dl) 23 44 { 24 45 int curCount = 1; … … 30 51 next = strchr(toSearch, dl); 31 52 32 while(curCount < index && next != NULL) {53 while(curCount < theindex && next != NULL) { 33 54 curCount++; 34 55 last = next + 1; … … 36 57 } 37 58 38 if ((curCount < index) || (next == NULL))59 if ((curCount < theindex) || (next == NULL)) 39 60 toReturn = strlen(toSearch) - (curCount - 1); 40 61 else … … 61 82 } 62 83 63 faim_export char *aimutil_itemi dx(char *toSearch, intindex, char dl)84 faim_export char *aimutil_itemindex(char *toSearch, int theindex, char dl) 64 85 { 65 86 int curCount; … … 73 94 next = strchr(toSearch, dl); 74 95 75 while (curCount < index && next != NULL) {96 while (curCount < theindex && next != NULL) { 76 97 curCount++; 77 98 last = next + 1; … … 79 100 } 80 101 81 if (curCount < index) {102 if (curCount < theindex) { 82 103 toReturn = malloc(sizeof(char)); 83 104 *toReturn = '\0'; … … 85 106 next = strchr(last, dl); 86 107 87 if (curCount < index) {108 if (curCount < theindex) { 88 109 toReturn = malloc(sizeof(char)); 89 110 *toReturn = '\0'; … … 101 122 } 102 123 124 /** 125 * Calculate the checksum of a given icon. 126 * 127 */ 128 faim_export fu16_t aimutil_iconsum(const fu8_t *buf, int buflen) 129 { 130 fu32_t sum; 131 int i; 132 133 for (i=0, sum=0; i+1<buflen; i+=2) 134 sum += (buf[i+1] << 8) + buf[i]; 135 if (i < buflen) 136 sum += buf[i]; 137 sum = ((sum & 0xffff0000) >> 16) + (sum & 0x0000ffff); 138 139 return sum; 140 } 141 142 faim_export int aim_util_getlocalip(fu8_t *ip) 143 { 144 struct hostent *hptr; 145 char localhost[129]; 146 147 /* XXX if available, use getaddrinfo() */ 148 /* XXX allow client to specify which IP to use for multihomed boxes */ 149 150 if (gethostname(localhost, 128) < 0) 151 return -1; 152 153 if (!(hptr = gethostbyname(localhost))) 154 return -1; 155 memcpy(ip, hptr->h_addr_list[0], 4); 156 157 return 0; 158 } 159 103 160 /* 104 161 * int snlen(const char *) … … 112 169 { 113 170 int i = 0; 114 const char *curPtr = NULL;115 171 116 172 if (!sn) 117 173 return 0; 118 174 119 curPtr = sn; 120 while ( (*curPtr) != (char) NULL) { 121 if ((*curPtr) != ' ') 122 i++; 123 curPtr++; 175 while (*sn != '\0') { 176 if (*sn != ' ') 177 i++; 178 sn++; 124 179 } 125 180 … … 133 188 * on screen names for AIM/AOL. Mainly, this means case and space 134 189 * insensitivity (all case differences and spacing differences are 135 * ignored). 190 * ignored, with the exception that screen names can not start with 191 * a space). 136 192 * 137 193 * Return: 0 if equal … … 141 197 faim_export int aim_sncmp(const char *sn1, const char *sn2) 142 198 { 143 const char *curPtr1 = NULL, *curPtr2 = NULL; 144 145 if (aim_snlen(sn1) != aim_snlen(sn2)) 146 return 1; 147 148 curPtr1 = sn1; 149 curPtr2 = sn2; 150 while ( (*curPtr1 != (char) NULL) && (*curPtr2 != (char) NULL) ) { 151 if ( (*curPtr1 == ' ') || (*curPtr2 == ' ') ) { 152 if (*curPtr1 == ' ') 153 curPtr1++; 154 if (*curPtr2 == ' ') 155 curPtr2++; 156 } else { 157 if ( toupper(*curPtr1) != toupper(*curPtr2)) 158 return 1; 159 curPtr1++; 160 curPtr2++; 161 } 162 } 163 164 /* Should both be NULL */ 165 if (*curPtr1 != *curPtr2) 166 return 1; 199 200 do { 201 while (*sn2 == ' ') 202 sn2++; 203 while (*sn1 == ' ') 204 sn1++; 205 if (toupper(*sn1) != toupper(*sn2)) 206 return 1; 207 } while ((*sn1 != '\0') && sn1++ && sn2++); 167 208 168 209 return 0; 169 210 } 170 171 /* strsep Copyright (C) 1992, 1993 Free Software Foundation, Inc.172 strsep is part of the GNU C Library.173 174 The GNU C Library is free software; you can redistribute it and/or175 modify it under the terms of the GNU Library General Public License as176 published by the Free Software Foundation; either version 2 of the177 License, or (at your option) any later version.178 179 The GNU C Library is distributed in the hope that it will be useful,180 but WITHOUT ANY WARRANTY; without even the implied warranty of181 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU182 Library General Public License for more details.183 184 You should have received a copy of the GNU Library General Public185 License along with the GNU C Library; see the file COPYING.LIB. If186 not, write to the Free Software Foundation, Inc., 675 Mass Ave,187 Cambridge, MA 02139, USA. */188 189 /* Minor changes by and1000 on 15/1/97 to make it go under Nemesis */190 191 faim_export char *aim_strsep(char **pp, const char *delim)192 {193 char *p, *q;194 195 if (!(p = *pp))196 return 0;197 198 if ((q = strpbrk (p, delim))) {199 *pp = q + 1;200 *q = '\0';201 } else202 *pp = 0;203 204 return p;205 }
Note: See TracChangeset
for help on using the changeset viewer.