mirror of
				https://github.com/osmarks/ngircd.git
				synced 2025-10-31 22:13:00 +00:00 
			
		
		
		
	Merge branch 'bug153-ServerMask' into master
* bug153-ServerMask: Update irc-info.c to use irc-macros.h Add new irc-macros.h to project irc-info.c: add/streamline function documentation comments irc-info: move static functions at the top of the file Implement new function Client_SearchServer() Conflicts: src/ngircd/irc-info.c
This commit is contained in:
		| @@ -86,6 +86,7 @@ noinst_HEADERS = \ | ||||
| 	irc-encoding.h \ | ||||
| 	irc-info.h \ | ||||
| 	irc-login.h \ | ||||
| 	irc-macros.h \ | ||||
| 	irc-metadata.h \ | ||||
| 	irc-mode.h \ | ||||
| 	irc-op.h \ | ||||
|   | ||||
| @@ -41,6 +41,7 @@ | ||||
| #include "hash.h" | ||||
| #include "irc-write.h" | ||||
| #include "log.h" | ||||
| #include "match.h" | ||||
| #include "messages.h" | ||||
|  | ||||
| #include <exp.h> | ||||
| @@ -556,13 +557,14 @@ Client_ModeDel( CLIENT *Client, char Mode ) | ||||
| } /* Client_ModeDel */ | ||||
|  | ||||
|  | ||||
| /** | ||||
|  * Search CLIENT structure of a given nick name. | ||||
|  * | ||||
|  * @return Pointer to CLIENT structure or NULL if not found. | ||||
|  */ | ||||
| GLOBAL CLIENT * | ||||
| Client_Search( const char *Nick ) | ||||
| { | ||||
| 	/* return Client-Structure that has the corresponding Nick. | ||||
| 	 * If none is found, return NULL. | ||||
| 	 */ | ||||
|  | ||||
| 	char search_id[CLIENT_ID_LEN], *ptr; | ||||
| 	CLIENT *c = NULL; | ||||
| 	UINT32 search_hash; | ||||
| @@ -583,7 +585,39 @@ Client_Search( const char *Nick ) | ||||
| 		c = (CLIENT *)c->next; | ||||
| 	} | ||||
| 	return NULL; | ||||
| } /* Client_Search */ | ||||
| } | ||||
|  | ||||
|  | ||||
| /** | ||||
|  * Serach first CLIENT structure matching a given mask of a server. | ||||
|  * | ||||
|  * The order of servers is arbitrary, but this function makes sure that the | ||||
|  * local server is always returned if the mask matches it. | ||||
|  * | ||||
|  * @return Pointer to CLIENT structure or NULL if no server could be found. | ||||
|  */ | ||||
| GLOBAL CLIENT * | ||||
| Client_SearchServer(const char *Mask) | ||||
| { | ||||
| 	CLIENT *c; | ||||
|  | ||||
| 	assert(Mask != NULL); | ||||
|  | ||||
| 	/* First check if mask matches the local server */ | ||||
| 	if (MatchCaseInsensitive(Mask, Client_ID(Client_ThisServer()))) | ||||
| 		return Client_ThisServer(); | ||||
|  | ||||
| 	c = My_Clients; | ||||
| 	while (c) { | ||||
| 		if (Client_Type(c) == CLIENT_SERVER) { | ||||
| 			/* This is a server: check if Mask matches */ | ||||
| 			if (MatchCaseInsensitive(Mask, c->id)) | ||||
| 				return c; | ||||
| 		} | ||||
| 		c = (CLIENT *)c->next; | ||||
| 	} | ||||
| 	return NULL; | ||||
| } | ||||
|  | ||||
|  | ||||
| /** | ||||
|   | ||||
| @@ -94,6 +94,7 @@ GLOBAL CLIENT *Client_ThisServer PARAMS(( void )); | ||||
| GLOBAL CLIENT *Client_GetFromToken PARAMS(( CLIENT *Client, int Token )); | ||||
|  | ||||
| GLOBAL CLIENT *Client_Search PARAMS(( const char *ID )); | ||||
| GLOBAL CLIENT *Client_SearchServer PARAMS(( const char *ID )); | ||||
| GLOBAL CLIENT *Client_First PARAMS(( void )); | ||||
| GLOBAL CLIENT *Client_Next PARAMS(( CLIENT *c )); | ||||
|  | ||||
|   | ||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										83
									
								
								src/ngircd/irc-macros.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										83
									
								
								src/ngircd/irc-macros.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,83 @@ | ||||
| /* | ||||
|  * ngIRCd -- The Next Generation IRC Daemon | ||||
|  * Copyright (c)2001-2013 Alexander Barton (alex@barton.de). | ||||
|  * | ||||
|  * This program is free software; you can redistribute it and/or modify | ||||
|  * it under the terms of the GNU General Public License as published by | ||||
|  * the Free Software Foundation; either version 2 of the License, or | ||||
|  * (at your option) any later version. | ||||
|  * Please read the file COPYING, README and AUTHORS for more information. | ||||
|  */ | ||||
|  | ||||
| #ifndef __irc_macros_h__ | ||||
| #define __irc_macros_h__ | ||||
|  | ||||
| /** | ||||
|  * @file | ||||
|  * Macros for functions that handle IRC commands. | ||||
|  */ | ||||
|  | ||||
| /** | ||||
|  * Make sure that number of passed parameters is less or equal than Max. | ||||
|  * | ||||
|  * If there are more than Max parameters, send an error to the client and | ||||
|  * return from the function. | ||||
|  */ | ||||
| #define _IRC_ARGC_LE_OR_RETURN_(Client, Req, Max) \ | ||||
| if (Req->argc > Max) \ | ||||
| 	return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG, \ | ||||
| 				  Client_ID(Client), Req->command); | ||||
|  | ||||
| /** | ||||
|  * Make sure that number of passed parameters is greater or equal than Min. | ||||
|  * | ||||
|  * If there aren't at least Min parameters, send an error to the client and | ||||
|  * return from the function. | ||||
|  */ | ||||
| #define _IRC_ARGC_GE_OR_RETURN_(Client, Req, Min) \ | ||||
| if (Req->argc < Min) \ | ||||
| 	return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG, \ | ||||
| 				  Client_ID(Client), Req->command); | ||||
|  | ||||
| /** | ||||
|  * Get sender of an IRC command. | ||||
|  * | ||||
|  * The sender is either stored in the prefix if the command has been | ||||
|  * received from a server or set to the client. If the sender is invalid, | ||||
|  * send an error to the client and return from the function. | ||||
|  */ | ||||
| #define _IRC_GET_SENDER_OR_RETURN_(Sender, Req, Client) \ | ||||
| 	if (Client_Type(Client) == CLIENT_SERVER) \ | ||||
| 		Sender = Client_Search(Req->prefix); \ | ||||
| 	else \ | ||||
| 		Sender = Client; \ | ||||
| 	if (!Sender) \ | ||||
| 		return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG, \ | ||||
| 					  Client_ID(Client), Req->prefix); | ||||
|  | ||||
| /** | ||||
|  * Get target of an IRC command and make sure that it is a server. | ||||
|  * | ||||
|  * Set the target to the local server if no target parameter is given in the | ||||
|  * received command, and send an error to the client and return from the | ||||
|  * function if the given target isn't resolvable to a server: the target | ||||
|  * parameter can be a server name, a nick name (then the target is set to | ||||
|  * the server to which this nick is connected), or a mask matching at least | ||||
|  * one server name in the network. | ||||
|  */ | ||||
| #define _IRC_GET_TARGET_SERVER_OR_RETURN_(Target, Req, Argc, From) \ | ||||
| 	if (Req->argc > Argc) { \ | ||||
| 		Target = Client_Search(Req->argv[Argc]); \ | ||||
| 		if (!Target) \ | ||||
| 			Target = Client_SearchServer(Req->argv[Argc]); \ | ||||
| 		if (!Target) \ | ||||
| 			return IRC_WriteStrClient(From, ERR_NOSUCHSERVER_MSG, \ | ||||
| 					  Client_ID(From), Req->argv[Argc]); \ | ||||
| 		if (Client_Type(Target) != CLIENT_SERVER) \ | ||||
| 			Target = Client_Introducer(Target); \ | ||||
| 	} else \ | ||||
| 		Target = Client_ThisServer(); | ||||
|  | ||||
| #endif	/* __irc_macros_h__ */ | ||||
|  | ||||
| /* -eof- */ | ||||
		Reference in New Issue
	
	Block a user
	 Alexander Barton
					Alexander Barton