Changeset e374dee for libfaim/util.c


Ignore:
Timestamp:
Oct 10, 2003, 5:12:30 PM (21 years ago)
Author:
James M. Kretchmar <kretch@mit.edu>
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
Message:
*** empty log message ***
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libfaim/util.c

    r862371b re374dee  
    11/*
    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
    56 */
    67
     
    910#include <ctype.h>
    1011
    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
     16faim_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
     32faim_export int aimutil_putstr(char *dest, const char *src, int len)
    1233{
    1334        memcpy(dest, src, len);
     
    2041 *
    2142 */
    22 faim_export int aimutil_tokslen(char *toSearch, int index, char dl)
     43faim_export int aimutil_tokslen(char *toSearch, int theindex, char dl)
    2344{
    2445        int curCount = 1;
     
    3051        next = strchr(toSearch, dl);
    3152
    32         while(curCount < index && next != NULL) {
     53        while(curCount < theindex && next != NULL) {
    3354                curCount++;
    3455                last = next + 1;
     
    3657        }
    3758
    38         if ((curCount < index) || (next == NULL))
     59        if ((curCount < theindex) || (next == NULL))
    3960                toReturn = strlen(toSearch) - (curCount - 1);
    4061        else
     
    6182}
    6283
    63 faim_export char *aimutil_itemidx(char *toSearch, int index, char dl)
     84faim_export char *aimutil_itemindex(char *toSearch, int theindex, char dl)
    6485{
    6586        int curCount;
     
    7394        next = strchr(toSearch, dl);
    7495
    75         while (curCount < index && next != NULL) {
     96        while (curCount < theindex && next != NULL) {
    7697                curCount++;
    7798                last = next + 1;
     
    79100        }
    80101
    81         if (curCount < index) {
     102        if (curCount < theindex) {
    82103                toReturn = malloc(sizeof(char));
    83104                *toReturn = '\0';
     
    85106        next = strchr(last, dl);
    86107
    87         if (curCount < index) {
     108        if (curCount < theindex) {
    88109                toReturn = malloc(sizeof(char));
    89110                *toReturn = '\0';
     
    101122}
    102123
     124/**
     125 * Calculate the checksum of a given icon.
     126 *
     127 */
     128faim_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
     142faim_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
    103160/*
    104161* int snlen(const char *)
     
    112169{
    113170        int i = 0;
    114         const char *curPtr = NULL;
    115171
    116172        if (!sn)
    117173                return 0;
    118174
    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++;
    124179        }
    125180
     
    133188* on screen names for AIM/AOL.  Mainly, this means case and space
    134189* 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).
    136192*
    137193* Return: 0 if equal
     
    141197faim_export int aim_sncmp(const char *sn1, const char *sn2)
    142198{
    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++);
    167208
    168209        return 0;
    169210}
    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/or
    175 modify it under the terms of the GNU Library General Public License as
    176 published by the Free Software Foundation; either version 2 of the
    177 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 of
    181 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    182 Library General Public License for more details.
    183 
    184 You should have received a copy of the GNU Library General Public
    185 License along with the GNU C Library; see the file COPYING.LIB.  If
    186 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         } else
    202                 *pp = 0;
    203 
    204         return p;
    205 }
Note: See TracChangeset for help on using the changeset viewer.