char *GetTrackerIdByUser(char *nickname) { char szWhoisCmd[100]; if(GettingUserTID) { if(Getting_user_tracker_error) { Getting_user_tracker_error = 0; GettingUserTID = 0; return (char *)-1; } if(*User_req_tracker_id) { GettingUserTID = 0; return User_req_tracker_id; } } else { strncpy(Getting_user_tracker_info_for, nickname, sizeof(Getting_user_tracker_info_for)-1); snprintf(szWhoisCmd, SSIZE(szWhoisCmd), NOX("/WHOIS %s"), nickname); User_req_tracker_id[0] = '\0'; SendChatString(szWhoisCmd,1); GettingUserTID = 1; } return NULL; }
char *GetChannelByUser(char *nickname) { char szWhoisCmd[100]; if(GettingUserChannel) { if(Getting_user_channel_error) { Getting_user_channel_error = 0; GettingUserChannel = 0; return (char *)-1; } if(*User_req_channel) { GettingUserChannel = 0; return User_req_channel; } } else { strncpy(Getting_user_channel_info_for, nickname, sizeof(Getting_user_channel_info_for)-1); User_req_channel[0] = '\0'; snprintf(szWhoisCmd, SSIZE(szWhoisCmd), NOX("/WHOIS %s"), nickname); SendChatString(szWhoisCmd,1); GettingUserChannel = 1; } return NULL; }
ssize_t StringPool::offsetForString(const String16 &val) const { const Vector<size_t> *indices = offsetsForString(val); ssize_t res = indices != NULL && indices->size() > 0 ? indices->itemAt(0) : -1; if (kIsDebug) { printf("Offset for string %s: %zd (%s)\n", String8(val).string(), SSIZE(res), res >= 0 ? String8(mEntries[mEntryArray[res]].value).string() : String8()); } return res; }
/* given the sequence, calculate the exact placement of the sectors */ static void calc_placement(struct params *fd, int gap) { int cur_sector, i, max_offset; int track_end=0; int final_slack; /* slack space extending from data start of last * sector on the track to fd->raw_capacity mark */ /* now compute the placement in terms of small sectors */ cur_sector = 0; for(i=0; i< fd->dsect; i++){ fd->sequence[i].offset = cur_sector; max_offset = cur_sector; /* offset of the starting sector */ if ( fd->sequence[i].sect == 1 ) fd->min = cur_sector * fd->chunksize; /* offset of the end of the of the highest sector */ if (fd->sequence[i].sect == fd->dsect) track_end = cur_sector * fd->chunksize + header_size + index_size + SSIZE(fd->sequence[i].size); if(i == fd->dsect - 1) break; cur_sector += chunks_in_sect(fd, fd->sequence[i].size, gap, fd->chunksize); } final_slack = fd->raw_capacity - cur_sector * fd->chunksize - header_size - index_size - 1; if(final_slack < 0) { fprintf(stderr, "Internal error, negative final slack %d\n", final_slack); abort(); } fd->max = fd->min + final_slack; fd->length = fd->rotations * fd->raw_capacity + track_end - fd->min; if(fd->length < 0) { fprintf(stderr, "Internal error, negative track length %d %d %d\n", fd->length, track_end, fd->min); abort(); exit(1); } /* this format accepts any offsets ranging from fd->min to fd->max. * After this track, the current offset will be: * fd->track_end + initial_offset - fd->min */ }
// Call this to set/join a channel. Since we can't be sure that we will be // able to join that channel, check it for completion // You can't be in more than one channel at a time with this API, so you // leave the current channel before trying to join // a new one. Because of this if the join fails, make sure you try to join // another channel, or the user won't be able to chat //-1 Failed to join // 0 joining // 1 successfully joined int SetNewChatChannel(char *channel) { char partstr[100]; if(!Socket_connected) return -1; partstr[sizeof(partstr)-1] = '\0'; if(Joining_channel==1) { if(Joined_channel==1) { //We made it in! Joining_channel = 0; return 1; } else if(Joined_channel==-1) { //Error -- we got a message that the channel was invite only, or we were banned or something Joining_channel = 0; strcpy_s(szChat_channel, ""); return -1; } } else { if(szChat_channel[0]) { snprintf(partstr, SSIZE(partstr), NOX("/PART %s"), szChat_channel); SendChatString(partstr,1); } strncpy(szChat_channel, channel, sizeof(szChat_channel)-1); snprintf(partstr, SSIZE(partstr), NOX("/JOIN %s"), szChat_channel); SendChatString(partstr,1); Joining_channel = 1; Joined_channel = 0; } return 0; }
static int compute_chunk_size_for_monosize(struct params *fd, int gap, int tailsize) { int min_chunksize; /* minimal chunk size reached so far */ int t_chunksize; /* tentative chunk size */ int ceiling; /* maximal divisor */ int t_sect_size; /* tentative sector size */ int min_sect_size=0; /* actual sector size */ int sector_size; int chunks_per_sect; int i; sector_size = SSIZE(sizeOfSector(fd,1)); min_chunksize = 0; ceiling = sector_size /( 129 + header_size); for(i= 1; i <= ceiling; i++ ){ t_chunksize = (sector_size - 1)/i + 1; /* unreachable chunk sizes */ if (((t_chunksize-header_size-1) & 511) > 255 && t_chunksize > 768 + header_size) continue; chunks_per_sect = (sector_size - 1)/t_chunksize + 1; t_sect_size = chunks_per_sect * t_chunksize; /* find the smallest sector size */ if (!min_chunksize || t_sect_size < min_sect_size ){ min_sect_size = t_sect_size; min_chunksize = t_chunksize; } if (t_sect_size == sector_size) break; } if(min_chunksize != sector_size) fd->need_init = 1; return min_chunksize; }
static int compute_tot_size(struct params *fd, int chunksize, int gap, int tailsize) { int i, nr; fd->nssect = 0; fd->actual_interleave = 1; for(i= 0; i < MAX_SIZECODE; i++){ nr = nrSectorsForSize(fd, i); fd->nssect += chunks_in_sect(fd, i, gap, chunksize) * nr; if(nr && GAPSIZE(i) < 34) fd->actual_interleave = 2; } if (tailsize >= 0) return (fd->nssect - chunks_in_sect(fd, tailsize, gap, chunksize)) * chunksize + SSIZE(tailsize); else return fd->nssect * chunksize; }
/* Extraer el fichero a file_path */ DWORD CLotusNote::AttachmentExtract(WORD index, char *file_path) { BLOCKID blockid; if (m_hnote == NULL) return Error_Handle("AttachmentExtract ... failed"); if (!MailGetMessageAttachmentInfo(m_hnote,index,&blockid,NULL,NULL,NULL,NULL,NULL,NULL)) { return SetError(false,ERR_API,"CLotusNote::AttachmentExtract -> MailGetMessageAttachmentInfo failed ... file is missing "); } return CLotusSection::Add_NApi_code_msg(MailExtractMessageAttachment(m_hnote,blockid,file_path),SSIZE(m_err_msg),"CLotusNote::AttachmentExtract->MailExtractMessageAttachment %s",file_path); }
/* Extrae el fichero en la ruta especificada */ DWORD CLotusNote::AttachmentExtractTo(WORD index, char *path) { BLOCKID blockid; char file_name[50]; char file_path[MAX_PATH]; if (m_hnote == NULL) return Error_Handle("AttachmentExtract ... failed"); if (!MailGetMessageAttachmentInfo(m_hnote,index,&blockid,file_name,NULL,NULL,NULL,NULL,NULL)) { return SetError(false,ERR_API,"CLotusNote::AttachmentExtractTo -> MailGetMessageAttachmentInfo failed ... file is missing "); } sprintf(file_path,"%s\\%s",path,file_name); return CLotusSection::Add_NApi_code_msg(MailExtractMessageAttachment(m_hnote,blockid,file_path),SSIZE(m_err_msg),"CLotusNote::AttachmentExtractTo->MailExtractMessageAttachment"); }
/* Extrae el fichero que corresponda con el nombre especificado */ DWORD CLotusNote::AttachmentExtractFile(char *file_path) { if (m_hnote == NULL) return Error_Handle("AttachmentExtract ... failed"); BLOCKID blockid; WORD index; char file[50]; char file_name[100]; char* cptr; char* pfile_name; // char err[100]; cptr = file_path; pfile_name = cptr; for (;;) { cptr = strstr(cptr,"\\"); if (cptr == NULL) break; cptr++; pfile_name = cptr; } strcpy(file_name,pfile_name); strupr(file_name); for (index = 0;;index++) { if (!MailGetMessageAttachmentInfo(m_hnote,index,&blockid,file,NULL,NULL,NULL,NULL,NULL)) { return SetError(false,ERR_FATAL,"AttachmentExtractFile ... file not found with FileName = %s",file_name); } // llevar a mayusculas el fichero strupr(file); if (strcmp(file,file_name) != 0) continue; return CLotusSection::Add_NApi_code_msg(MailExtractMessageAttachment(m_hnote,blockid,file_path),SSIZE(m_err_msg),"CLotusNote::AttachmentExtractFile->MailExtractMessageAttachment"); } return ERR_FATAL; }
DWORD CLotusNote::ItemSetNumber(char *item_name, NUMBER *number) { if (m_hnote == NULL) return Error_Handle("ItemSetText ... failed"); return CLotusSection::Add_NApi_code_msg(NSFItemSetNumber(m_hnote,item_name,number),SSIZE(m_err_msg),"CLotusNote::ItemSetNumber->NSFItemSetNumber"); }
DWORD CLotusNote::ItemDelete(char *item_name) { if (m_hnote == NULL) return Error_Handle("ItemDelete ... failed"); return CLotusSection::Add_NApi_code_msg(NSFItemDelete(m_hnote,item_name,strlen(item_name)),SSIZE(m_err_msg),"CLotusNote::ItemDelete->NSFItemDelete"); }
DWORD CLotusNote::AttachmentExtract(BLOCKID blockid, char *file_path) { if (m_hnote == NULL) return Error_Handle("AttachmentExtract ... failed"); return CLotusSection::Add_NApi_code_msg(MailExtractMessageAttachment(m_hnote,blockid,file_path),SSIZE(m_err_msg),"CLotusNote::AttachmentExtract->MailExtractMessageAttachment"); }
DWORD CLotusNote::Update(WORD flags) { if (m_hnote == NULL) return Error_Handle("CLotusNote::Update"); return CLotusSection::Add_NApi_code_msg(NSFNoteUpdate(m_hnote,flags),SSIZE(m_err_msg),"CLotusNote::Update->NSFNoteUpdate"); }
DWORD CLotusNote::ItemSetTime(char *itemname, TIMEDATE *ptime) { if (m_hnote == NULL) return Error_Handle("CLotusNote::ItemSetTime"); return CLotusSection::Add_NApi_code_msg(NSFItemSetTime(m_hnote,itemname,ptime),SSIZE(m_err_msg),"CLotusNote::ItemSetTime->NSFItemSetTime"); }
DWORD CLotusNote::ItemAdd(char *item_name, WORD item_type, WORD item_flags, char *item_value, DWORD item_len) { if (m_hnote == NULL) return Error_Handle("ItemAdd ... failed"); return CLotusSection::Add_NApi_code_msg(NSFItemAppend(m_hnote,item_flags,item_name,strlen(item_name),item_type,item_value,item_len),SSIZE(m_err_msg),"CLotusNote::ItemAdd->NSFItemAppend"); }
DWORD CLotusNote::Create_CompoundText(char *name, HANDLE *phRichText) { if (m_hnote == NULL) return Error_Handle("CLotusNote::Create_CompoundText"); return CLotusSection::Add_NApi_code_msg(CompoundTextCreate(m_hnote,name,phRichText),SSIZE(m_err_msg),"CLotusNote::Create_CompoundText->CompoundTextCreate"); }
ssize_t StringPool::add(const String16 &value, bool mergeDuplicates, const String8 *configTypeName, const ResTable_config *config) { ssize_t vidx = mValues.indexOfKey(value); ssize_t pos = vidx >= 0 ? mValues.valueAt(vidx) : -1; ssize_t eidx = pos >= 0 ? mEntryArray.itemAt(pos) : -1; if (eidx < 0) { eidx = mEntries.add(entry(value)); if (eidx < 0) { fprintf(stderr, "Failure adding string %s\n", String8(value).string()); return eidx; } } if (configTypeName != NULL) { entry &ent = mEntries.editItemAt(eidx); if (kIsDebug) { printf("*** adding config type name %s, was %s\n", configTypeName->string(), ent.configTypeName.string()); } if (ent.configTypeName.size() <= 0) { ent.configTypeName = *configTypeName; } else if (ent.configTypeName != *configTypeName) { ent.configTypeName = " "; } } if (config != NULL) { // Add this to the set of configs associated with the string. entry &ent = mEntries.editItemAt(eidx); size_t addPos; for (addPos = 0; addPos < ent.configs.size(); addPos++) { int cmp = ent.configs.itemAt(addPos).compareLogical(*config); if (cmp >= 0) { if (cmp > 0) { if (kIsDebug) { printf("*** inserting config: %s\n", config->toString().string()); } ent.configs.insertAt(*config, addPos); } break; } } if (addPos >= ent.configs.size()) { if (kIsDebug) { printf("*** adding config: %s\n", config->toString().string()); } ent.configs.add(*config); } } const bool first = vidx < 0; const bool styled = (pos >= 0 && (size_t) pos < mEntryStyleArray.size()) ? mEntryStyleArray[pos].spans.size() : 0; if (first || styled || !mergeDuplicates) { pos = mEntryArray.add(eidx); if (first) { vidx = mValues.add(value, pos); } entry &ent = mEntries.editItemAt(eidx); ent.indices.add(pos); } if (kIsDebug) { printf("Adding string %s to pool: pos=%zd eidx=%zd vidx=%zd\n", String8(value).string(), SSIZE(pos), SSIZE(eidx), SSIZE(vidx)); } return pos; }
char* CbBSTR::GetChar() { GetCharString(SSIZE(m_cstr)); return m_cstr; }
char * ParseIRCMessage(char *Line, int iMode) { char szRemLine[MAXLOCALSTRING] =""; char *pszTempStr; char szPrefix[MAXLOCALSTRING] = ""; char szHackPrefix[MAXLOCALSTRING] = ""; char szTarget[MAXLOCALSTRING] = ""; char szNick[MAXLOCALSTRING] = ""; char szCmd[MAXLOCALSTRING] = ""; char szCTCPCmd[MAXLOCALSTRING] = ""; static char szResponse[MAXLOCALSTRING] = ""; int iPrefixLen = 0; // JAS: Get rid of optimized warning szRemLine[MAXLOCALSTRING-1] = '\0'; szPrefix[MAXLOCALSTRING-1] = '\0'; szHackPrefix[MAXLOCALSTRING-1] = '\0'; szTarget[MAXLOCALSTRING-1] = '\0'; szNick[MAXLOCALSTRING-1] = '\0'; szCmd[MAXLOCALSTRING-1] = '\0'; szCTCPCmd[MAXLOCALSTRING-1] = '\0'; szResponse[MAXLOCALSTRING-1] = '\0'; if(strlen(Line)>=MAXLOCALSTRING) { return NULL; } //Nick included.... if(iMode==MSG_REMOTE) { strncpy(szRemLine, Line, sizeof(szRemLine)-1); //Start by getting the prefix if(Line[0]==':') { // pszTempStr=GetWordNum(0,Line+1); strncpy(szPrefix, pszTempStr, sizeof(szPrefix)-1); strncpy(szHackPrefix, pszTempStr, sizeof(szHackPrefix)-1); strncpy(szRemLine, Line+1+strlen(szPrefix), sizeof(szRemLine)-1); } //Next, get the Nick pszTempStr=strtok(szHackPrefix,"!"); if(pszTempStr) { strncpy(szNick, pszTempStr, sizeof(szNick)-1); } else { strncpy(szNick,szPrefix,31); szNick[31]=0; } iPrefixLen=strlen(szPrefix); } else if(iMode==MSG_LOCAL) { strncpy(szRemLine, Line, sizeof(szRemLine)-1); strncpy(szNick, Nick_name, sizeof(szNick)-1); strncpy(szPrefix, Nick_name, sizeof(szPrefix)-1); iPrefixLen=-2; } //Next is the command pszTempStr=GetWordNum(0,szRemLine); if(pszTempStr[0]) { strncpy(szCmd, pszTempStr, sizeof(szCmd)-1); } else { //Shouldn't ever happen, but we can't be sure of what the host will send us. return NULL; } //Move the szRemLine string up strncpy(szRemLine, Line+iPrefixLen+strlen(szCmd)+2, sizeof(szRemLine)-1); //Now parse the commands! if(stricmp(szCmd,NOX("PRIVMSG"))==0) { pszTempStr=GetWordNum(0,szRemLine); strncpy(szTarget, pszTempStr, sizeof(szTarget)-1); strncpy(szRemLine, Line+iPrefixLen+strlen(szCmd)+strlen(szTarget)+4, sizeof(szRemLine)-1); if(szRemLine[0]==':') { strncpy(szCTCPCmd, GetWordNum(0,szRemLine+1), sizeof(szCTCPCmd)-1); if(szCTCPCmd[strlen(szCTCPCmd)-1]==0x01) szCTCPCmd[strlen(szCTCPCmd)-1]=0x00; } else { strncpy(szCTCPCmd, GetWordNum(0,szRemLine), sizeof(szCTCPCmd)-1); if(szCTCPCmd[strlen(szCTCPCmd)-1]==0x01) szCTCPCmd[strlen(szCTCPCmd)-1]=0x00; } if(szCTCPCmd[0]==0x01) { //Handle ctcp message strncpy(szRemLine, Line+iPrefixLen+strlen(szCmd)+strlen(szTarget)+strlen(szCTCPCmd)+6, sizeof(szRemLine)-1); szRemLine[strlen(szRemLine)-1] = '\0';//null out the ending 0x01 if(stricmp(szCTCPCmd+1,NOX("ACTION"))==0) { //Posture snprintf(szResponse, SSIZE(szResponse), "* %s %s", szNick, szRemLine); return szResponse; } if(iMode==MSG_LOCAL) { strncpy(szHackPrefix, Line+iPrefixLen+strlen(szCmd)+strlen(szTarget)+4, sizeof(szHackPrefix)-1); szRemLine[strlen(szRemLine)-1] = '\0'; snprintf(szResponse, SSIZE(szResponse), NOX("** CTCP %s %s %s"), szTarget, szCTCPCmd+1, szRemLine); return szResponse; } if(stricmp(szCTCPCmd+1,NOX("PING"))==0) { snprintf(szResponse, SSIZE(szResponse), NOX("/NOTICE %s :\001PING %s\001"), szNick, szRemLine);//Don't need the trailing \001 because szremline has it. SendChatString(szResponse,1); return NULL; } if(stricmp(szCTCPCmd+1,NOX("VERSION"))==0) { return NULL; } strncpy(szRemLine, 1 + GetWordNum(0,Line+iPrefixLen+strlen(szCmd)+strlen(szTarget)+4), sizeof(szRemLine)-1); szRemLine[strlen(szRemLine)-1] = '\0'; snprintf(szResponse, SSIZE(szResponse), NOX("** CTCP Message from %s (%s)"), szNick, szRemLine); return szResponse; } //differentiate between channel and private if(szTarget[0]=='#') { pszTempStr=GetWordNum(0,szRemLine); snprintf(szResponse, SSIZE(szResponse), "[%s] %s", szNick, pszTempStr); return szResponse; } else { if(iMode == MSG_LOCAL) { pszTempStr=GetWordNum(0,szRemLine); snprintf(szResponse, SSIZE(szResponse), NOX("Private Message to <%s>: %s"), szNick, pszTempStr); } else { pszTempStr=GetWordNum(0,szRemLine); snprintf(szResponse, SSIZE(szResponse), NOX("Private Message from <%s>: %s"), szNick, pszTempStr); } return szResponse; } } //don't handle any other messages locally. if(iMode==MSG_LOCAL) { return NULL; } if(stricmp(szCmd,NOX("NOTICE"))==0) { pszTempStr=GetWordNum(0,szRemLine); strncpy(szTarget, pszTempStr, sizeof(szTarget)-1); strncpy(szRemLine, Line+iPrefixLen+strlen(szCmd)+strlen(szTarget)+4, sizeof(szRemLine)-1); if(szRemLine[0]==':') { strncpy(szCTCPCmd, GetWordNum(0,szRemLine+1), sizeof(szCTCPCmd)-1); if(szCTCPCmd[strlen(szCTCPCmd)-1]==0x01) szCTCPCmd[strlen(szCTCPCmd)-1]=0x00; } else { strncpy(szCTCPCmd, GetWordNum(0,szRemLine), sizeof(szCTCPCmd)-1); if(szCTCPCmd[strlen(szCTCPCmd)-1]==0x01) szCTCPCmd[strlen(szCTCPCmd)-1]=0x00; } if(szCTCPCmd[0]==0x01) { //Handle ctcp message strncpy(szRemLine, Line+iPrefixLen+strlen(szCmd)+strlen(szTarget)+strlen(szCTCPCmd)+6, sizeof(szRemLine)-1); szRemLine[strlen(szRemLine)-1] = '\0';//null out the ending 0x01 if(stricmp(szCTCPCmd+1,NOX("PING"))==0) { return NULL; } //Default message strncpy(szRemLine, 1 + GetWordNum(0,Line+iPrefixLen+strlen(szCmd)+strlen(szTarget)+4), sizeof(szRemLine)-1); szRemLine[strlen(szRemLine)-1] = '\0'; snprintf(szResponse, SSIZE(szResponse), XSTR("** CTCP Message from %s (%s)", 635), szNick, szRemLine); return szResponse; } snprintf(szResponse, SSIZE(szResponse), "%s", szRemLine); return NULL; } if(stricmp(szCmd,NOX("JOIN"))==0) { //see if it is me! if(stricmp(Nick_name,szNick)==0) { Joined_channel = 1; if(stricmp(szChat_channel,NOX("#autoselect"))==0) { strncpy(szChat_channel, GetWordNum(0,szRemLine), sizeof(szChat_channel)-1); AddChatCommandToQueue(CC_YOURCHANNEL,szChat_channel,strlen(szChat_channel)+1); } } pszTempStr=GetWordNum(0,szRemLine); strncpy(szTarget, pszTempStr, sizeof(szTarget)-1); AddChatUser(szNick); snprintf(szResponse, SSIZE(szResponse), XSTR("** %s has joined %s", 636), szNick, szTarget); return NULL;//szResponse; //Add them to the userlist too! } if(stricmp(szCmd,NOX("PART"))==0) { pszTempStr=GetWordNum(0,szRemLine); strncpy(szTarget, pszTempStr, sizeof(szTarget)-1); strncpy(szRemLine, Line+iPrefixLen+strlen(szCmd)+strlen(szTarget)+3, sizeof(szRemLine)-1); //see if it is me! if(stricmp(Nick_name,szNick)==0) { RemoveAllChatUsers(); } RemoveChatUser(szNick); return NULL; //Remove them to the userlist too! } if(stricmp(szCmd,NOX("KICK"))==0) { pszTempStr=GetWordNum(0,szRemLine); strncpy(szTarget, pszTempStr, sizeof(szTarget)-1); pszTempStr=GetWordNum(1,szRemLine); strncpy(szHackPrefix, pszTempStr, sizeof(szHackPrefix)-1); pszTempStr=GetWordNum(2,szRemLine); //see if it is me! if(stricmp(Nick_name,GetWordNum(1,szRemLine))==0) { //Yup, it's me! szChat_channel[0] = '\0'; AddChatCommandToQueue(CC_KICKED,NULL,0); RemoveAllChatUsers(); } snprintf(szResponse, SSIZE(szResponse), XSTR("*** %s has kicked %s from channel %s (%s)", 637), szNick, szHackPrefix, szTarget, pszTempStr); //Remove them to the userlist too! RemoveChatUser(szNick); return szResponse; } if(stricmp(szCmd,NOX("NICK"))==0) { //see if it is me! if(stricmp(Nick_name,szNick)==0) { //Yup, it's me! strncpy(Nick_name, GetWordNum(0,szRemLine), sizeof(Nick_name)-1); } char nicks[70]; snprintf(nicks, SSIZE(nicks), "%s %s", szNick, GetWordNum(0, szRemLine)); AddChatCommandToQueue(CC_NICKCHANGED,nicks,strlen(nicks)+1); RemoveChatUser(szNick); AddChatUser(GetWordNum(0,szRemLine)); snprintf(szResponse, SSIZE(szResponse), XSTR("*** %s is now known as %s", 638), szNick, GetWordNum(0, szRemLine)); return szResponse; } if(stricmp(szCmd,NOX("PING"))==0) { //respond with pong (GetWordNum(0,szRemLine)) snprintf(szResponse, SSIZE(szResponse), NOX("/PONG :%s"), GetWordNum(0, szRemLine)); SendChatString(szResponse,1); return NULL; } if(stricmp(szCmd,NOX("MODE"))==0) { //Channel Mode info return NULL; } if(stricmp(szCmd, "403")==0) { // ERR_NOSUCHCHANNEL - Used to indicate the given channel name is invalid. Joined_channel = -1; return NULL; } if(stricmp(szCmd,"401")==0) { //This is whois user info, we can get their tracker info from here. -5 char szWhoisUser[33]; memset(szWhoisUser, 0, sizeof(szWhoisUser)); strncpy(szWhoisUser, GetWordNum(1,szRemLine), sizeof(szWhoisUser)-1); Getting_user_tracker_error = 1; Getting_user_channel_error = 1; snprintf(szResponse, SSIZE(szResponse), XSTR("**Error: %s is not online!", 639), szWhoisUser); return szResponse; } if(stricmp(szCmd,"311")==0) { char szWhoisUser[33]; memset(szWhoisUser, 0, sizeof(szWhoisUser)); strncpy(szWhoisUser, GetWordNum(1,szRemLine), sizeof(szWhoisUser)-1); //This is whois user info, we can get their tracker info from here. -5 strncpy(User_req_tracker_id, GetWordNum(5,szRemLine), sizeof(User_req_tracker_id)-1); return NULL; } if(stricmp(szCmd,"319")==0) { char szWhoisUser[33]; memset(szWhoisUser, 0, sizeof(szWhoisUser)); strncpy(szWhoisUser, GetWordNum(1,szRemLine), sizeof(szWhoisUser)-1); //This is whois channel info -- what channel they are on -2 strncpy(User_req_channel, GetWordNum(2,szRemLine), sizeof(User_req_channel)-1); return NULL; } //End of whois and we didn't get a channel means they aren't in a channel. if(stricmp(szCmd,"318")==0) { if(!*User_req_channel) { User_req_channel[0] = '*'; } } if(stricmp(szCmd,"321")==0) { //start of channel list FlushChannelList(); GettingChannelList = 1; return NULL; } if(stricmp(szCmd,"322")==0) { //channel list data if(GettingChannelList == 1) { char channel_list_name[33]; char sztopic[200]; memset(channel_list_name, 0, sizeof(channel_list_name)); memset(sztopic, 0, sizeof(sztopic)); strncpy(sztopic, GetWordNum(3,szRemLine), sizeof(sztopic)-1); strncpy(channel_list_name, GetWordNum(1,szRemLine), sizeof(channel_list_name)-1); AddChannel(channel_list_name,(short)atoi(GetWordNum(2,szRemLine)),sztopic); } return NULL; } if(stricmp(szCmd,"323")==0) { //end of channel list GettingChannelList = 2; return NULL; } if(stricmp(szCmd,"324")==0) { //Channel Mode info return NULL; } if(stricmp(szCmd,"332")==0) { //Channel Topic, update status bar. if(stricmp(szChat_channel,szTarget)==0) { //strncpy(szChanTopic,GetWordNum(2,szRemLine),70); } //sprintf(NewMsg.Message,"*** %s has changed the topic to: %s",szNick,GetWordNum(2,szRemLine)); return NULL; } if(stricmp(szCmd,NOX("TOPIC"))==0) { //Channel Topic, update status bar. if(stricmp(szChat_channel,szTarget)==0) { //strncpy(szChanTopic,GetWordNum(1,szRemLine),70); } //sprintf(NewMsg.Message,"*** %s has changed the topic to: %s",szNick,GetWordNum(1,szRemLine)); return NULL; } if(stricmp(szCmd,NOX("QUIT"))==0) { //Remove the user! RemoveChatUser(szNick); return NULL; } if(stricmp(szCmd,"376")==0) //end of motd, trigger autojoin... { if (!Chat_server_connected) { Chat_server_connected=1; } // end of motd strncpy(szResponse, PXO_CHAT_END_OF_MOTD_PREFIX, sizeof(szResponse)-1); return szResponse; } if((stricmp(szCmd,"377")==0)|| (stricmp(szCmd,"372")==0)) { //Stip the message, and display it. pszTempStr=GetWordNum(3,Line); snprintf(szResponse, SSIZE(szResponse), "%s%s", PXO_CHAT_MOTD_PREFIX, pszTempStr); return szResponse; } //Ignore these messages if(((stricmp(szCmd,"366")==0))|| (stricmp(szCmd,"333")==0) || //Who set the topic (stricmp(szCmd,"329")==0)) //Time Channel created { return NULL; } if(stricmp(szCmd,"353")==0) { //Names in the channel. pszTempStr = GetWordNum(3,Line+iPrefixLen+strlen(szCmd)+2); strncpy(szRemLine, pszTempStr, sizeof(szRemLine)-1); pszTempStr = strtok(szRemLine," "); while(pszTempStr) { if(pszTempStr[0]=='@') { AddChatUser(pszTempStr+1); } else if(pszTempStr[0]=='+') { AddChatUser(pszTempStr+1); } else { AddChatUser(pszTempStr); } pszTempStr=strtok(NULL," "); } return NULL; } //MOTD Codes if((stricmp(szCmd,"001")==0)|| (stricmp(szCmd,"002")==0)|| (stricmp(szCmd,"003")==0)|| (stricmp(szCmd,"004")==0)|| (stricmp(szCmd,"251")==0)|| (stricmp(szCmd,"254")==0)|| (stricmp(szCmd,"255")==0)|| (stricmp(szCmd,"265")==0)|| (stricmp(szCmd,"372")==0)|| (stricmp(szCmd,"375")==0) ) { return NULL; // return szResponse; } if(stricmp(szCmd,"432")==0) { //Channel Mode info snprintf(szResponse, SSIZE(szResponse), "%s", XSTR("Your nickname contains invalid characters", 640)); AddChatCommandToQueue(CC_DISCONNECTED,NULL,0); return szResponse; } if(stricmp(szCmd,"433")==0) { //Channel Mode info char new_nick[33]; snprintf(new_nick, SSIZE(new_nick), "%s%d", Orignial_nick_name, Nick_variety); strncpy(Nick_name, new_nick, sizeof(Nick_name)-1); Nick_variety++; snprintf(szResponse, SSIZE(szResponse), NOX("/NICK %s"), new_nick); SendChatString(szResponse,1); return NULL; } //Default print strncpy(szResponse, Line, sizeof(szResponse)-1); return NULL; }
// Return codes: //-2 Already connected //-1 Failed to connect // 0 Connecting // 1 Connected // Call it once with the server IP address, and it will return immediately // with 0. Keep calling it until it returns something other than 0 // note: the nickname may be changed if someone with that name already // exists (Scourge1 for instance) int ConnectToChatServer(char *serveraddr, char *nickname, char *trackerid) { short chat_port; char chat_server[50]; char *p; unsigned long argp = 1; char signon_str[100]; if(!Socket_connecting) { unsigned long iaddr; strncpy(Nick_name, nickname, sizeof(Nick_name)-1); strncpy(Orignial_nick_name, nickname, sizeof(Orignial_nick_name)-1); strncpy(Chat_tracker_id, trackerid, sizeof(Chat_tracker_id)-1); Firstuser = NULL; Firstcommand = NULL; Chat_server_connected = 0; FlushChatCommandQueue(); p = strchr(serveraddr,':'); if(NULL==p) { return -1; } memset(chat_server, 0, sizeof(chat_server)); strncpy(chat_server,serveraddr,(p-serveraddr)); chat_server[p-serveraddr] = '\0'; chat_port = (short)atoi(p+1); if(0==chat_port) { return -1; } Chatsock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if(INVALID_SOCKET == Chatsock) { return -1; } memset( &Chataddr, 0, sizeof(SOCKADDR_IN) ); Chataddr.sin_family = AF_INET; Chataddr.sin_addr.s_addr = INADDR_ANY; Chataddr.sin_port = 0; if (SOCKET_ERROR==bind(Chatsock, (SOCKADDR*)&Chataddr, sizeof (sockaddr))) { return -1; } ioctlsocket(Chatsock, FIONBIO, &argp); // first try and resolve by name iaddr = inet_addr( chat_server ); if ( iaddr == INADDR_NONE ) { HOSTENT *he; he = gethostbyname(chat_server); if(!he) { return 0; } memcpy(&iaddr, he->h_addr_list[0],4); } memcpy(&Chataddr.sin_addr.s_addr, &iaddr,4); Chataddr.sin_port = htons( chat_port ); if(SOCKET_ERROR == connect(Chatsock,(SOCKADDR *)&Chataddr,sizeof(SOCKADDR_IN))) { if(WSAEWOULDBLOCK == WSAGetLastError()) { Socket_connecting = 1; return 0; } } else { //This should never happen, connect should always return WSAEWOULDBLOCK Socket_connecting = 1; Socket_connected = 1; return 1; } } else { if(Chat_server_connected) { return 1; } if(!Socket_connected) { //Do a few select to check for an error, or to see if we are writeable (connected) fd_set write_fds,error_fds; struct timeval timeout; timeout.tv_sec=0; timeout.tv_usec=0; FD_ZERO(&write_fds); FD_SET(Chatsock, &write_fds); //Writable -- that means it's connected if (select(Chatsock+1, NULL, &write_fds, NULL, &timeout) > 0) { // make sure that we don't have any connect() errors (since it's non-blocking) int err_val = 0; size_t err_val_size = sizeof(err_val); getsockopt(Chatsock, SOL_SOCKET, SO_ERROR, (char*)&err_val, (socklen_t*)&err_val_size); if (err_val) { if (err_val != WSAEWOULDBLOCK) { return -1; } return 0; } Socket_connected = 1; memset(signon_str, 0, sizeof(signon_str)); snprintf(signon_str, SSIZE(signon_str), NOX("/USER %s %s %s :%s"), NOX("user"), NOX("user"), NOX("user"), Chat_tracker_id); SendChatString(signon_str, 1); snprintf(signon_str, SSIZE(signon_str), NOX("/NICK %s"), Nick_name); SendChatString(signon_str,1); return 0; //Now we are waiting for Chat_server_connected } FD_ZERO(&error_fds); FD_SET(Chatsock,&error_fds); //error -- that means it's not going to connect if ( select(Chatsock+1, NULL, NULL, &error_fds, &timeout) ) { return -1; } return 0; } } return 0; }
/** * Send a string to be sent as chat, or scanned for messages (/msg \<user\> string) */ const char * SendChatString(const char *line,int raw) { char szCmd[200]; char szTarget[50]; if(!Socket_connected) return NULL; szCmd[sizeof(szCmd)-1] = '\0'; szTarget[sizeof(szTarget)-1] = '\0'; if(line[0]=='/') { //Start off by getting the command strncpy(szCmd, GetWordNum(0, line+1), sizeof(szCmd)-1); if(stricmp(szCmd,NOX("msg"))==0) { strncpy(szTarget, GetWordNum(1, line+1), sizeof(szTarget)-1); snprintf(szCmd, SSIZE(szCmd), NOX("PRIVMSG %s :%s\n\r"), szTarget, line+strlen(NOX("/msg "))+strlen(szTarget)+1); send(Chatsock,szCmd,strlen(szCmd),0); szCmd[strlen(szCmd)-2] = '\0'; return ParseIRCMessage(szCmd,MSG_LOCAL); } if(stricmp(szCmd,NOX("me"))==0) { snprintf(szCmd, SSIZE(szCmd), NOX("PRIVMSG %s :\001ACTION %s\001\n\r"), szChat_channel,line+strlen(NOX("/me "))); send(Chatsock,szCmd,strlen(szCmd),0); szCmd[strlen(szCmd)-2] = '\0'; return ParseIRCMessage(szCmd,MSG_LOCAL); } if(stricmp(szCmd,NOX("xyz"))==0) { //Special command to send raw irc commands snprintf(szCmd, SSIZE(szCmd), "%s\n\r", line+strlen(NOX("/xyz "))); send(Chatsock,szCmd,strlen(szCmd),0); return NULL; } if(stricmp(szCmd,NOX("list"))==0) { snprintf(szCmd, SSIZE(szCmd), "%s\n\r", line+1); send(Chatsock,szCmd,strlen(szCmd),0); return NULL; } if(raw) { snprintf(szCmd, SSIZE(szCmd), "%s\n\r", line+1); send(Chatsock,szCmd,strlen(szCmd),0); return NULL; } return XSTR("Unrecognized command",634); } else { if(szChat_channel[0]) { snprintf(szCmd, SSIZE(szCmd), NOX("PRIVMSG %s :%s\n\r"), szChat_channel, line); send(Chatsock,szCmd,strlen(szCmd),0); if(strlen(szCmd) >= 2){ szCmd[strlen(szCmd)-2] = '\0'; return ParseIRCMessage(szCmd,MSG_LOCAL); } return NULL; } } return NULL; }
DWORD CLotusNote::ItemAddTextList(char *item_name, char *item_value,BOOL duplicate) { if (m_hnote == NULL) return Error_Handle("ItemAddTextList ... failed"); return CLotusSection::Add_NApi_code_msg(NSFItemAppendTextList(m_hnote,item_name,item_value,MAXWORD,duplicate),SSIZE(m_err_msg),"CLotusNote::ItemAddTextList->NSFItemAppendTextList"); }
DWORD CLotusNote::ItemInfo(char *item_name, BLOCKID *item_blockid, WORD *item_datatype, BLOCKID *value_blockid, DWORD *value_len) { WORD size = 0; if (m_hnote == NULL) return Error_Handle("GetItemInfo ... failed"); if (item_name != NULL) size = strlen(item_name); return CLotusSection::Add_NApi_code_msg(NSFItemInfo(m_hnote,item_name,size,item_blockid,item_datatype,value_blockid,value_len),SSIZE(m_err_msg),"CLotusNote::ItemInfo->NSFItemInfo"); }
DWORD CLotusNote::ItemSetText(char *item_name, char *text, WORD length) { if (m_hnote == NULL) return SetError(false,ERR_HANDLE,"CLotusNote::ItemSetText ..."); return CLotusSection::Add_NApi_code_msg(NSFItemSetText(m_hnote,item_name,text,length),SSIZE(m_err_msg),"CLotusNote::ItemSetText->NSFItemSetText(%s,%s)",item_name,text); }
DWORD CLotusNote::ExtractFile(BLOCKID item_blockid, char *file_path, ENCRYPTION_KEY *key) { if (m_hnote == NULL) return Error_Handle("ExtractFile ... failed"); return CLotusSection::Add_NApi_code_msg(NSFNoteExtractFile(m_hnote,item_blockid,file_path,key),SSIZE(m_err_msg),"CLotusNote::ExtractFile->NSFNoteExtractFile"); }
DWORD CLotusNote::ComputeWithForm(NOTEHANDLE frm_handle,DWORD flag) { if (m_hnote == NULL) return Error_Handle("CLotusNote::ComputeWithForm"); return CLotusSection::Add_NApi_code_msg(NSFNoteComputeWithForm(m_hnote,frm_handle,flag,gCWF_ERROR_PROC,this),SSIZE(m_err_msg),"CLotusNote::ComputeWithForm->NSFNoteComputeWithForm"); }
DWORD CLotusNote::DetachFile(BLOCKID item_blockid) { if (m_hnote == NULL) return Error_Handle("ExtractFile ... failed"); return CLotusSection::Add_NApi_code_msg(NSFNoteDetachFile(m_hnote,item_blockid),SSIZE(m_err_msg),"CLotusNote::DetachFile->NSFNoteDetachFile"); }
DWORD CLotusNote::AttachFile(char *item, char *file_path, WORD encoding) { char* filename = file_path; char* cptr = file_path; if (m_hnote == NULL) return Error_Handle("AttachFile ... failed"); for(;;) { cptr = strstr(cptr,"\\"); if (cptr == NULL) break; cptr++; filename = cptr; } return CLotusSection::Add_NApi_code_msg(NSFNoteAttachFile(m_hnote,item,strlen(item),file_path,filename,encoding),SSIZE(m_err_msg),"CLotusNote::AttachFile->NSFNoteAttachFile"); }
DWORD CLotusNote::AttachmentAdd(char *file_path, char *file_name) { char* filename = file_path; char* cptr = file_path; if (m_hnote == NULL) return Error_Handle("CLotusNote::AttachmentAdd ... failed"); if (file_name == NULL) for(;;) { cptr = strstr(cptr,"\\"); if (cptr == NULL) break; cptr++; filename = cptr; } else filename = file_name; return CLotusSection::Add_NApi_code_msg(MailAddMessageAttachment(m_hnote,file_path,filename),SSIZE(m_err_msg),"CLotusNote::AttachmentAdd->MailAddMessageAttachment"); }